-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
91 lines (70 loc) · 1.88 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"flag"
"github.com/DITAS-Project/VDC-Throughput-Agent/throughputagent"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
)
var (
Build string
)
var logger = logrus.New()
var log *logrus.Entry
func init() {
if Build == "" {
Build = "Debug"
}
logger.Formatter = new(prefixed.TextFormatter)
logger.SetLevel(logrus.DebugLevel)
log = logger.WithFields(logrus.Fields{
"prefix": "thr-agn",
"build": Build,
})
}
/*
TODO:
- Logging (like always)
- push to Elastic
- failsafe
*/
func main() {
viper.SetConfigName("traffic")
viper.AddConfigPath("/etc/ditas/")
viper.AddConfigPath("/.config/")
viper.AddConfigPath(".config/")
viper.AddConfigPath(".")
viper.SetDefault("ElasticSearchURL", "http://localhost:9200")
viper.SetDefault("ElasticBasicAuth", false)
viper.SetDefault("ElasticUser", "")
viper.SetDefault("ElasticPassword", "")
viper.SetDefault("windowTime", 1)
viper.SetDefault("VDCName", "dummyVDC")
err := viper.ReadInConfig()
if err != nil {
log.Errorf("Fatal error config file: %s \n", err)
}
log.Infof("config file used @ %s", viper.ConfigFileUsed())
viper.RegisterAlias("elastic", "ElasticSearchURL")
flag.String("elastic", "http://localhost:9200", "used to define the elasticURL")
flag.Int("wt", 1, "wait time for each monitoring window")
flag.Bool("verbose", false, "enable verbose logging")
flag.Bool("trace", false, "enable very verbose logging")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
if viper.GetBool("trace") {
viper.Set("verbose", true)
}
if viper.GetBool("verbose") {
logger.SetLevel(logrus.DebugLevel)
}
throughputagent.SetLogger(logger)
throughputagent.SetLog(log)
agent, err := throughputagent.NewThroughputAgent()
if err != nil {
log.Fatal(err)
}
agent.Run()
}