-
Notifications
You must be signed in to change notification settings - Fork 1
/
fritzCable_exporter.go
48 lines (40 loc) · 1.96 KB
/
fritzCable_exporter.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
package main
import (
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/prometheus/common/version"
"gopkg.in/alecthomas/kingpin.v2"
)
const (
exporterName = "fritzCable_exporter"
namespace = "fritzCable"
)
func main() {
var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9623").String()
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
clientScrapeURI = kingpin.Flag("client.scrape-uri", "Base URI on which to scrape Fritzbox Cable.").Default("http://192.168.178.1/").String()
clientUsername = kingpin.Flag("client.username", "Username of Fritzbox Cable.").Default("admin").String()
clientPassword = kingpin.Flag("client.password", "Password of Fritzbox Cable.").Default("totalsecure").String()
clientTimeout = kingpin.Flag("client.timeout", "Timeout for HTTP requests to Fritzbox.").Default("50s").Duration()
clientDisableCertValidation = kingpin.Flag("client.disable-cert", "Ignore SSL certificate valiation").Bool()
)
log.AddFlags(kingpin.CommandLine)
kingpin.Version(version.Print(exporterName))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
log.Infoln("Starting", exporterName, version.Info())
log.Infoln("Build context", version.BuildContext())
exporter, err := NewExporter(*clientScrapeURI, *clientUsername, *clientPassword, *clientTimeout, *clientDisableCertValidation)
if err != nil {
log.Fatal(err)
}
prometheus.MustRegister(exporter)
prometheus.MustRegister(version.NewCollector(exporterName))
log.Infoln("Listening on", *listenAddress)
http.Handle(*metricsPath, promhttp.Handler())
http.Handle("/", http.RedirectHandler(*metricsPath, http.StatusFound))
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}