From 7ec0f826e3f342132b72efb19d7c57da1340d6ca Mon Sep 17 00:00:00 2001 From: Nicolas Ruflin Date: Tue, 6 Sep 2016 14:14:53 +0200 Subject: [PATCH] Add uptime value to metric reporting (#2464) 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 8cae9223ea7..ae3e4ebfd97 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)) }