From 0f9e4b9472b9ce960104039d3153e7c75da0692d Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sun, 14 Mar 2021 11:33:15 +1300 Subject: [PATCH] metrics: Use labels for pool statistics It's very likely that you'll want to operate over common pool statistics together. --- src/main.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index cf4bb62a4..00cbd2316 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3217,7 +3217,7 @@ void PruneAndFlush() { } struct PoolMetrics { - size_t commitments; + std::optional commitments; std::optional value; static PoolMetrics Sprout(CBlockIndex *pindex, CCoinsViewCache *view) { @@ -3239,22 +3239,28 @@ struct PoolMetrics { SaplingMerkleTree saplingTree; if (view->GetSaplingAnchorAt(pindex->hashFinalSaplingRoot, saplingTree)) { stats.commitments = saplingTree.size(); + } else { + stats.commitments = 0; } return stats; } }; -#define RenderPoolMetrics(poolName, poolMetrics) \ - do { \ - static constexpr const char* poolCommitments = \ - "pool." poolName ".commitments"; \ - static constexpr const char* poolValue = \ - "pool." poolName ".value.zatoshis"; \ - MetricsGauge(poolCommitments, poolMetrics.commitments); \ - if (poolMetrics.value) { \ - MetricsGauge(poolValue, poolMetrics.value.value()); \ - } \ +#define RenderPoolMetrics(poolName, poolMetrics) \ + do { \ + if (poolMetrics.commitments) { \ + MetricsStaticGauge( \ + "pool.commitments", \ + poolMetrics.commitments.value(), \ + "name", poolName); \ + } \ + if (poolMetrics.value) { \ + MetricsStaticGauge( \ + "pool.value.zatoshis", \ + poolMetrics.value.value(), \ + "name", poolName); \ + } \ } while (0) /** Update chainActive and related internal data structures. */