From b133213c7a53f0af8f1492b505d52a2031f865ce Mon Sep 17 00:00:00 2001 From: Matthias Rampke Date: Sun, 28 Jul 2019 10:37:10 +0200 Subject: [PATCH] Report non-fatal collection errors in the exporter metric. (#1439) As per prometheus/client_golang#543, pass the Registry for exporter metrics when setting up the /metrics HTTP handler. With this, the `promhttp_metric_handler_errors_total` metric will increment on (possibly non-fatal) collection-time errors, such as duplicate metrics from text files. Signed-off-by: Matthias Rampke --- collector/fixtures/e2e-64k-page-output.txt | 4 ++++ collector/fixtures/e2e-output.txt | 4 ++++ node_exporter.go | 1 + 3 files changed, 9 insertions(+) diff --git a/collector/fixtures/e2e-64k-page-output.txt b/collector/fixtures/e2e-64k-page-output.txt index 8e9ba2cc..14bd80d7 100644 --- a/collector/fixtures/e2e-64k-page-output.txt +++ b/collector/fixtures/e2e-64k-page-output.txt @@ -3539,6 +3539,10 @@ node_zfs_zpool_wupdate{zpool="poolz1"} 1.10734831833266e+14 # TYPE process_virtual_memory_bytes gauge # HELP process_virtual_memory_max_bytes Maximum amount of virtual memory available in bytes. # TYPE process_virtual_memory_max_bytes gauge +# HELP promhttp_metric_handler_errors_total Total number of internal errors encountered by the promhttp metric handler. +# TYPE promhttp_metric_handler_errors_total counter +promhttp_metric_handler_errors_total{cause="encoding"} 0 +promhttp_metric_handler_errors_total{cause="gathering"} 0 # HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served. # TYPE promhttp_metric_handler_requests_in_flight gauge promhttp_metric_handler_requests_in_flight 1 diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index dab7df8c..657856e9 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -3539,6 +3539,10 @@ node_zfs_zpool_wupdate{zpool="poolz1"} 1.10734831833266e+14 # TYPE process_virtual_memory_bytes gauge # HELP process_virtual_memory_max_bytes Maximum amount of virtual memory available in bytes. # TYPE process_virtual_memory_max_bytes gauge +# HELP promhttp_metric_handler_errors_total Total number of internal errors encountered by the promhttp metric handler. +# TYPE promhttp_metric_handler_errors_total counter +promhttp_metric_handler_errors_total{cause="encoding"} 0 +promhttp_metric_handler_errors_total{cause="gathering"} 0 # HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served. # TYPE promhttp_metric_handler_requests_in_flight gauge promhttp_metric_handler_requests_in_flight 1 diff --git a/node_exporter.go b/node_exporter.go index 550d7b13..ceee4e10 100644 --- a/node_exporter.go +++ b/node_exporter.go @@ -116,6 +116,7 @@ func (h *handler) innerHandler(filters ...string) (http.Handler, error) { ErrorLog: log.NewErrorLogger(), ErrorHandling: promhttp.ContinueOnError, MaxRequestsInFlight: h.maxRequests, + Registry: h.exporterMetricsRegistry, }, ) if h.includeExporterMetrics {