mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-27 07:39:05 +01:00
Read config file path from commandline
This commit is contained in:
parent
40265726ed
commit
4ee4e617b2
@ -11,6 +11,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
"flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
// List of provided collectors. Which collector should be run can be
|
// List of provided collectors. Which collector should be run can be
|
||||||
@ -51,12 +52,19 @@ func LoadConfiguration(file string, config *GlobalConfig) error {
|
|||||||
defer configFile.Close()
|
defer configFile.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
jsonParser := json.NewDecoder(configFile)
|
jsonParser := json.NewDecoder(configFile)
|
||||||
jsonParser.Decode(config)
|
jsonParser.Decode(config)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReadCli() string {
|
||||||
|
cfg := flag.String("config", "./config.json", "Path to configuration file")
|
||||||
|
flag.Parse()
|
||||||
|
return *cfg
|
||||||
|
}
|
||||||
|
|
||||||
// Register an interrupt handler for Ctrl+C and similar. At signal,
|
// Register an interrupt handler for Ctrl+C and similar. At signal,
|
||||||
// all collectors are closed
|
// all collectors are closed
|
||||||
func shutdown(wg *sync.WaitGroup, config *GlobalConfig, sink sinks.SinkFuncs) {
|
func shutdown(wg *sync.WaitGroup, config *GlobalConfig, sink sinks.SinkFuncs) {
|
||||||
@ -86,9 +94,14 @@ func main() {
|
|||||||
log.Print(err)
|
log.Print(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
configfile := ReadCli()
|
||||||
|
|
||||||
// Load and check configuration
|
// Load and check configuration
|
||||||
LoadConfiguration("config.json", &config)
|
err = LoadConfiguration(configfile, &config)
|
||||||
|
if (err != nil) {
|
||||||
|
log.Print("Error reading configuration file ", configfile)
|
||||||
|
return
|
||||||
|
}
|
||||||
if config.Interval <= 0 || time.Duration(config.Interval)*time.Second <= 0 {
|
if config.Interval <= 0 || time.Duration(config.Interval)*time.Second <= 0 {
|
||||||
log.Print("Configuration value 'interval' must be greater than zero")
|
log.Print("Configuration value 'interval' must be greater than zero")
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user