forked from jfindley/newrelic_exporter
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnewrelic_exporter.go
47 lines (36 loc) · 1.02 KB
/
newrelic_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
package main
import (
"flag"
"net/http"
"camino.ru/newrelic_exporter/config"
"camino.ru/newrelic_exporter/exporter"
"camino.ru/newrelic_exporter/newrelic"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"
)
func main() {
var configFile string
flag.StringVar(&configFile, "config", "newrelic_exporter.yml", "Config file path. Defaults to 'newrelic_exporter.yml'")
flag.Parse()
cfg, err := config.GetConfig(configFile)
api := newrelic.NewAPI(cfg)
exp := exporter.NewExporter(api, cfg)
prometheus.MustRegister(exp)
http.Handle(cfg.MetricPath, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>NewRelic exporter</title></head>
<body>
<h1>NewRelic exporter</h1>
<p><a href='` + cfg.MetricPath + `'>Metrics</a></p>
</body>
</html>
`))
})
log.Printf("Listening on %s.", cfg.ListenAddress)
err = http.ListenAndServe(cfg.ListenAddress, nil)
if err != nil {
log.Fatal(err)
}
log.Print("HTTP server stopped.")
}