From f0ca83cc48af8e3ebdfb7136566c15d1c0af7082 Mon Sep 17 00:00:00 2001 From: Sch8ill <92382209+Sch8ill@users.noreply.github.com> Date: Sat, 30 Nov 2024 00:40:36 -0400 Subject: [PATCH] fix traffic metric with faulty session log source --- README.md | 3 ++- metrics/metrics.go | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 24faa4d..9b6e8c6 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ scrape_configs: | name | description | labels | type | |-------------------------------------|-------------------------------------------------------|--------------------|--------------| | myst_node_bandwidth | Internet bandwidth of the node | id, name | mbit/s | -| myst_node_traffic | Traffic transferred by the node over the last 30 days | id, name, service, country | gigabytes | +| myst_node_traffic | Traffic transferred by the node over the last 30 days | id, name | gigabytes | | myst_node_quality | Quality score assigned to the node | id, name | float | | myst_node_service | whether a service on the node is running | id, name, service | boolean | | myst_node_earnings | Earnings by service of node over the last 30 days | id, name, service | MYST | @@ -76,6 +76,7 @@ scrape_configs: | myst_node_earnings_unsettled | Unsettled earnings by node | id, name | MYST | | myst_node_sessions | Number of sessions of the node over the last 30 days | id, name, service, country | int | | myst_node_session_earings | Earnings by node, generated from session log | id, name, service, country | MYST | +| myst_node_session_traffic | Traffic served by node, generated from session log | id, name, service, country | gigabyte | | myst_node_session_durations | Total duration of sessions over the last 30 days | id, name, service, country | seconds | | myst_token_price | Current price of the MYST token | currency | EUR/USD | | myst_node_location | Location of the node | id, name, location | country code | diff --git a/metrics/metrics.go b/metrics/metrics.go index 7aef8fd..6c2c0c8 100755 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -23,8 +23,8 @@ var nodeBandwidth = prometheus.NewGaugeVec(prometheus.GaugeOpts{ var nodeTraffic = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: "myst_node_traffic", - Help: "Traffic transferred by the node by service and country over the last 30 days", -}, []string{"id", "name", "service", "country"}) + Help: "Traffic transferred by the node over the last 30 days", +}, []string{"id", "name"}) var nodeUserID = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: "myst_node_user_id", @@ -181,6 +181,11 @@ var nodeSessionEarnings = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Help: "Earnings by node, service and country generated from session log", }, []string{"id", "name", "service", "country"}) +var nodeSessionTraffic = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "myst_node_session_traffic", + Help: "Traffic served by node by service and country, generated from session log", +}, []string{"id", "name", "service", "country"}) + var nodeSessionDurations = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: "myst_node_session_durations", Help: "Total duration of sessions of the node by service and country over the last 30 days", @@ -212,8 +217,8 @@ func init() { nodeAvailableAt, nodeCreatedAt, nodeUpdatedAt, nodeDeleted, nodeLauncherVersion, nodeIPTagged, nodeMonitoringFailed, nodeMonitoringFailedLastAt, nodeOnline, nodeOnlineLastAt, nodeStatusCreatedAt, nodeStatusUpdatedAt, nodeIPCategory, nodeLocation, nodeQuality, nodeService, nodeMonitoringStatus, - nodeEarnings, nodeSessions, nodeSessionEarnings, nodeSessionDurations, nodeLifetimeEarnings, - nodeSettledEarnings, nodeUnsettledEarnings, mystPrice) + nodeEarnings, nodeSessions, nodeSessionEarnings, nodeSessionTraffic, nodeSessionDurations, + nodeLifetimeEarnings, nodeSettledEarnings, nodeUnsettledEarnings, mystPrice) } func NodeCount(n int) { @@ -245,7 +250,7 @@ func NodeSessions(id string, name string, sessions []node.Session) { for f, total := range sessionCount { nodeSessions.WithLabelValues(id, name, f.service, f.country).Set(float64(total)) - nodeTraffic.WithLabelValues(id, name, f.service, f.country).Set(traffic[f]) + nodeSessionTraffic.WithLabelValues(id, name, f.service, f.country).Set(traffic[f]) nodeSessionDurations.WithLabelValues(id, name, f.service, f.country).Set(float64(durations[f].Seconds())) nodeSessionEarnings.WithLabelValues(id, name, f.service, f.country).Set(earnings[f]) } @@ -299,6 +304,7 @@ func NodeLifetimeEarnings(id string, name string, earnings node.LifetimeEarnings func NodeTotals(id string, name string, t *totals.Totals) { nodeBandwidth.WithLabelValues(id, name).Set(t.BandwidthTotal) + nodeTraffic.WithLabelValues(id, name).Set(t.TrafficTotal * 1024) } func MystPrices(prices map[string]float64) {