forked from digitalocean/openvswitch_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exporter.go
47 lines (37 loc) · 1.26 KB
/
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
// Copyright 2018-2021 DigitalOcean.
// Copyright 2021 OSISM
// SPDX-License-Identifier: Apache-2.0
// Command openvswitch_exporter implements a Prometheus exporter for Open vSwitch.
package main
import (
"flag"
"log"
"net/http"
"github.com/digitalocean/go-openvswitch/ovsnl"
"github.com/osism/openvswitch_exporter/internal/ovsexporter"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
var (
metricsAddr = flag.String("metrics.addr", ":9310", "address for Open vSwitch exporter")
metricsPath = flag.String("metrics.path", "/metrics", "URL path for surfacing collected metrics")
)
flag.Parse()
c, err := ovsnl.New()
if err != nil {
log.Fatalf("failed to connect to Open vSwitch datapath: %v", err)
}
defer c.Close()
collector := ovsexporter.New(c)
prometheus.MustRegister(collector)
mux := http.NewServeMux()
mux.Handle(*metricsPath, promhttp.Handler())
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, *metricsPath, http.StatusMovedPermanently)
})
log.Printf("starting Open vSwitch exporter on %q", *metricsAddr)
if err := http.ListenAndServe(*metricsAddr, mux); err != nil {
log.Fatalf("cannot start Open vSwitch exporter: %v", err)
}
}