allow the metrics call to fail

Starting from 1.9.0 Geth removed the `debug_metrics` RPC call

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-07-11 13:42:56 -04:00 committed by Jakub
parent 3a4b493ab7
commit 62c76c4ced
3 changed files with 15 additions and 7 deletions

View File

@ -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).

View File

@ -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 {

View File

@ -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)