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 19:40:46 +00:00
|
|
|
Enable bool
|
|
|
|
NodesVersion int
|
|
|
|
NodesPath string
|
|
|
|
GraphPath string
|
|
|
|
StatePath string
|
|
|
|
SaveInterval Duration // Save nodes periodically
|
2017-01-29 20:04:10 +00:00
|
|
|
OfflineAfter Duration // Set node to offline if not seen within this period
|
2017-01-29 19:40:46 +00:00
|
|
|
PruneAfter Duration // Remove nodes after n days of inactivity
|
2017-01-29 17:30:08 +00:00
|
|
|
}
|
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
|
|
|
|
}
|