From 62c76c4ced042f9ec3710fd9105ae62c386d8119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 11 Jul 2019 13:42:56 -0400 Subject: [PATCH] allow the metrics call to fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Starting from 1.9.0 Geth removed the `debug_metrics` RPC call Signed-off-by: Jakub SokoĊ‚owski --- README.md | 2 ++ collector.go | 18 +++++++++++------- metrics.go | 2 ++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3a1947b..0877f24 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# WARNING: This software is deprecated since Geth `1.9.0` which introduced its own [Prometheus endpoint](https://blog.ethereum.org/2019/07/10/geth-v1-9-0/#metrics-collection). + # geth_exporter `geth_exporter` is a metrics exporter for [Prometheus](https://github.com/prometheus/prometheus). diff --git a/collector.go b/collector.go index c3ba728..7253261 100644 --- a/collector.go +++ b/collector.go @@ -39,18 +39,22 @@ func (c *collector) collect() (flatMetrics, error) { m, err := cl.metrics() if err != nil { - return nil, err + /* not all geth nodes have debug enabled, s might be nil */ + log.Printf("failed to get metrics: %v", err) } + /* can handle m being nil, will just return an empty flatMetrics */ all := transformMetrics(m) - /* optional syncing stats */ s, err := cl.syncingMetrics() - if err == nil { - sync := decodeSyncData(s, "sync_") - for k, v := range sync { - all[k] = v - } + if err != nil { + /* not all geth nodes have eth enabled, s might be nil */ + log.Printf("failed to get syncing stats: %v", err) + } + + sync := decodeSyncData(s, "sync_") + for k, v := range sync { + all[k] = v } for k := range all { diff --git a/metrics.go b/metrics.go index 6fb685e..3fcdbea 100644 --- a/metrics.go +++ b/metrics.go @@ -34,6 +34,8 @@ func transformMetrics(data metrics) flatMetrics { return flattenMetrics(data, make(flatMetrics), "") } +/* flattenMetrics can handle data being nil, it will just return memo. + * A range over a nil slice is like a range over an empty slice. */ func flattenMetrics(data metrics, memo flatMetrics, prefix string) flatMetrics { for k, v := range data { key := prefix + normalizeKey(k)