metrics: Use labels for pool statistics

It's very likely that you'll want to operate over common pool statistics
together.
This commit is contained in:
Jack Grigg 2021-03-14 11:33:15 +13:00
parent 78b83fd6e9
commit 0f9e4b9472
1 changed files with 17 additions and 11 deletions

View File

@ -3217,7 +3217,7 @@ void PruneAndFlush() {
} }
struct PoolMetrics { struct PoolMetrics {
size_t commitments; std::optional<size_t> commitments;
std::optional<CAmount> value; std::optional<CAmount> value;
static PoolMetrics Sprout(CBlockIndex *pindex, CCoinsViewCache *view) { static PoolMetrics Sprout(CBlockIndex *pindex, CCoinsViewCache *view) {
@ -3239,22 +3239,28 @@ struct PoolMetrics {
SaplingMerkleTree saplingTree; SaplingMerkleTree saplingTree;
if (view->GetSaplingAnchorAt(pindex->hashFinalSaplingRoot, saplingTree)) { if (view->GetSaplingAnchorAt(pindex->hashFinalSaplingRoot, saplingTree)) {
stats.commitments = saplingTree.size(); stats.commitments = saplingTree.size();
} else {
stats.commitments = 0;
} }
return stats; return stats;
} }
}; };
#define RenderPoolMetrics(poolName, poolMetrics) \ #define RenderPoolMetrics(poolName, poolMetrics) \
do { \ do { \
static constexpr const char* poolCommitments = \ if (poolMetrics.commitments) { \
"pool." poolName ".commitments"; \ MetricsStaticGauge( \
static constexpr const char* poolValue = \ "pool.commitments", \
"pool." poolName ".value.zatoshis"; \ poolMetrics.commitments.value(), \
MetricsGauge(poolCommitments, poolMetrics.commitments); \ "name", poolName); \
if (poolMetrics.value) { \ } \
MetricsGauge(poolValue, poolMetrics.value.value()); \ if (poolMetrics.value) { \
} \ MetricsStaticGauge( \
"pool.value.zatoshis", \
poolMetrics.value.value(), \
"name", poolName); \
} \
} while (0) } while (0)
/** Update chainActive and related internal data structures. */ /** Update chainActive and related internal data structures. */