2016-03-07 09:52:52 +01:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
|
2017-01-29 18:30:08 +01:00
|
|
|
"github.com/influxdata/toml"
|
2016-03-07 09:52:52 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
//Config the config File of this daemon
|
|
|
|
type Config struct {
|
2016-03-09 03:26:08 +01:00
|
|
|
Respondd struct {
|
2017-01-29 18:30:08 +01:00
|
|
|
Enable bool
|
|
|
|
Interface string
|
|
|
|
CollectInterval Duration
|
|
|
|
}
|
2016-03-07 09:52:52 +01:00
|
|
|
Webserver struct {
|
2017-01-29 18:30:08 +01:00
|
|
|
Enable bool
|
2017-01-29 20:06:56 +01:00
|
|
|
Bind string
|
2017-01-29 18:30:08 +01:00
|
|
|
Webroot string
|
|
|
|
}
|
2016-03-07 09:52:52 +01:00
|
|
|
Nodes struct {
|
2017-01-29 18:30:08 +01:00
|
|
|
Enable bool
|
|
|
|
NodesVersion int
|
2017-01-29 20:06:56 +01:00
|
|
|
NodesPath string
|
|
|
|
NodesDynamicPath string
|
|
|
|
GraphPath string
|
2017-01-29 18:30:08 +01:00
|
|
|
SaveInterval Duration // Save nodes periodically
|
|
|
|
PruneAfter Duration // Remove nodes after n days of inactivity
|
|
|
|
}
|
2016-03-12 03:36:02 +01:00
|
|
|
Influxdb struct {
|
2017-01-29 18:30:08 +01:00
|
|
|
Enable bool
|
|
|
|
Address string
|
|
|
|
Database string
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
SaveInterval Duration // Save nodes every n seconds
|
|
|
|
DeleteInterval Duration // Delete stats of nodes every n minutes
|
|
|
|
DeleteAfter Duration // Delete stats of nodes till now-deletetill n minutes
|
2016-03-12 03:36:02 +01:00
|
|
|
}
|
2016-03-07 09:52:52 +01:00
|
|
|
}
|
|
|
|
|
2017-01-20 22:27:44 +01:00
|
|
|
// ReadConfigFile reads a config model from path of a yml file
|
2016-03-20 19:54:43 +01:00
|
|
|
func ReadConfigFile(path string) *Config {
|
2016-03-07 09:52:52 +01:00
|
|
|
config := &Config{}
|
2017-01-29 18:30:08 +01:00
|
|
|
file, err := ioutil.ReadFile(path)
|
2016-03-07 09:52:52 +01:00
|
|
|
if err != nil {
|
2017-01-29 18:30:08 +01:00
|
|
|
panic(err)
|
2016-03-07 09:52:52 +01:00
|
|
|
}
|
2017-01-29 18:30:08 +01:00
|
|
|
|
|
|
|
if err := toml.Unmarshal(file, config); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2016-03-07 09:52:52 +01:00
|
|
|
return config
|
|
|
|
}
|