Skip to content

Commit

Permalink
Add tx counters by slice
Browse files Browse the repository at this point in the history
  • Loading branch information
wizeguyy committed Aug 12, 2024
1 parent 29852d1 commit c50ff05
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
35 changes: 16 additions & 19 deletions metrics_config/grafana_metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -215,7 +216,7 @@
"x": 12,
"y": 1
},
"id": 21,
"id": 23,
"options": {
"colorMode": "value",
"graphMode": "area",
Expand All @@ -242,7 +243,7 @@
},
"disableTextWrap": false,
"editorMode": "builder",
"expr": "TxpoolGauges{label=\"slots\"}",
"expr": "TxpoolGauges{label=\"queued\"}",
"fullMetaSearch": false,
"includeNullMetadata": true,
"instant": false,
Expand All @@ -252,7 +253,7 @@
"useBackend": false
}
],
"title": "Transaction slots used",
"title": "Gapped",
"type": "stat"
},
{
Expand Down Expand Up @@ -435,7 +436,6 @@
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
Expand Down Expand Up @@ -464,7 +464,7 @@
"x": 12,
"y": 5
},
"id": 23,
"id": 21,
"options": {
"colorMode": "value",
"graphMode": "area",
Expand All @@ -491,7 +491,7 @@
},
"disableTextWrap": false,
"editorMode": "builder",
"expr": "TxpoolGauges{label=\"queued\"}",
"expr": "TxpoolGauges{label=\"slots\"}",
"fullMetaSearch": false,
"includeNullMetadata": true,
"instant": false,
Expand All @@ -501,7 +501,7 @@
"useBackend": false
}
],
"title": "Gapped",
"title": "Transaction slots used",
"type": "stat"
},
{
Expand Down Expand Up @@ -939,7 +939,7 @@
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
Expand Down Expand Up @@ -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"
}
Expand All @@ -994,7 +993,7 @@
},
"disableTextWrap": false,
"editorMode": "code",
"expr": "rate(TxPropagation{label=~\".*\"}[1m])",
"expr": "rate(TxCount{label=~\".*\"}[1m])",
"fullMetaSearch": false,
"includeNullMetadata": true,
"instant": false,
Expand All @@ -1004,7 +1003,7 @@
"useBackend": false
}
],
"title": "Transaction Propagation",
"title": "Transaction Count",
"type": "timeseries"
},
{
Expand Down Expand Up @@ -1935,8 +1934,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
Expand Down Expand Up @@ -2137,8 +2135,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
Expand Down
17 changes: 14 additions & 3 deletions quai/p2p_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c50ff05

Please sign in to comment.