-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
77 lines (61 loc) · 1.86 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
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
73
74
75
76
77
package main
import (
"fmt"
"log"
"net/http"
"os"
"runtime"
"time"
"git.luolix.top.sfragata/adguardhome_exporter/collector"
"git.luolix.top.sfragata/adguardhome_exporter/server"
"github.com/integrii/flaggy"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
// These variables will be replaced by real values when do gorelease
var (
version = "none"
date string
commit string
)
func main() {
info := fmt.Sprintf(
"%s\nDate: %s\nCommit: %s\nOS: %s\nArch: %s",
version,
date,
commit,
runtime.GOOS,
runtime.GOARCH,
)
flaggy.SetName("adguardhome_exporter")
flaggy.SetDescription("Prometheus exporter for Adguard home")
flaggy.SetVersion(info)
var adguardHost = "127.0.0.1"
flaggy.String(&adguardHost, "H", "host", "Adguard home address")
var adguardPort = 80
flaggy.Int(&adguardPort, "p", "port", "Adguard home port")
var adguardToken = os.Getenv("ADGUARD_HOME_TOKEN") // username:password in base64
flaggy.String(&adguardToken, "t", "token", "Adguard home token (if ADGUARD_HOME_TOKEN env variable is set, don't need to pass it). username:password in base64 format")
var metricsPort = "9311"
flaggy.String(&metricsPort, "l", "listen-address", "Adguard home exporter metrics port")
flaggy.Parse()
client := &http.Client{
Timeout: server.HTTPTimeout * time.Second,
}
AdguardServer := server.AdguardServer{
Host: adguardHost,
Port: adguardPort,
Token: adguardToken,
HTTPClient: *client,
}
err := prometheus.Register(collector.NewAdguardCollector(AdguardServer, version))
if err != nil {
log.Fatalf("Can't register collectors: %v", err)
}
http.Handle("/metrics", promhttp.Handler())
log.Printf("starting adguardhome_export [:%s]", metricsPort)
err = http.ListenAndServe(":"+metricsPort, nil)
if err != nil {
log.Fatalf("Can't start server %s", metricsPort)
}
}