forked from xperimental/freifunk-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (34 loc) · 989 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
43
package main
import (
"log"
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/pflag"
)
var (
addr string
sourceURL string
cacheInterval time.Duration
)
func init() {
pflag.StringVar(&addr, "addr", ":9295", "Address to listen on.")
pflag.StringVar(&sourceURL, "source-url", "", "URL to Meshviewer JSON file.")
pflag.DurationVar(&cacheInterval, "cache-interval", time.Minute*3, "Interval for local caching of Meshviewer data.")
}
func main() {
pflag.Parse()
if len(sourceURL) == 0 {
log.Println("Need to provide source URL.")
return
}
collector := newCollector(sourceURL, cacheInterval)
prometheus.MustRegister(collector)
http.Handle("/", http.RedirectHandler("/metrics", http.StatusFound))
http.Handle("/metrics", promhttp.Handler())
log.Printf("Listening on %s...", addr)
if err := http.ListenAndServe(addr, nil); err != nil {
log.Fatal(err)
}
}