forked from Technofy/cloudwatch_exporter
-
Notifications
You must be signed in to change notification settings - Fork 88
/
main.go
81 lines (70 loc) · 3.08 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
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"net/http"
"os"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
"github.com/prometheus/common/version"
"gopkg.in/alecthomas/kingpin.v2"
"github.com/percona/rds_exporter/basic"
"github.com/percona/rds_exporter/client"
"github.com/percona/rds_exporter/config"
"github.com/percona/rds_exporter/enhanced"
"github.com/percona/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()
logger = log.NewNopLogger()
)
func main() {
kingpin.HelpFlag.Short('h')
promlogConfig := &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.Version(version.Print("rds_exporter"))
kingpin.Parse()
logger = promlog.New(promlogConfig)
level.Info(logger).Log("msg", fmt.Sprintf("Starting RDS exporter %s", version.Info()))
level.Info(logger).Log("msg", fmt.Sprintf("Build context %s", version.BuildContext()))
cfg, err := config.Load(*configFileF)
if err != nil {
level.Error(logger).Log("msg", "Can't read configuration file", "error", err)
os.Exit(1)
}
client := client.New(logger)
sess, err := sessions.New(cfg.Instances, client.HTTP(), logger, *logTraceF)
if err != nil {
level.Error(logger).Log("msg", "Can't create sessions", "error", err)
os.Exit(1)
}
// basic metrics + client metrics + exporter own metrics (ProcessCollector and GoCollector)
{
prometheus.MustRegister(basic.New(cfg, sess, logger))
prometheus.MustRegister(client)
http.Handle(*basicMetricsPathF, promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{
//ErrorLog: log.NewErrorLogger(), TODO TS
ErrorHandling: promhttp.ContinueOnError,
}))
}
// enhanced metrics
{
registry := prometheus.NewRegistry()
registry.MustRegister(enhanced.NewCollector(sess, logger))
http.Handle(*enhancedMetricsPathF, promhttp.HandlerFor(registry, promhttp.HandlerOpts{
//ErrorLog: log.NewErrorLogger(), TODO TS
ErrorHandling: promhttp.ContinueOnError,
}))
}
level.Info(logger).Log("msg", fmt.Sprintf("Basic metrics : http://%s%s", *listenAddressF, *basicMetricsPathF))
level.Info(logger).Log("msg", fmt.Sprintf("Enhanced metrics: http://%s%s", *listenAddressF, *enhancedMetricsPathF))
level.Error(logger).Log("error", http.ListenAndServe(*listenAddressF, nil))
}