forked from percona/rds_exporter
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
68 lines (58 loc) · 2.5 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
64
65
66
67
68
package main
import (
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/prometheus/common/version"
"gopkg.in/alecthomas/kingpin.v2"
"github.com/quintoandar/rds_exporter/basic"
"github.com/quintoandar/rds_exporter/client"
"github.com/quintoandar/rds_exporter/config"
"github.com/quintoandar/rds_exporter/enhanced"
"github.com/quintoandar/rds_exporter/sessions"
)
//nolint:lll
var (
listenAddressF = kingpin.Flag("web.listen-address", "Address on which to expose metrics and web interface.").Default(":9042").String()
basicMetricsPathF = kingpin.Flag("web.basic-telemetry-path", "Path under which to expose exporter's basic metrics.").Default("/basic").String()
enhancedMetricsPathF = kingpin.Flag("web.enhanced-telemetry-path", "Path under which to expose exporter's enhanced metrics.").Default("/enhanced").String()
configFileF = kingpin.Flag("config.file", "Path to configuration file.").Default("config.yml").String()
logTraceF = kingpin.Flag("log.trace", "Enable verbose tracing of AWS requests (will log credentials).").Default("false").Bool()
)
func main() {
log.AddFlags(kingpin.CommandLine)
log.Infoln("Starting RDS exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
kingpin.Parse()
cfg, err := config.Load(*configFileF)
if err != nil {
log.Fatalf("Can't read configuration file: %s", err)
}
client := client.New()
sess, err := sessions.New(cfg.Instances, client.HTTP(), *logTraceF)
if err != nil {
log.Fatalf("Can't create sessions: %s", err)
}
// basic metrics + client metrics + exporter own metrics (ProcessCollector and GoCollector)
{
prometheus.MustRegister(basic.New(cfg, sess))
prometheus.MustRegister(client)
http.Handle(*basicMetricsPathF, promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{
ErrorLog: log.NewErrorLogger(),
ErrorHandling: promhttp.ContinueOnError,
}))
}
// enhanced metrics
{
registry := prometheus.NewRegistry()
registry.MustRegister(enhanced.NewCollector(sess))
http.Handle(*enhancedMetricsPathF, promhttp.HandlerFor(registry, promhttp.HandlerOpts{
ErrorLog: log.NewErrorLogger(),
ErrorHandling: promhttp.ContinueOnError,
}))
}
log.Infof("Basic metrics : http://%s%s", *listenAddressF, *basicMetricsPathF)
log.Infof("Enhanced metrics: http://%s%s", *listenAddressF, *enhancedMetricsPathF)
log.Fatal(http.ListenAndServe(*listenAddressF, nil))
}