-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
53 lines (43 loc) · 1.02 KB
/
config.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
package main
import (
"io/ioutil"
"log"
"os"
"path"
yml "gopkg.in/yaml.v2"
)
type config struct {
WebMetricsAddr string `yaml:"web_metrics_addr"`
MetricsEndpoint string `yaml:"metrics_endpoint"`
ScrapeInterval int64 `yaml:"scrape_interval"`
Auth struct {
Email string
Token string
}
}
var conf config
func (conf *config) Read(f string) {
if !path.IsAbs(f) && f[:1] == "~" {
f = path.Join(os.Getenv("HOME"), f[1:])
}
bytes, err := ioutil.ReadFile(f)
if err != nil {
log.Fatalf("Read file %s is failed: %s", f, err)
}
err = yml.Unmarshal(bytes, conf)
if err != nil {
log.Fatalf("Read config is failed: %s", err)
}
if conf.WebMetricsAddr == "" {
conf.WebMetricsAddr = "localhost:9999"
log.Println("Web metrics address:", conf.WebMetricsAddr)
}
if conf.MetricsEndpoint == "" {
conf.MetricsEndpoint = "/metrics"
log.Println("Metrics endpoint:", conf.MetricsEndpoint)
}
if conf.ScrapeInterval == 0 {
conf.ScrapeInterval = 300
log.Println("Scrape interval:", conf.ScrapeInterval)
}
}