diff --git a/metrics_config/grafana_metrics.json b/metrics_config/grafana_metrics.json index 6129bf090f..d7f2d9f4a7 100644 --- a/metrics_config/grafana_metrics.json +++ b/metrics_config/grafana_metrics.json @@ -15,7 +15,13 @@ "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "11.0.0" + "version": "11.1.1" + }, + { + "type": "panel", + "id": "histogram", + "name": "Histogram", + "version": "" }, { "type": "datasource", @@ -215,6 +221,7 @@ "graphMode": "area", "justifyMode": "auto", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "lastNotNull" @@ -226,7 +233,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.1", "targets": [ { "datasource": { @@ -287,6 +294,7 @@ "graphMode": "area", "justifyMode": "auto", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "lastNotNull" @@ -298,7 +306,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.1", "targets": [ { "datasource": { @@ -462,6 +470,7 @@ "graphMode": "area", "justifyMode": "auto", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "lastNotNull" @@ -473,7 +482,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.1", "targets": [ { "datasource": { @@ -534,6 +543,7 @@ "graphMode": "area", "justifyMode": "auto", "orientation": "auto", + "percentChangeColorMode": "standard", "reduceOptions": { "calcs": [ "lastNotNull" @@ -545,7 +555,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "11.0.0", + "pluginVersion": "11.1.1", "targets": [ { "datasource": { @@ -2097,6 +2107,103 @@ ], "title": "Bandwidth by Protocol", "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "fillOpacity": 80, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineWidth": 1, + "stacking": { + "group": "A", + "mode": "none" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 67 + }, + "id": 29, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "exemplar": false, + "expr": "PropagationTimes_count{label=\"block propagation time (sec)\"}", + "format": "time_series", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "{{label}}", + "range": true, + "refId": "A", + "useBackend": false + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "PropagationTimes_count{label=\"header propagation time (sec)\"}", + "format": "time_series", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "{{label}}", + "range": true, + "refId": "B", + "useBackend": false + } + ], + "title": "Propagation Times", + "type": "histogram" } ], "refresh": "5s", @@ -2109,11 +2216,10 @@ "from": "now-15m", "to": "now" }, - "timeRangeUpdatedDuringEditOrView": false, "timepicker": {}, "timezone": "", "title": "Go-quai Metrics Under Development", "uid": "adae3653-aaad-4a59-9c93-5827d20896b9-v3", - "version": 4, + "version": 1, "weekStart": "" } \ No newline at end of file diff --git a/metrics_config/metrics.go b/metrics_config/metrics.go index 57992e979d..daba1a9737 100644 --- a/metrics_config/metrics.go +++ b/metrics_config/metrics.go @@ -27,6 +27,7 @@ var enabled bool var registeredGauges = make(map[string]*prometheus.GaugeVec) var registeredCounters = make(map[string]*prometheus.CounterVec) +var registeredHistograms = make(map[string]*prometheus.HistogramVec) // Init enables or disables the metrics system. Since we need this to run before // any other code gets to create meters and timers, we'll actually do an ugly hack @@ -112,6 +113,19 @@ func NewCounterVec(name string, help string) *prometheus.CounterVec { return counterVec } +func NewHistogramVec(name string, help string) *prometheus.HistogramVec { + if histVec, exists := registeredHistograms[name]; exists { + return histVec + } + histVec := prometheus.NewHistogramVec(prometheus.HistogramOpts{ + Name: name, + Help: help, + }, []string{"label"}) + prometheus.Register(histVec) + registeredHistograms[name] = histVec + return histVec +} + func NewTimer(name string, help string) *prometheus.Timer { timeHistogram := prometheus.NewHistogram(prometheus.HistogramOpts{ Name: name, diff --git a/p2p/node/api.go b/p2p/node/api.go index 794f32b594..ea7c35e3b8 100644 --- a/p2p/node/api.go +++ b/p2p/node/api.go @@ -11,6 +11,7 @@ import ( "github.com/dominant-strategies/go-quai/core/types" "github.com/dominant-strategies/go-quai/log" + "github.com/dominant-strategies/go-quai/metrics_config" "github.com/dominant-strategies/go-quai/p2p" "github.com/dominant-strategies/go-quai/p2p/node/pubsubManager" "github.com/dominant-strategies/go-quai/p2p/node/streamManager" @@ -23,6 +24,12 @@ import ( "github.com/dominant-strategies/go-quai/common" ) +var ( + propagationTimes = metrics_config.NewHistogramVec("PropagationTimes", "message propagation times by type (sec)") + blockPropagationHist = propagationTimes.WithLabelValues("block propagation time (sec)") + headerPropagationHist = propagationTimes.WithLabelValues("header propagation time (sec)") +) + const requestTimeout = 10 * time.Second // Starts the node and all of its services @@ -371,8 +378,12 @@ func (p *P2PNode) handleBroadcast(sourcePeer peer.ID, Id string, topic string, d switch v := data.(type) { case types.WorkObjectHeaderView: + dt := uint64(time.Now().Unix()) - v.Time() + headerPropagationHist.Observe(float64(dt)) p.cacheAdd(v.Hash(), &v, nodeLocation) case types.WorkObjectBlockView: + dt := uint64(time.Now().Unix()) - v.Time() + blockPropagationHist.Observe(float64(dt)) p.cacheAdd(v.Hash(), &v, nodeLocation) }