-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
42 lines (34 loc) · 974 Bytes
/
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
package main
//This script listens on a given TCP port for
//HTTP REST Get messages than scraps the given
//Open vSwtich entry and gives back the stats
//in Prometheus compatible format
//Written by Megyo @ LeanNet
import (
"log"
"net/http"
"github.com/biwwy0/ovs-exporter/ovs"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
//the TCP port that this scripts listens
var listenPort string = ":9981"
func handler(w http.ResponseWriter, r *http.Request) {
target := r.URL.Query().Get("target")
if target == "" {
target = "127.0.0.1"
}
c := OvsPromCollector{
ip: target,
port: ovs.OvsDefaultPort,
ovsReader: ovs.CliDumpReader,
}
registry := prometheus.NewRegistry()
registry.MustRegister(c)
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
h.ServeHTTP(w, r)
}
func main() {
http.HandleFunc("/metrics", handler)
log.Fatal(http.ListenAndServe(listenPort, nil))
}