-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (45 loc) · 1.67 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
package main
import (
"io"
"log"
"net/http"
"github.com/alecthomas/kingpin/v2"
kitlog "github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/collectors/version"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/exporter-toolkit/web"
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
)
func main() {
webConfig := webflag.AddFlags(kingpin.CommandLine, ":8081")
metricsPath := kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
timeout := kingpin.Flag("scrape-timeout", "Maximum duration for a scrape.").Default("1m").Duration()
kingpin.Parse()
reg := prometheus.NewPedanticRegistry()
reg.MustRegister(
collectors.NewBuildInfoCollector(),
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
collectors.NewGoCollector(),
version.NewCollector("prometheus_ai_on_the_edge_device_exporter"),
)
http.Handle(*metricsPath, promhttp.HandlerFor(reg, promhttp.HandlerOpts{}))
http.HandleFunc("/probe", func(w http.ResponseWriter, r *http.Request) {
probeHandler(w, r, *timeout)
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, `<html>
<head><title>AI-on-the-edge-device Exporter</title></head>
<body>
<h1>AI-on-the-edge-device Exporter</h1>
<p><a href="`+*metricsPath+`">Metrics</a></p>
</body>
</html>`)
})
logger := kitlog.NewLogfmtLogger(kitlog.StdlibWriter{})
server := &http.Server{}
if err := web.ListenAndServe(server, webConfig, logger); err != nil {
log.Fatal(err)
}
}