forked from slok/ecs-exporter
/
main.go
63 lines (50 loc) · 1.31 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
58
59
60
61
62
63
package main
//import _ "net/http/pprof"
import (
"net/http"
"os"
"github.com/prometheus/client_golang/prometheus"
"github.com/slok/ecs-exporter/collector"
"github.com/slok/ecs-exporter/log"
)
// Main is the application entry point
func Main() int {
log.Infof("Starting ECS exporter...")
// Parse command line flags
if err := parse(os.Args[1:]); err != nil {
log.Error(err)
return 1
}
if cfg.debug {
log.SetLevel(log.DebugLevel)
}
if cfg.disableCIMetrics {
log.Warnf("Cluster container instance metrics have been disabled")
}
// Create the exporter and register it
exporter, err := collector.New(cfg.awsRegion, cfg.clusterFilter, cfg.disableCIMetrics)
if err != nil {
log.Error(err)
return 1
}
prometheus.MustRegister(exporter)
// Serve metrics
http.Handle(cfg.metricsPath, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>ECS Exporter</title></head>
<body>
<h1>ECS Exporter</h1>
<p><a href='` + cfg.metricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
log.Infoln("Listening on", cfg.listenAddress)
log.Fatal(http.ListenAndServe(cfg.listenAddress, nil))
return 0
}
func main() {
// Run main program
exCode := Main()
os.Exit(exCode)
}