-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
54 lines (45 loc) · 1.35 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
package main
import (
"net/http"
// _ "net/http/pprof"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
"github.com/vetinari/brickd_exporter/collector"
)
func main() {
config, err := parseConfig()
collector.Version = Version
if err != nil {
log.Fatalf("Error loading configuration: %s", err)
}
if config.Collector.LogLevel == "" {
config.Collector.LogLevel = "info"
}
lvl, err := log.ParseLevel(config.Collector.LogLevel)
if err != nil {
log.Errorf("failed to parse `log_level` %s: %s", config.Collector.LogLevel, err)
lvl = log.InfoLevel
}
log.SetLevel(lvl)
c := collector.NewCollector(
config.Brickd.Address,
config.Brickd.Password,
config.Collector.CallbackPeriod,
config.Collector.IgnoredUIDs,
config.Collector.Labels,
config.Collector.SensorLabels,
config.Collector.Expire,
config.MQTT,
)
prometheus.MustRegister(c)
listenAddress := config.Listen.Address
http.Handle(config.Listen.MetricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, config.Listen.MetricsPath, http.StatusFound)
})
log.Printf("Starting brickd exporter on %q", listenAddress)
if err := http.ListenAndServe(listenAddress, nil); err != nil {
log.Fatalf("Cannot start WL exporter: %s", err)
}
}