diff --git a/.travis.yml b/.travis.yml index 09ccfac..9dd032d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,14 +3,13 @@ sudo: false language: go go: - - 1.6.x - 1.7.x - 1.8.x + - 1.9.x - tip os: - linux - - osx branches: only: diff --git a/common/redis-latency-monitor.spec b/common/redis-latency-monitor.spec index 48c72af..d4b9013 100644 --- a/common/redis-latency-monitor.spec +++ b/common/redis-latency-monitor.spec @@ -10,7 +10,7 @@ Summary: Tiny Redis client for latency measurement Name: redis-latency-monitor -Version: 2.3.1 +Version: 2.4.0 Release: 0%{?dist} Group: Applications/System License: EKOL @@ -58,6 +58,9 @@ rm -rf %{buildroot} ############################################################################### %changelog +* Tue Oct 03 2017 Anton Novojilov - 2.4.0-0 +- Added option -T/--timestamps for output time as unix timestamp + * Thu Jul 06 2017 Anton Novojilov - 2.3.1-0 - Added auth error handling diff --git a/readme.md b/readme.md index 5d4addf..51ab4ad 100644 --- a/readme.md +++ b/readme.md @@ -16,7 +16,7 @@ Before the initial install allows git to use redirects for [pkg.re](https://gith git config --global http.https://pkg.re.followRedirects true ``` -To build the `redis-latency-monitor` from scratch, make sure you have a working Go 1.6+ workspace ([instructions](https://golang.org/doc/install)), then: +To build the `redis-latency-monitor` from scratch, make sure you have a working Go 1.7+ workspace ([instructions](https://golang.org/doc/install)), then: ``` go get github.com/essentialkaos/redis-latency-monitor @@ -61,6 +61,7 @@ Options --password, -a password Password to use when connecting to the server --timeout, -t 1-300 Connection timeout in seconds (3 by default) --interval, -i 1-3600 Interval in seconds (60 by default) + --timestamps, -T Use unix timestamps in output --output, -o file Path to output CSV file --error-log, -e file Path to log with error messages --no-color, -nc Disable colors in output diff --git a/redis-latency-monitor.go b/redis-latency-monitor.go index a079d10..e9e923b 100644 --- a/redis-latency-monitor.go +++ b/redis-latency-monitor.go @@ -1,3 +1,5 @@ +// +build linux + package main // ////////////////////////////////////////////////////////////////////////////////// // @@ -33,7 +35,7 @@ import ( const ( APP = "Redis Latency Monitor" - VER = "2.3.1" + VER = "2.4.0" DESC = "Tiny Redis client for latency measurement" ) @@ -43,34 +45,36 @@ const ( ) const ( - OPT_HOST = "h:host" - OPT_PORT = "p:port" - OPT_AUTH = "a:password" - OPT_TIMEOUT = "t:timeout" - OPT_INTERVAL = "i:interval" - OPT_CONNECT = "c:connect" - OPT_OUTPUT = "o:output" - OPT_ERROR_LOG = "e:error-log" - OPT_NO_COLOR = "nc:no-color" - OPT_HELP = "help" - OPT_VER = "v:version" + OPT_HOST = "h:host" + OPT_PORT = "p:port" + OPT_AUTH = "a:password" + OPT_TIMEOUT = "t:timeout" + OPT_INTERVAL = "i:interval" + OPT_CONNECT = "c:connect" + OPT_TIMESTAMPS = "T:timestamps" + OPT_OUTPUT = "o:output" + OPT_ERROR_LOG = "e:error-log" + OPT_NO_COLOR = "nc:no-color" + OPT_HELP = "help" + OPT_VER = "v:version" ) // ////////////////////////////////////////////////////////////////////////////////// // // optMap is map with options var optMap = options.Map{ - OPT_HOST: {Value: "127.0.0.1"}, - OPT_PORT: {Value: "6379"}, - OPT_CONNECT: {Type: options.BOOL}, - OPT_TIMEOUT: {Type: options.INT, Value: 3, Min: 1, Max: 300}, - OPT_AUTH: {}, - OPT_INTERVAL: {Type: options.INT, Value: 60, Min: 1, Max: 3600}, - OPT_OUTPUT: {}, - OPT_ERROR_LOG: {}, - OPT_NO_COLOR: {Type: options.BOOL}, - OPT_HELP: {Type: options.BOOL, Alias: "u:usage"}, - OPT_VER: {Type: options.BOOL, Alias: "ver"}, + OPT_HOST: {Value: "127.0.0.1"}, + OPT_PORT: {Value: "6379"}, + OPT_CONNECT: {Type: options.BOOL}, + OPT_TIMEOUT: {Type: options.INT, Value: 3, Min: 1, Max: 300}, + OPT_AUTH: {}, + OPT_INTERVAL: {Type: options.INT, Value: 60, Min: 1, Max: 3600}, + OPT_TIMESTAMPS: {Type: options.BOOL}, + OPT_OUTPUT: {}, + OPT_ERROR_LOG: {}, + OPT_NO_COLOR: {Type: options.BOOL}, + OPT_HELP: {Type: options.BOOL, Alias: "u:usage"}, + OPT_VER: {Type: options.BOOL, Alias: "ver"}, } // pingCommand is PING command data @@ -338,14 +342,25 @@ func printMeasurements(t *table.Table, errors int, measurements []float64, prett formatNumber(p95), formatNumber(p99), ) } else { - outputWriter.WriteString( - fmt.Sprintf( - "%s;%d;%d;%.03f;%.03f;%.03f;%.03f;%.03f;%.03f;%.03f;%.03f;\n", - timeutil.Format(time.Now(), "%Y/%m/%d %H:%M:%S.%K"), - len(measurements), errors, - min, max, men, med, mgh, sdv, p95, p99, - ), - ) + if options.GetB(OPT_TIMESTAMPS) { + outputWriter.WriteString( + fmt.Sprintf( + "%d;%d;%d;%.03f;%.03f;%.03f;%.03f;%.03f;%.03f;%.03f;%.03f;\n", + time.Now().Unix(), len(measurements), errors, + min, max, men, med, mgh, sdv, p95, p99, + ), + ) + } else { + outputWriter.WriteString( + fmt.Sprintf( + "%s;%d;%d;%.03f;%.03f;%.03f;%.03f;%.03f;%.03f;%.03f;%.03f;\n", + timeutil.Format(time.Now(), "%Y/%m/%d %H:%M:%S.%K"), + len(measurements), errors, + min, max, men, med, mgh, sdv, p95, p99, + ), + ) + } + } } @@ -456,6 +471,7 @@ func showUsage() { info.AddOption(OPT_AUTH, "Password to use when connecting to the server", "password") info.AddOption(OPT_TIMEOUT, "Connection timeout in seconds {s-}(3 by default){!}", "1-300") info.AddOption(OPT_INTERVAL, "Interval in seconds {s-}(60 by default){!}", "1-3600") + info.AddOption(OPT_TIMESTAMPS, "Use unix timestamps in output") info.AddOption(OPT_OUTPUT, "Path to output CSV file", "file") info.AddOption(OPT_ERROR_LOG, "Path to log with error messages", "file") info.AddOption(OPT_NO_COLOR, "Disable colors in output")