-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (34 loc) · 1021 Bytes
/
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
package main
import (
"net/http"
"os"
"github.com/BurntSushi/toml"
"github.com/jimyag/log"
_ "github.com/jimyag/version-go"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/jimyag/pingexporter/config"
"github.com/jimyag/pingexporter/metrics"
)
func main() {
if len(os.Args) < 2 {
log.Error().Msg("usage is: ping_exporter <config-path>")
os.Exit(1)
}
configFile := &os.Args[1]
cfg := &config.Config{}
cfg.GlobalLabels = make(map[string]string)
if _, err := toml.DecodeFile(*configFile, &cfg); err != nil {
log.Panic(err).Msg("could not load config")
}
log.Info().Any("config", cfg).Msg("loaded config")
cfg.Default()
cfg.Verify()
ping := metrics.New(cfg)
prometheus.MustRegister(ping)
http.Handle(cfg.Web.MetricsPath, promhttp.Handler())
log.Info().Str("address", cfg.Web.Address).Msg("starting web server")
if err := http.ListenAndServe(cfg.Web.Address, nil); err != nil {
log.Panic(err).Msg("listen failed")
}
}