add args: interval
This commit is contained in:
parent
7dd967a79d
commit
3443d71efe
|
@ -51,11 +51,6 @@ func (r *InputReader) startInput(inputName string) {
|
|||
interval = time.Duration(r.input.GetInterval())
|
||||
}
|
||||
|
||||
// get output quickly
|
||||
if config.Config.TestMode {
|
||||
interval = time.Second * 3
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-r.quitChan:
|
||||
|
|
|
@ -61,7 +61,7 @@ type ConfigType struct {
|
|||
|
||||
var Config *ConfigType
|
||||
|
||||
func InitConfig(configDir string, debugMode bool, testMode bool) error {
|
||||
func InitConfig(configDir string, debugMode, testMode bool, interval int64) error {
|
||||
configFile := path.Join(configDir, "config.toml")
|
||||
if !file.IsExist(configFile) {
|
||||
return fmt.Errorf("configuration file(%s) not found", configFile)
|
||||
|
@ -77,6 +77,10 @@ func InitConfig(configDir string, debugMode bool, testMode bool) error {
|
|||
return fmt.Errorf("failed to load configs of dir: %s", configDir)
|
||||
}
|
||||
|
||||
if interval > 0 {
|
||||
Config.Global.Interval = Duration(time.Duration(interval) * time.Second)
|
||||
}
|
||||
|
||||
if err := Config.fillIP(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
3
main.go
3
main.go
|
@ -25,6 +25,7 @@ var (
|
|||
configDir = flag.String("configs", osx.GetEnv("CATEGRAF_CONFIGS", "conf"), "Specify configuration directory.(env:CATEGRAF_CONFIGS)")
|
||||
debugMode = flag.Bool("debug", false, "Is debug mode?")
|
||||
testMode = flag.Bool("test", false, "Is test mode? print metrics to stdout")
|
||||
interval = flag.Int64("interval", 0, "Global interval(unit:Second)")
|
||||
showVersion = flag.Bool("version", false, "Show version.")
|
||||
inputFilters = flag.String("inputs", "", "e.g. cpu:mem:system")
|
||||
|
||||
|
@ -59,7 +60,7 @@ func main() {
|
|||
printEnv()
|
||||
|
||||
// init configs
|
||||
if err := config.InitConfig(*configDir, *debugMode, *testMode); err != nil {
|
||||
if err := config.InitConfig(*configDir, *debugMode, *testMode, *interval); err != nil {
|
||||
log.Fatalln("F! failed to init config:", err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue