-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
57 lines (47 loc) · 1.75 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
56
57
package main
import (
"fmt"
"net/http"
"github.com/ContaAzul/newrelic_exporter/collector"
"github.com/ContaAzul/newrelic_exporter/config"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"gopkg.in/alecthomas/kingpin.v2"
)
const defaultBaseURL = "https://api.newrelic.com/"
var (
version = "dev"
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry").Default(":9112").String()
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
apiKey = kingpin.Flag("newrelic.api-key", "New Relic API key").OverrideDefaultFromEnvar("NEWRELIC_API_KEY").String()
configFile = kingpin.Flag("config", "Configuration file path").Default("config.yml").OverrideDefaultFromEnvar("CONFIG_FILEPATH").String()
)
func main() {
kingpin.Version(version)
kingpin.HelpFlag.Short('h')
kingpin.Parse()
log.Info("Starting newrelic_exporter ", version)
if *apiKey == "" {
log.Fatal("You must provide your New Relic API key")
}
var config = config.Parse(*configFile)
prometheus.MustRegister(collector.NewNewRelicCollector(defaultBaseURL, *apiKey, config))
http.Handle(*metricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, // nolint: gas, errcheck
`
<html>
<head><title>NewRelic Exporter</title></head>
<body>
<h1>NewRelic Exporter</h1>
<p><a href="`+*metricsPath+`">Metrics</a></p>
</body>
</html>
`)
})
log.Infof("Server listening on %s", *listenAddress)
if err := http.ListenAndServe(*listenAddress, nil); err != nil {
log.Fatalf("Error starting server: %v", err)
}
}