-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
47 lines (41 loc) · 1.15 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
package main
import (
"fmt"
"time"
"flag"
"strings"
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
iface = flag.String("interface", "eth0", "Interface to configure via DHCP")
dnsTargets = flag.String("dns", "", "DNS servers to probe, separate by comma.")
icmpTargets = flag.String("icmp", "", "ICMP target.")
icmpCount = flag.Int("icmp-count", 3, "ICMP count.")
dnsQname = flag.String("qname", "healthcheck.event.dreamhack.se.", "DNS healthcheck qname to probe.")
interval = flag.Duration("interval", time.Second * 5, "Collection interval")
verbose = flag.Bool("verbose", false, "Verbose")
)
func main() {
flag.Parse()
fmt.Println("Starting observer.")
dnsTargetsList := strings.Split(*dnsTargets, ",")
icmpTargetsList := strings.Split(*icmpTargets, ",")
http.Handle("/metrics", promhttp.Handler())
go func(){
for {
sampleDhcp(*iface, *verbose)
if len(dnsTargetsList) > 0 {
sampleDns(dnsTargetsList, *dnsQname)
}
if len(icmpTargetsList) > 0 {
sampleIcmp(icmpTargetsList, *icmpCount)
}
time.Sleep(*interval)
}
}()
err := http.ListenAndServe(":9023", nil)
if err != nil {
panic(err)
}
}