forked from githubexporter/github-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (44 loc) · 1.51 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
package main
import (
"net/http"
"github.com/fatih/structs"
conf "github.com/infinityworks/github-exporter/config"
"github.com/infinityworks/github-exporter/exporter"
"github.com/infinityworks/go-common/logger"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
)
var (
log *logrus.Logger
applicationCfg conf.Config
mets map[string]*prometheus.Desc
)
func init() {
applicationCfg = conf.Init()
mets = exporter.AddMetrics()
log = logger.Start(&applicationCfg)
}
func main() {
log.WithFields(structs.Map(applicationCfg)).Info("Starting Exporter")
exporter := exporter.Exporter{
APIMetrics: mets,
Config: applicationCfg,
}
// Register Metrics from each of the endpoints
// This invokes the Collect method through the prometheus client libraries.
prometheus.MustRegister(&exporter)
// Setup HTTP handler
http.Handle(applicationCfg.MetricsPath(), prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Github Exporter</title></head>
<body>
<h1>GitHub Prometheus Metrics Exporter</h1>
<p>For more information, visit <a href=https://github.com/infinityworks/github-exporter>GitHub</a></p>
<p><a href='` + applicationCfg.MetricsPath() + `'>Metrics</a></p>
</body>
</html>
`))
})
log.Fatal(http.ListenAndServe(":"+applicationCfg.ListenPort(), nil))
}