diff --git a/lib/agent.js b/lib/agent.js index 00ee26561e..ff75e37d99 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -684,3 +684,7 @@ Agent.prototype.registerMetric = function (name, labelsOrCallback, callback) { this._metrics.getOrCreateGauge(name, callback, labels) } + +Agent.prototype.registerMetricCounter = function (name, dimensions) { + return this._metrics.getOrCreateCounter(name, dimensions) +} diff --git a/lib/metrics/reporter.js b/lib/metrics/reporter.js index 93e1dc68b0..cfec4ccd0d 100644 --- a/lib/metrics/reporter.js +++ b/lib/metrics/reporter.js @@ -48,7 +48,13 @@ class MetricsReporter extends Reporter { } if (metric.metricImpl.constructor.name === 'Counter') { - metric.metricImpl.reset() + // We need a way to avoid ignoring metrics that might go stale + // because we want values for each counter to appear in every document + // This is not a great check but there does not seem to be a way + // to provide meta data about a metric to enable to better check + if (!metric.name.startsWith('kibana')) { + metric.metricImpl.reset() + } } } @@ -68,6 +74,11 @@ class MetricsReporter extends Reporter { // if a metric is a counting metric and that count is // zero, then the metric is considered stale if (metric.metricImpl && metric.metricImpl._count === 0) { + // We need a way to avoid ignoring metrics that might go stale + // because we want values for each counter to appear in every document + // This is not a great check but there does not seem to be a way + // to provide meta data about a metric to enable to better check + if (metric.name.startsWith('kibana')) return false return true } return false