-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrally_exporter.go
More file actions
71 lines (59 loc) · 1.81 KB
/
Copy pathrally_exporter.go
File metadata and controls
71 lines (59 loc) · 1.81 KB
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
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/fitbeard/rally-exporter/rally"
)
func main() {
var (
listenAddress = kingpin.Flag(
"web.listen-address",
"Address on which to expose metrics and web interface.",
).Default(":9355").String()
metricsPath = kingpin.Flag(
"web.telemetry-path",
"Path under which to expose metrics.",
).Default("/metrics").String()
deployment = kingpin.Flag(
"deployment-name",
"Name of the Rally deployment",
).Required().String()
exectime = kingpin.Flag(
"execution-time",
"Wait X minutes before next run. Default: 5",
).Default("5").Int()
taskcount = kingpin.Flag(
"task-history",
"Number of tasks to keep in history. Default: 10",
).Default("10").Int()
)
kingpin.Version(version.Print("rally-exporter"))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
// Get rid of any additional metrics
// we have to expose our metrics with a custom registry
registry := prometheus.NewRegistry()
runner := rally.NewPeriodicRunner(*deployment, *exectime, *taskcount)
registry.MustRegister(runner)
go runner.Run()
handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
http.Handle("/metrics", handler)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte(`<html>
<head><title>OpenStack Rally Exporter</title></head>
<body>
<h1>OpenStack Rally Exporter</h1>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body>
</html>`))
if err != nil {
log.Error(err)
}
})
log.Infoln("Listening on", *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}