Skip to content

Commit

Permalink
Cleanup how exporter endpoints are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Nov 14, 2020
1 parent 7a06245 commit 37228a1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ssh_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import (
"gopkg.in/alecthomas/kingpin.v2"
)

const (
sshEndpoint = "/ssh"
metricsEndpoint = "/metrics"
)

var (
configFile = kingpin.Flag("config.file", "Path to exporter config file").Default("ssh_exporter.yaml").String()
defaultTimeout = kingpin.Flag("collector.ssh.default-timeout", "Default timeout for SSH collection").Default("10").Int()
Expand Down Expand Up @@ -81,7 +86,6 @@ func metricsHandler(c *config.Config, logger log.Logger) http.HandlerFunc {
}

func main() {
metricsEndpoint := "/ssh"
promlogConfig := &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.Version(version.Print("ssh_exporter"))
Expand All @@ -106,13 +110,13 @@ func main() {
<head><title>SSH Exporter</title></head>
<body>
<h1>SSH Exporter</h1>
<p><a href='` + metricsEndpoint + `'>SSH Metrics</a></p>
<p><a href='/metrics'>Exporter Metrics</a></p>
<p><a href='` + sshEndpoint + `'>SSH Metrics</a></p>
<p><a href='` + metricsEndpoint + `'>Exporter Metrics</a></p>
</body>
</html>`))
})
http.Handle(metricsEndpoint, metricsHandler(sc.C, logger))
http.Handle("/metrics", promhttp.Handler())
http.Handle(sshEndpoint, metricsHandler(sc.C, logger))
http.Handle(metricsEndpoint, promhttp.Handler())
err := http.ListenAndServe(*listenAddress, nil)
if err != nil {
level.Error(logger).Log("err", err)
Expand Down

0 comments on commit 37228a1

Please sign in to comment.