Add splash page, make metrics path configuriable
Also reformat using `go fmt` and document this in the README.md Normalized parameter names by looking at what node- exporter offers.
This commit is contained in:
parent
14593192c8
commit
e52dbd900d
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
We are building a prometheus exporter for the fastd vpn daemon. We don't have a working version yet, stay tuned
|
We are building a prometheus exporter for the fastd vpn daemon. We don't have a working version yet, stay tuned
|
||||||
|
|
||||||
|
## Formatting
|
||||||
|
|
||||||
|
We are using `go fmt` for formatting the code.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
For now run
|
For now run
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -18,7 +18,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
address = flag.String("listen-address", ":9099", "The address to listen on for HTTP requests.")
|
address = flag.String("web.listen-address", ":9099", "Address on which to expose metrics and web interface.")
|
||||||
|
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
|
||||||
instances = flag.String("instances", "", "The fastd instances to Update on, comma separated.")
|
instances = flag.String("instances", "", "The fastd instances to Update on, comma separated.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -80,8 +81,7 @@ type PrometheusExporter struct {
|
||||||
txErrorBytes *prometheus.Desc
|
txErrorBytes *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func c(parts ...string) string {
|
||||||
func c(parts... string) string {
|
|
||||||
parts = append([]string{"fastd"}, parts...)
|
parts = append([]string{"fastd"}, parts...)
|
||||||
return strings.Join(parts, "_")
|
return strings.Join(parts, "_")
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ func NewPrometheusExporter(instanceName string, sockName string) PrometheusExpor
|
||||||
|
|
||||||
return PrometheusExporter{
|
return PrometheusExporter{
|
||||||
SocketName: sockName,
|
SocketName: sockName,
|
||||||
uptime: prometheus.NewDesc(c(instanceName ,"uptime"), "uptime of the prometheus exporter", nil, l),
|
uptime: prometheus.NewDesc(c(instanceName, "uptime"), "uptime of the prometheus exporter", nil, l),
|
||||||
|
|
||||||
rxPackets: prometheus.NewDesc(c("rx_packets"), "rx packet count", nil, l),
|
rxPackets: prometheus.NewDesc(c("rx_packets"), "rx packet count", nil, l),
|
||||||
rxBytes: prometheus.NewDesc(c("rx_bytes"), "rx byte count", nil, l),
|
rxBytes: prometheus.NewDesc(c("rx_bytes"), "rx byte count", nil, l),
|
||||||
|
@ -192,6 +192,16 @@ func main() {
|
||||||
prometheus.MustRegister(exp)
|
prometheus.MustRegister(exp)
|
||||||
|
|
||||||
// Expose the registered metrics via HTTP.
|
// Expose the registered metrics via HTTP.
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
http.Handle(*metricsPath, promhttp.Handler())
|
||||||
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Write([]byte(`<html>
|
||||||
|
<head><title>fastd exporter</title></head>
|
||||||
|
<body>
|
||||||
|
<h1>fastd exporter</h1>
|
||||||
|
<p><a href="` + *metricsPath + `">Metrics</a></p>
|
||||||
|
</body>
|
||||||
|
</html>`))
|
||||||
|
})
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(*address, nil))
|
log.Fatal(http.ListenAndServe(*address, nil))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue