From 9ab59693d47e6f09b03eb5c49d7b5497117de643 Mon Sep 17 00:00:00 2001 From: Mark van den Boogaard Date: Thu, 18 Mar 2021 07:10:21 +0100 Subject: [PATCH 1/2] Make it possible to truncate the files on every run. This way you can add this data to Prometheus together with the JSON exporter --- config/options.go | 5 +++-- runners/printer.go | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config/options.go b/config/options.go index 4aca2cc..eae6afe 100644 --- a/config/options.go +++ b/config/options.go @@ -19,8 +19,9 @@ type OptionsType struct { Printer string `short:"p" long:"printer" description:"the output printer to use (valid printers: ncurses, text, json)" default:"ncurses"` - Output string `short:"o" long:"output" description:"the output channel to send printer output (valid output: stdout, file, tcp, udp)" default:"stdout"` - OutputTarget string `long:"target" description:"for output 'file' the location, for 'tcp' or 'udp' the url (host:port) to the server"` + Output string `short:"o" long:"output" description:"the output channel to send printer output (valid output: stdout, file, tcp, udp)" default:"stdout"` + OutputTarget string `long:"target" description:"for output 'file' the location, for 'tcp' or 'udp' the url (host:port) to the server"` + OutputTargetTruncate bool `long:"targettruncate" description:"for output 'file' the target will only contain the latest result (can be used for prometheus json exporter)"` NetworkDevice string `long:"netdev" description:"The network device used for the virtual traffic"` StorageDevice string `long:"storedev" description:"The storage device used for the virtual block devices"` diff --git a/runners/printer.go b/runners/printer.go index 878eb74..43f3532 100644 --- a/runners/printer.go +++ b/runners/printer.go @@ -41,6 +41,14 @@ func InitializePrinter(wg *sync.WaitGroup) { // Print runs one printing cycle func Print() { + if config.Options.Output == "file" && config.Options.OutputTargetTruncate { + err := os.Truncate(config.Options.OutputTarget, 0) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to truncate the output file") + os.Exit(1) + } + } + printable := models.Printable{} // add general domain fields first From 5c218c6118939139e0ca89a825be81c274678c88 Mon Sep 17 00:00:00 2001 From: mvdboogaard Date: Thu, 18 Mar 2021 07:12:23 +0100 Subject: [PATCH 2/2] Replace spaces for tabs --- runners/printer.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/runners/printer.go b/runners/printer.go index 43f3532..69a02a9 100644 --- a/runners/printer.go +++ b/runners/printer.go @@ -41,13 +41,13 @@ func InitializePrinter(wg *sync.WaitGroup) { // Print runs one printing cycle func Print() { - if config.Options.Output == "file" && config.Options.OutputTargetTruncate { - err := os.Truncate(config.Options.OutputTarget, 0) - if err != nil { - fmt.Fprintf(os.Stderr, "failed to truncate the output file") - os.Exit(1) - } - } + if config.Options.Output == "file" && config.Options.OutputTargetTruncate { + err := os.Truncate(config.Options.OutputTarget, 0) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to truncate the output file") + os.Exit(1) + } + } printable := models.Printable{}