yanic/models/config.go

56 lines
1.2 KiB
Go
Raw Normal View History

2016-03-07 09:52:52 +01:00
package models
import (
"io/ioutil"
"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 {
Enable bool
Interface string
CollectInterval Duration
}
2016-03-07 09:52:52 +01:00
Webserver struct {
Enable bool
2017-01-29 20:06:56 +01:00
Bind string
Webroot string
}
2016-03-07 09:52:52 +01:00
Nodes struct {
Enable bool
NodesVersion int
NodesPath string
GraphPath string
StatePath string
SaveInterval Duration // Save nodes periodically
OfflineAfter Duration // Set node to offline if not seen within this period
PruneAfter Duration // Remove nodes after n days of inactivity
}
2016-03-12 03:36:02 +01:00
Influxdb struct {
Enable bool
Address string
Database string
Username string
Password string
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
}
// 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{}
file, err := ioutil.ReadFile(path)
2016-03-07 09:52:52 +01:00
if err != nil {
panic(err)
2016-03-07 09:52:52 +01:00
}
if err := toml.Unmarshal(file, config); err != nil {
panic(err)
}
2016-03-07 09:52:52 +01:00
return config
}