-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
67 lines (56 loc) · 1.49 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
58
59
60
61
62
63
64
65
66
67
package main
import (
"flag"
"fmt"
"net/http"
"os"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/solsson/go-conbee/sensors"
"go.uber.org/zap"
)
var (
conbeeHost string
conbeeKey string
metricsEndpoint string
metricsListen string
)
func usage() {
fmt.Fprintf(os.Stderr, "usage: kubernetes-zigbee-prometheus -host=[string] -key=[string]\n")
flag.PrintDefaults()
os.Exit(2)
}
func init() {
on := new(bool)
*on = true
flag.StringVar(&conbeeHost, "host", "127.0.0.1:80", "conbee host addr")
flag.StringVar(&conbeeKey, "key", "", "conbee api key")
flag.StringVar(&metricsEndpoint, "endpoint", "/metrics", "Metrics endpoint path")
flag.StringVar(&metricsListen, "listen", ":8080", "Metrics http listen")
flag.Parse()
flag.Usage = usage
}
func main() {
logger, _ := zap.NewDevelopment()
defer logger.Sync()
if conbeeKey != "" {
logger.Info("failed to fetch URL",
zap.String("host", conbeeHost),
zap.Int("keylength", len(conbeeKey)),
)
ss = sensors.New(conbeeHost, conbeeKey)
deconz := newDeconzCollector(logger, ss)
registry := prometheus.NewRegistry()
registry.MustRegister(deconz)
prometheus.MustRegister(deconz)
logger.Info("Listening",
zap.String("endpoint", metricsEndpoint),
zap.String("on", metricsListen),
)
handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{});
http.Handle(metricsEndpoint, handler)
http.ListenAndServe(metricsListen, nil)
} else {
usage()
}
}