-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathfrr_exporter.go
72 lines (59 loc) · 1.99 KB
/
frr_exporter.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
package main
import (
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"github.com/alecthomas/kingpin/v2"
"github.com/prometheus/client_golang/prometheus"
versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promslog"
"github.com/prometheus/common/promslog/flag"
"github.com/prometheus/common/version"
"github.com/prometheus/exporter-toolkit/web"
"github.com/prometheus/exporter-toolkit/web/kingpinflag"
"github.com/tynany/frr_exporter/collector"
)
var (
telemetryPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
webFlagConfig = kingpinflag.AddFlags(kingpin.CommandLine, ":9342")
)
func main() {
promslogConfig := &promslog.Config{}
flag.AddFlags(kingpin.CommandLine, promslogConfig)
kingpin.Version(version.Print("frr_exporter"))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
logger := promslog.New(promslogConfig)
prometheus.MustRegister(versioncollector.NewCollector("frr_exporter"))
logger.Info("Starting frr_exporter", "version", version.Info())
logger.Info("Build context", "build_context", version.BuildContext())
nc, err := collector.NewExporter(logger)
if err != nil {
panic(fmt.Errorf("Could not create collector: %w", err))
}
prometheus.MustRegister(nc)
http.Handle(*telemetryPath, promhttp.Handler())
if *telemetryPath != "/" && *telemetryPath != "" {
landingConfig := web.LandingConfig{
Name: "FRR Exporter",
Description: "Prometheus Exporter for FRRouting daemon",
Version: version.Info(),
Links: []web.LandingLinks{
{Address: *telemetryPath, Text: "Metrics"},
},
}
landingPage, err := web.NewLandingPage(landingConfig)
if err != nil {
logger.Error(err.Error())
os.Exit(1)
}
http.Handle("/", landingPage)
}
server := &http.Server{}
if err := web.ListenAndServe(server, webFlagConfig, logger); err != nil {
logger.Error(err.Error())
os.Exit(1)
}
}