-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
56 lines (48 loc) · 1.22 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
54
55
56
package main
import (
"io"
"io/ioutil"
"gopkg.in/yaml.v2"
)
type Config struct {
Metrics []Metric `yaml:"metrics"`
}
type Metric struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
ValueMin int `yaml:"value_min"`
ValueMax int `yaml:"value_max"`
Value *float64 `json:"value"`
Labels map[string][]string `yaml:"labels"`
MaxCardinality int `yaml:"max_cardinality"`
}
var (
defaultConfig = &Config{
Metrics: []Metric{
{
Name: "cpu_usage",
Type: "gauge",
ValueMin: 0,
ValueMax: 100,
Labels: map[string][]string{
"instance": {"localhost:8080"},
"cluster": {"dev", "prod", "staging", "test", "qa"},
"region": {"us-east-1", "us-west-1", "us-west-2", "eu-west-1", "eu-central-1"},
"service": {"api", "web", "db", "cache", "queue", "worker"},
},
MaxCardinality: 10,
},
},
}
)
func GetConfig(confReader io.Reader) (*Config, error) {
yamlFile, err := ioutil.ReadAll(confReader)
if err != nil {
return nil, err
}
var conf Config
if err = yaml.Unmarshal(yamlFile, &conf); err != nil {
return nil, err
}
return &conf, nil
}