forked from kobtea/dummy_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy_exporter.go
68 lines (56 loc) · 1.92 KB
/
dummy_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"net/http"
"github.com/alecthomas/kingpin/v2"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/version"
log "github.com/sirupsen/logrus"
"github.com/TheoBrigitte/prometheus-dummy-exporter/pkg/collector"
"github.com/TheoBrigitte/prometheus-dummy-exporter/pkg/config"
)
var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry").Default(":9510").String()
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
configFile = kingpin.Flag("config", "Path to config file").Default("").String()
logLevel = kingpin.Flag("log.level", fmt.Sprintf("Log level: %v", logLevelsString())).Default(log.InfoLevel.String()).String()
)
func logLevelsString() (levels []string) {
for _, level := range log.AllLevels {
levels = append(levels, level.String())
}
return
}
func main() {
kingpin.Version(version.Print("prometheus-dummy-exporter"))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
log.Infof("starting %s", version.Info())
level, err := log.ParseLevel(*logLevel)
if err != nil {
log.Fatalf("failed to parse log level: %v", err)
}
log.SetLevel(level)
conf := config.New()
if *configFile != "" {
err := conf.ReadFromFile(*configFile)
if err != nil {
log.Fatalf("failed to read config file: %v", err)
}
}
collector, err := collector.New(conf)
if err != nil {
log.Fatalf("failed to create collector: %v", err)
}
err = prometheus.Register(collector)
if err != nil {
log.Fatalf("failed to register collector: %v", err)
}
http.Handle(*metricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
log.Infoln("listening on", *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, nil)) // nolint:gosec
}