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