-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
84 lines (71 loc) · 2.07 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"io/ioutil"
"gopkg.in/yaml.v2"
"log"
)
type conf struct {
Discovery discovery `yaml:"discovery"`
Static []static `yaml:"static"`
}
type discovery struct {
ExportedTagsOnMetrics exportedTagsOnMetrics `yaml:"exportedTagsOnMetrics"`
Jobs []job `yaml:"jobs"`
}
type exportedTagsOnMetrics map[string][]string
type job struct {
Region string `yaml:"region"`
Type string `yaml:"type"`
RoleArn string `yaml:"roleArn"`
SearchTags []tag `yaml:"searchTags"`
Metrics []metric `yaml:"metrics"`
}
type static struct {
Name string `yaml:"name"`
Region string `yaml:"region"`
RoleArn string `yaml:"roleArn"`
Namespace string `yaml:"namespace"`
CustomTags []tag `yaml:"customTags"`
Dimensions []dimension `yaml:"dimensions"`
Metrics []metric `yaml:"metrics"`
}
type metric struct {
Name string `yaml:"name"`
Statistics []string `yaml:"statistics"`
AdditionalDimensions []dimension `yaml:"additionalDimensions"`
Period int `yaml:"period"`
Length int `yaml:"length"`
Delay int `yaml:"delay"`
NilToZero bool `yaml:"nilToZero"`
AddCloudwatchTimestamp bool `yaml:"addCloudwatchTimestamp"`
}
type dimension struct {
Name string `yaml:"name"`
Value string `yaml:"value"`
}
type tag struct {
Key string `yaml:"Key"`
Value string `yaml:"Value"`
}
func (c *conf) load(file *string) error {
yamlFile, err := ioutil.ReadFile(*file)
if err != nil {
return err
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
return err
}
for _, job := range c.Discovery.Jobs {
if !stringInSlice(job.Type, supportedServices) {
return fmt.Errorf("Service is not in known list!: %v", job.Type)
}
for _, metric := range job.Metrics {
if metric.Length <= 300 {
log.Output(2, "WATCH OUT! - Metric length of less than 5 minutes configured which is default for most cloudwatch metrics e.g. ELBs")
}
}
}
return nil
}