From a7ac63c235af414d25626bd9b1c3b17b065d3d1b Mon Sep 17 00:00:00 2001 From: Ryan Merrick Date: Wed, 27 Jan 2016 14:24:05 +0000 Subject: [PATCH] Update new relic plugin to correctly handle 1 minute time periods requested on the hour. (+1 squashed commits) Squashed commits: [57f5f76] Update new relic plugin to correctly handle 1 minute time periods requested on the hour. --- plugins/inputs/newrelic/newrelic.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/plugins/inputs/newrelic/newrelic.go b/plugins/inputs/newrelic/newrelic.go index b6bef3021..6c80ab82c 100644 --- a/plugins/inputs/newrelic/newrelic.go +++ b/plugins/inputs/newrelic/newrelic.go @@ -129,24 +129,26 @@ func (nr *NewRelic) Gather(acc inputs.Accumulator) error { } if len(nr.Metrics) > 0 { - t := time.Now() - tFrom := fmt.Sprintf("%d-%02d-%02dT%02d:%02d:%02d-00:00\n", - t.Year(), t.Month(), t.Day(), - t.Hour(), t.Minute()-1, t.Second()) + tNow := time.Now() + tFrom := tNow.Add(-1 * time.Minute) - tTo := fmt.Sprintf("%d-%02d-%02dT%02d:%02d:%02d-00:00\n", - t.Year(), t.Month(), t.Day(), - t.Hour(), t.Minute(), t.Second()) + tFromStr := fmt.Sprintf("%d-%02d-%02dT%02d:%02d:%02d-00:00\n", + tFrom.Year(), tFrom.Month(), tFrom.Day(), + tFrom.Hour(), tFrom.Minute(), 00) + + tToStr := fmt.Sprintf("%d-%02d-%02dT%02d:%02d:%02d-00:00\n", + tNow.Year(), tNow.Month(), tNow.Day(), + tNow.Hour(), tNow.Minute(), 00) vals := url.Values{} + vals.Add("from", tFromStr) + vals.Add("to", tToStr) + for k := range nr.Metrics { vals.Add("names[]", k) } - vals.Add("from", tFrom) - vals.Add("to", tTo) - result := conn.GetMetricData(nr.APPID, vals) var fieldsMetrics map[string]interface{}