-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (73 loc) · 2.59 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
82
83
84
package main
import (
"github.com/Ab-hishek/LVM-exporter/collector"
"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"
"net/http"
"os"
)
func main() {
var (
listenAddress = kingpin.Flag(
"web.listen-address",
"Address on which to expose metrics and web interface.",
).Default(":9101").String()
metricsPath = kingpin.Flag(
"web.telemetry-path",
"Path under which to expose metrics.",
).Default("/metrics").String()
disableExporterMetrics = kingpin.Flag(
"web.disable-exporter-metrics",
"Exclude metrics about the exporter itself (promhttp_*, process_*, go_*).",
).Default("true").Bool()
)
promlogConfig := &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.Version(version.Print("lvm_exporter"))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
logger := promlog.New(promlogConfig)
level.Info(logger).Log("msg", "Starting lvm_exporter", "version", version.Info())
level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext())
registry := prometheus.NewRegistry()
if !*disableExporterMetrics {
registry.MustRegister(
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}),
prometheus.NewGoCollector(),
)
}
registry.MustRegister(version.NewCollector("lvm_exporter"))
//Create a new instance of the LvmVgCollector and
//register it with the prometheus client.
LvmVgCollector := collector.NewVgCollector()
registry.MustRegister(LvmVgCollector)
//Create a new instance of the LvmLvCollector and
//register it with the prometheus client.
LvmLvCollector := collector.NewLvCollector()
registry.MustRegister(LvmLvCollector)
//Create a new instance of the LvmPvCollector and
//register it with the prometheus client.
LvmPvCollector := collector.NewPvCollector()
registry.MustRegister(LvmPvCollector)
http.Handle(*metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
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>
`))
})
level.Info(logger).Log("msg", "Listening on", "address", *listenAddress)
if err := http.ListenAndServe(*listenAddress, nil); err != nil {
level.Error(logger).Log("msg", "Error starting HTTP server:", "err", err)
os.Exit(1)
}
}