From 3fba39ae18a45a8e536bcdcf09f41fc55afa1aa7 Mon Sep 17 00:00:00 2001 From: ruflin Date: Mon, 5 Sep 2016 16:31:04 +0200 Subject: [PATCH] Add uptime value to metric reporting This metric can be useful in combination with https://github.com/elastic/beats/pull/2456 to track how long the harvesting of a file took. Uptime is reported before shutdown. --- libbeat/logp/logp.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libbeat/logp/logp.go b/libbeat/logp/logp.go index 8cae9223ea7c..ae3e4ebfd97f 100644 --- a/libbeat/logp/logp.go +++ b/libbeat/logp/logp.go @@ -13,10 +13,19 @@ import ( "github.com/elastic/beats/libbeat/paths" ) -// cmd line flags -var verbose *bool -var toStderr *bool -var debugSelectorsStr *string +var ( + // cmd line flags + verbose *bool + toStderr *bool + debugSelectorsStr *string + + // Beat start time + startTime time.Time +) + +func init() { + startTime = time.Now() +} type Logging struct { Selectors []string @@ -234,4 +243,5 @@ func LogTotalExpvars(cfg *Logging) { snapshotExpvars(vals) metrics := buildMetricsOutput(prevVals, vals) Info("Total non-zero values: %s", metrics) + Info("Uptime: %s", time.Now().Sub(startTime)) }