-
Notifications
You must be signed in to change notification settings - Fork 0
/
rctl_exporter.go
70 lines (58 loc) · 2.08 KB
/
rctl_exporter.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
// Copyright 2020, johan@nosd.in
// +build freebsd
// Inspired from dovecot_exporter and https://blog.skyrise.tech/custom-prometheus-exporter
package main
import (
"os"
"strings"
"net/http"
// For profiling, to fix these memory leaks. This is the only required instruction
// required to enable profiling on the already included web server !
_ "net/http/pprof"
"github.com/sirupsen/logrus"
"github.com/alecthomas/kingpin"
"github.com/yo000/rctl_exporter/rctl"
"github.com/yo000/rctl_exporter/collector"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
log = logrus.New()
)
//var rctlCollect = []string{"process:.*", "user:^yo$", "jail:ioc-testarp", "loginclass:.*"}
func main() {
var results []rctl.Resource
var (
app = kingpin.New("rctl_exporter", "Prometheus metrics exporter for rctl")
listenAddress = app.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9767").String()
metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
rctlCollectArg = app.Flag("rctl.filter", "Filter for rctl collection. Ex: \"process:.*java.*,user:git\"").Default("user:.*").String()
debug = app.Flag("debug", "Enable debug mode").Bool()
)
kingpin.MustParse(app.Parse(os.Args[1:]))
if *debug == true {
log.SetLevel(logrus.DebugLevel)
}
rctlCollect := strings.Split(*rctlCollectArg, ",")
rmgr, err := rctl.NewResourceManager(rctlCollect, log)
if err != nil {
log.Error("Error getting resources : %d", err)
}
for _, r := range rmgr.Resources {
results = append(results, r)
}
coll := collector.New(rmgr, log)
prometheus.MustRegister(coll)
http.Handle(*metricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`
<html>
<head><title>rctl Exporter</title></head>
<body>
<h1>rctl Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}