-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
131 lines (115 loc) · 3.38 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"log"
"strings"
"time"
"github.com/hora-prediction/hora/adm"
"github.com/hora-prediction/hora/cfp"
"github.com/hora-prediction/hora/eval"
"github.com/hora-prediction/hora/fpm"
"github.com/hora-prediction/hora/mondat"
"github.com/hora-prediction/hora/resultio"
"github.com/spf13/viper"
)
func main() {
// Read configurations
log.Println("Reading configuration")
viper.SetConfigName("config") // name of config file (without extension)
viper.SetConfigType("toml")
viper.AddConfigPath(".")
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
log.Println("Fatal error config file: %s \n", err)
}
viper.SetEnvPrefix("hora") // will be uppercased automatically
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
batchMode := viper.GetBool("prediction.batch")
// Read first ADM before continue
admController := adm.NewController()
log.Println("Waiting for ADM")
m := <-admController.AdmCh
log.Println("Waiting for ADM done")
// Creating CFPs
cfpController, cfpResultCh := cfp.NewController(m)
// Creating FPM
f, fpmResultCh, err := fpm.NewBayesNetR(m)
if err != nil {
log.Println("Error creating FPM", err)
}
resultWriter, err := resultio.New(
viper.GetString("influxdb.hora.addr"),
viper.GetString("influxdb.hora.username"),
viper.GetString("influxdb.hora.password"),
viper.GetString("influxdb.hora.db"),
)
if err != nil {
log.Printf("Error creating InfluxDB result writer. %s", err)
}
influxKiekerReader := mondat.InfluxKiekerReader{
Archdepmod: m,
KiekerDb: mondat.InfluxDBConfig{
Addr: viper.GetString("influxdb.kieker.addr"),
Username: viper.GetString("influxdb.kieker.username"),
Password: viper.GetString("influxdb.kieker.password"),
DbName: viper.GetString("influxdb.kieker.db"),
},
K8sDb: mondat.InfluxDBConfig{
Addr: viper.GetString("influxdb.k8s.addr"),
Username: viper.GetString("influxdb.k8s.username"),
Password: viper.GetString("influxdb.k8s.password"),
DbName: viper.GetString("influxdb.k8s.db"),
},
LocustDb: mondat.InfluxDBConfig{
Addr: viper.GetString("influxdb.locust.addr"),
Username: viper.GetString("influxdb.locust.username"),
Password: viper.GetString("influxdb.locust.password"),
DbName: viper.GetString("influxdb.locust.db"),
},
Batch: batchMode,
Interval: time.Minute,
Starttime: viper.GetTime("prediction.starttime"),
Endtime: viper.GetTime("prediction.endtime"),
}
evaluator := eval.New()
go func() {
for {
m := <-admController.AdmCh
log.Println("Updating ADM")
influxKiekerReader.UpdateADM(m)
cfpController.UpdateADM(m)
f.UpdateAdm(m)
log.Println("Updating ADM done")
}
}()
go func() {
for {
cfpResult := <-cfpResultCh
f.UpdateCfpResult(cfpResult)
evaluator.UpdateCfpResult(cfpResult)
resultWriter.WriteCfpResult(cfpResult)
}
}()
go func() {
for {
fpmResult := <-fpmResultCh
evaluator.UpdateFpmResult(fpmResult)
resultWriter.WriteFpmResult(fpmResult)
}
}()
// Start reading monitoring data
monDatCh := influxKiekerReader.Read()
for {
monDat, ok := <-monDatCh
if !ok {
log.Println("Monitoring data channel closed. Terminating")
break
}
cfpController.AddMonDat(monDat)
evaluator.UpdateMondat(monDat)
}
if batchMode {
log.Println("Running evaluation")
evaluator.ComputeROC()
}
}