-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
55 lines (50 loc) · 1.79 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
package main
import (
"net/http"
"os"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
"github.com/prometheus/common/version"
"github.com/shift/continent8_exporter/collectors"
"gopkg.in/alecthomas/kingpin.v2"
)
// TODO: use https://support.continent8.com/data/locations.json to prettify datacenter names
// TODO: use prettify rack names
var (
httpBind = kingpin.Flag("bind", "The address to listen on for HTTP requests.").Default(":9364").String()
scrapeDuration = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Name: "scrape_collection_duration_seconds",
Help: "Duration of scraping",
},
[]string{"method"},
)
logger = log.NewNopLogger()
)
func init() {
prometheus.MustRegister(version.NewCollector("continent8_exporter"))
prometheus.MustRegister(scrapeDuration)
}
func main() {
allowedLevel := promlog.AllowedLevel{}
flag.AddFlags(kingpin.CommandLine, &allowedLevel)
kingpin.Version(version.Print("continent8_exporter"))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
logger = promlog.New(allowedLevel)
collectors.Logger(logger)
level.Info(logger).Log("msg", "Starting continent8_exporter", "version", version.Info())
level.Info(logger).Log("msg", "Build context", version.BuildContext())
prometheus.MustRegister(collectors.NewBandwidthCollector())
prometheus.MustRegister(collectors.NewEnvironmentCollector())
http.Handle("/metrics", promhttp.Handler())
level.Info(logger).Log("msg", "Listening", "port", *httpBind)
if err := http.ListenAndServe(*httpBind, nil); err != nil {
level.Error(logger).Log("msg", "Error starting HTTP server", "err", err)
os.Exit(1)
}
}