-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (55 loc) · 1.76 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
package main
import (
"fmt"
"os"
"github.com/fedor-git/dns_exporter/core/config"
"github.com/fedor-git/dns_exporter/core/dnspoller"
"github.com/fedor-git/dns_exporter/core/webapp"
log "github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"
)
const (
internalPort = 9433
version string = "1.0.2"
)
var (
showVersion = kingpin.Flag("version", "Print version information").Default().Bool()
listenAddress = kingpin.Flag("web.listen-address", "Address on which to expose metrics and web interface").Default("").String()
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics").Default("/metrics").String()
configFile = kingpin.Flag("config.path", "Path to config file").Default("").String()
logLevel = kingpin.Flag("log.level", "Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]").Default("info").String()
)
func printVersion() {
fmt.Println("dns-exporter")
fmt.Printf("Version: %s\n", version)
fmt.Println("Author(s): Fedir Sorokin")
fmt.Println("Metric exporter for DNS infrastructure")
}
func loadConfig() (*config.Config, error) {
if *configFile == "" {
return nil, fmt.Errorf("config file path is empty")
}
f, err := os.Open(*configFile)
if err != nil {
return nil, fmt.Errorf("cannot load config file: %w", err)
}
defer f.Close()
cfg, err := config.FromYAML(f)
return cfg, err
}
func main() {
kingpin.Parse()
setLogLevel(*logLevel)
log.SetReportCaller(true)
if *showVersion {
printVersion()
os.Exit(0)
}
cfg, err := loadConfig()
if err != nil {
kingpin.FatalUsage("could not load config.path: %v", err)
}
dnspoller.InitMetrics(cfg)
dnspoller.StartDNSThread(cfg)
webapp.StartServer(*listenAddress, internalPort, *metricsPath)
}