forked from hansmi/prometheus-lvm-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
75 lines (60 loc) · 2.17 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
package main
import (
"flag"
"fmt"
"log"
"net/http"
"github.com/kballard/go-shellquote"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/version"
"github.com/prometheus/exporter-toolkit/web"
kitlog "github.com/go-kit/kit/log"
)
const metricPrefix = "lvm_"
func main() {
showVersion := flag.Bool("version", false, "Output version information and exit")
listenAddress := flag.String("web.listen-address", ":9845", "The address to listen on for HTTP requests")
configFile := flag.String("web.config", "", "Path to config yaml file that can enable TLS or authentication")
metricsPath := flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics")
disableExporterMetrics := flag.Bool("web.disable-exporter-metrics", false, "Exclude metrics about the exporter itself")
cmd := flag.String("command", "/usr/sbin/lvm", "Path to the LVM binary")
flag.Parse()
if *showVersion {
fmt.Println(version.Print("prometheus-lvm-exporter"))
return
}
cmdParts, err := shellquote.Split(*cmd)
if err != nil {
log.Fatalf("Parsing command failed: %v", err)
}
registry := prometheus.NewPedanticRegistry()
lvmRegistry := prometheus.WrapRegistererWithPrefix(metricPrefix, registry)
lvmRegistry.MustRegister(newCommandCollector(cmdParts))
if !*disableExporterMetrics {
registry.MustRegister(
prometheus.NewBuildInfoCollector(),
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}),
prometheus.NewGoCollector(),
version.NewCollector("lvm_exporter"),
)
}
http.Handle(*metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{
MaxRequestsInFlight: 3,
}))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>LVM exporter</title></head>
<body>
<h1>LVM exporter</h1>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body>
</html>`))
})
log.Printf("Listening on %q", *listenAddress)
server := &http.Server{Addr: *listenAddress}
logger := kitlog.NewLogfmtLogger(kitlog.StdlibWriter{})
if err := web.ListenAndServe(server, *configFile, logger); err != nil {
log.Fatal(err)
}
}