Skip to content

Commit

Permalink
feature: add cli options config, version and help
Browse files Browse the repository at this point in the history
  • Loading branch information
tbelda-ems committed Jun 26, 2023
1 parent fc00f9b commit 84086bb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Metric timestamp precision will be set according to the polling interval, so it
/path/to/ovirtstat --config /path/to/ovirtstat.conf
```

* Wait for the poll_interval or press enter. You should see lines like those in the Example output below.
* Press enter to force the collectin of metrics. You should see lines like those in the Example output below.


# Example output
Expand Down
28 changes: 27 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
"how often to send metrics",
)
configFile = flag.String("config", "", "path to the config file for this plugin")
showVersion = flag.Bool("version", false, "show ovirtstat version and exit")
showVersion = flag.Bool("version", false, "display ovirtstat version and exit")
err error
)

Expand All @@ -42,6 +42,23 @@ func main() {
}
oV := ovirtstat.New()
oV.SetVersion(Version)
for _, col := range flag.Args() {
switch col {
case "help":
help()
os.Exit(0)
case "version":
fmt.Println(pluginName, Version)
os.Exit(0)
case "config":
fmt.Println(oV.SampleConfig())
os.Exit(0)
case "run":
default:
help()
os.Exit(1)
}
}

// load config an wait for stdin signal from telegraf to gather data
if *configFile != "" {
Expand Down Expand Up @@ -73,3 +90,12 @@ func main() {
}
oV.Stop()
}

func help() {
fmt.Println(pluginName + " [--help] [--config <FILE>] command")
fmt.Println("COMMANDS:")
fmt.Println(" help Display options and commands and exit")
fmt.Println(" config Display full sample configuration and exit")
fmt.Println(" version Display current version and exit")
fmt.Println(" run Run as telegraf execd input plugin using signal=stdin. This is the default command.")
}

0 comments on commit 84086bb

Please sign in to comment.