From c50ff0541edbeaeb0a917d1e109df0bf11d66641 Mon Sep 17 00:00:00 2001 From: wizeguyy Date: Fri, 9 Aug 2024 10:53:01 -0500 Subject: [PATCH] Add tx counters by slice --- metrics_config/grafana_metrics.json | 35 +++++++++++++---------------- quai/p2p_backend.go | 17 +++++++++++--- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/metrics_config/grafana_metrics.json b/metrics_config/grafana_metrics.json index d7f2d9f4a7..8e96b6a81f 100644 --- a/metrics_config/grafana_metrics.json +++ b/metrics_config/grafana_metrics.json @@ -187,6 +187,7 @@ "type": "prometheus", "uid": "${DS_PROMETHEUS}" }, + "description": "", "fieldConfig": { "defaults": { "color": { @@ -215,7 +216,7 @@ "x": 12, "y": 1 }, - "id": 21, + "id": 23, "options": { "colorMode": "value", "graphMode": "area", @@ -242,7 +243,7 @@ }, "disableTextWrap": false, "editorMode": "builder", - "expr": "TxpoolGauges{label=\"slots\"}", + "expr": "TxpoolGauges{label=\"queued\"}", "fullMetaSearch": false, "includeNullMetadata": true, "instant": false, @@ -252,7 +253,7 @@ "useBackend": false } ], - "title": "Transaction slots used", + "title": "Gapped", "type": "stat" }, { @@ -435,7 +436,6 @@ "type": "prometheus", "uid": "${DS_PROMETHEUS}" }, - "description": "", "fieldConfig": { "defaults": { "color": { @@ -464,7 +464,7 @@ "x": 12, "y": 5 }, - "id": 23, + "id": 21, "options": { "colorMode": "value", "graphMode": "area", @@ -491,7 +491,7 @@ }, "disableTextWrap": false, "editorMode": "builder", - "expr": "TxpoolGauges{label=\"queued\"}", + "expr": "TxpoolGauges{label=\"slots\"}", "fullMetaSearch": false, "includeNullMetadata": true, "instant": false, @@ -501,7 +501,7 @@ "useBackend": false } ], - "title": "Gapped", + "title": "Transaction slots used", "type": "stat" }, { @@ -939,7 +939,7 @@ "scaleDistribution": { "type": "linear" }, - "showPoints": "never", + "showPoints": "auto", "spanNulls": false, "stacking": { "group": "A", @@ -967,21 +967,20 @@ "overrides": [] }, "gridPos": { - "h": 6, + "h": 14, "w": 12, "x": 12, "y": 19 }, - "id": 25, + "id": 30, "options": { "legend": { "calcs": [], - "displayMode": "table", - "placement": "right", + "displayMode": "list", + "placement": "bottom", "showLegend": true }, "tooltip": { - "maxHeight": 600, "mode": "single", "sort": "none" } @@ -994,7 +993,7 @@ }, "disableTextWrap": false, "editorMode": "code", - "expr": "rate(TxPropagation{label=~\".*\"}[1m])", + "expr": "rate(TxCount{label=~\".*\"}[1m])", "fullMetaSearch": false, "includeNullMetadata": true, "instant": false, @@ -1004,7 +1003,7 @@ "useBackend": false } ], - "title": "Transaction Propagation", + "title": "Transaction Count", "type": "timeseries" }, { @@ -1935,8 +1934,7 @@ "mode": "absolute", "steps": [ { - "color": "green", - "value": null + "color": "green" }, { "color": "red", @@ -2137,8 +2135,7 @@ "mode": "absolute", "steps": [ { - "color": "green", - "value": null + "color": "green" }, { "color": "red", diff --git a/quai/p2p_backend.go b/quai/p2p_backend.go index fcf2e87154..4d1cfb78cb 100644 --- a/quai/p2p_backend.go +++ b/quai/p2p_backend.go @@ -16,6 +16,7 @@ import ( "github.com/dominant-strategies/go-quai/trie" pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/libp2p/go-libp2p/core/peer" + "github.com/prometheus/client_golang/prometheus" ) const ( @@ -24,8 +25,9 @@ const ( var ( // TxPool propagation metrics - txPropagationMetrics = metrics_config.NewCounterVec("TxPropagation", "Transaction propagation counter") - txIngressCounter = txPropagationMetrics.WithLabelValues("ingress") + txPropagationMetrics = metrics_config.NewCounterVec("TxCount", "Transaction counter") + txTotalCounter = txPropagationMetrics.WithLabelValues("total txs") + txCountersBySlice = make(map[string]prometheus.Counter) workObjectMetrics = metrics_config.NewCounterVec("WorkObjectCounters", "Tracks block statistics") // Block propagation metrics @@ -147,7 +149,16 @@ func (qbe *QuaiBackend) OnNewBroadcast(sourcePeer p2p.PeerID, Id string, topic s backend.SendRemoteTxs(data.WorkObject.Transactions()) workShareIngressCounter.Inc() - txIngressCounter.Add(float64(len(data.WorkObject.Transactions()))) + sliceName := data.Location().Name() + txCount := float64(len(data.WorkObject.Transactions())) + txTotalCounter.Add(txCount) + if counter, exists := txCountersBySlice[sliceName]; exists { + counter.Add(txCount) + } else { + newCounter := txPropagationMetrics.WithLabelValues(sliceName + " txs") + newCounter.Add(txCount) + txCountersBySlice[sliceName] = newCounter + } } // If it was a good broadcast, mark the peer as lively qbe.p2pBackend.MarkLivelyPeer(sourcePeer, topic)