-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (48 loc) · 1.5 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"net/http"
kingpin "gopkg.in/alecthomas/kingpin.v2"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/prometheus/common/version"
)
var (
listenAddress = kingpin.Flag("web.listen-address",
"Address on which to expose metrics and web interface.",
).Default(":9565").String()
metricsPath = kingpin.Flag(
"web.telemetry-path",
"Path under which to expose metrics.",
).Default("/metrics").String()
bminerScrapeURI = kingpin.Flag(
"bminer.scrape-uri",
"URI on which to scrape Bminer metrics.",
).Default("http://localhost:1880").String()
)
func init() {
prometheus.MustRegister(newExporter())
prometheus.MustRegister(version.NewCollector("bminer_exporter"))
}
func main() {
log.AddFlags(kingpin.CommandLine)
kingpin.Version(version.Print("bminer_exporter"))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
log.Infoln("Starting bminer exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
http.Handle(*metricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head>
<title>Bminer Exporter</title>
</head>
<body>
<h1>Bminer Exporter</h1>
<p><a href="/metrics">Metrics</a></p>
</body>
</html>`))
})
log.Infof("Listening on %s", *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}