Skip to content

Commit 709c7f8

Browse files
committed
use exporter-toolkit/web to add TLS and basic auth
Unfortunately ListenAndServe needs a logger implementing the Log() method, so hack in go-kit/log. How about switching to promlog?
1 parent 0f8a9e5 commit 709c7f8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ require (
66
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
77
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 // indirect
88
github.com/apex/log v1.9.0
9+
github.com/go-kit/log v0.2.0
910
github.com/prometheus/client_golang v1.1.0
1011
github.com/prometheus/common v0.6.0
1112
github.com/stmcginnis/gofish v0.6.0
13+
github.com/prometheus/exporter-toolkit v0.5.0
1214
gopkg.in/alecthomas/kingpin.v2 v2.2.6
1315
gopkg.in/yaml.v2 v2.2.2
1416
)

main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ import (
88
"syscall"
99

1010
alog "github.com/apex/log"
11+
kitlog "github.com/go-kit/log"
1112
"github.com/jenningsloy318/redfish_exporter/collector"
1213
"github.com/prometheus/client_golang/prometheus"
1314
"github.com/prometheus/client_golang/prometheus/promhttp"
1415
"github.com/prometheus/common/log"
16+
"github.com/prometheus/exporter-toolkit/web"
17+
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
1518
kingpin "gopkg.in/alecthomas/kingpin.v2"
1619
)
1720

@@ -27,6 +30,7 @@ var (
2730
"config.file",
2831
"Path to configuration file.",
2932
).String()
33+
webConfig = webflag.AddFlags(kingpin.CommandLine)
3034
listenAddress = kingpin.Flag(
3135
"web.listen-address",
3236
"Address to listen on for web interface and telemetry.",
@@ -119,6 +123,7 @@ func main() {
119123
log.AddFlags(kingpin.CommandLine)
120124
kingpin.HelpFlag.Short('h')
121125
kingpin.Parse()
126+
kitlogger := kitlog.NewLogfmtLogger(os.Stderr)
122127

123128
configLoggerCtx := rootLoggerCtx.WithField("config", *configFile)
124129
configLoggerCtx.Info("starting app")
@@ -178,7 +183,8 @@ func main() {
178183
})
179184

180185
rootLoggerCtx.Infof("app started. listening on %s", *listenAddress)
181-
err := http.ListenAndServe(*listenAddress, nil)
186+
srv := &http.Server{Addr: *listenAddress}
187+
err := web.ListenAndServe(srv, *webConfig, kitlogger)
182188
if err != nil {
183189
log.Fatal(err)
184190
}

0 commit comments

Comments
 (0)