8fc004ab36
Signed-off-by: Vasiliy Tolstov <v.tolstov@sdstack.com>
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
promlibvirt "sdstack.com/sdstack/prometheus-libvirt"
|
|
)
|
|
|
|
func main() {
|
|
var (
|
|
listenAddress = flag.String("web.listen-address", ":9177", "Address to listen on for web interface and telemetry.")
|
|
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
|
|
libvirtURI = flag.String("libvirt.uri", "qemu:///system", "Libvirt URI from which to extract metrics.")
|
|
)
|
|
flag.Parse()
|
|
|
|
exporter, err := promlibvirt.NewLibvirtExporter(*libvirtURI)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
prometheus.MustRegister(exporter)
|
|
|
|
http.Handle(*metricsPath, prometheus.Handler())
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Write([]byte(`
|
|
<html>
|
|
<head><title>Libvirt Exporter</title></head>
|
|
<body>
|
|
<h1>Libvirt Exporter</h1>
|
|
<p><a href='` + *metricsPath + `'>Metrics</a></p>
|
|
</body>
|
|
</html>`))
|
|
})
|
|
log.Fatal(http.ListenAndServe(*listenAddress, nil))
|
|
}
|