-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
52 lines (42 loc) · 1.18 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
package main
import (
"log"
"github.com/mitchellh/mapstructure"
"github.com/spf13/viper"
"github.com/urjitbhatia/go-datadog-autoscaler/scaler"
"github.com/zorkian/go-datadog-api"
)
func main() {
config := getConfig()
cl := getDatadogClient(config)
ddMetrics, ok := config.Get("ddMetrics").([]interface{})
if !ok {
log.Fatalln("Error parsing ddMetrics. Lint yaml")
}
for _, ddMetric := range ddMetrics {
metric := &scaler.Metric{}
mapstructure.Decode(ddMetric, metric)
scaler.ProcessMetric(*metric, cl)
}
}
func getDatadogClient(config *viper.Viper) *datadog.Client {
log.Println("Connecting to Datadog")
ddApiKey := config.GetString("ddApiKey")
ddAppKey := config.GetString("ddAppKey")
if len(ddApiKey) == 0 || len(ddAppKey) == 0 {
log.Fatalln("Datadog config missing api key or app key")
}
client := datadog.NewClient(ddApiKey, ddAppKey)
return client
}
func getConfig() *viper.Viper {
config := viper.New()
config.SetConfigType("yaml")
config.SetConfigName("config")
config.AddConfigPath(".")
err := config.ReadInConfig()
if err != nil {
log.Fatalf("Error reading config. Looking for `config.yaml` in the current dir. Err:{%+v}", err)
}
return config
}