From 502ffbadb31d8dfed8850552b0d49c42dd355955 Mon Sep 17 00:00:00 2001 From: ScarletRedMan Date: Sat, 30 Nov 2024 01:17:54 +0700 Subject: [PATCH] feat: added more metrics --- .../api/module/PrometheusMetricsModule.java | 15 + prometheus/grafana_dashboards/jvm.json | 545 +++++++----------- 2 files changed, 233 insertions(+), 327 deletions(-) diff --git a/api/src/main/java/ru/dragonestia/msb3/api/module/PrometheusMetricsModule.java b/api/src/main/java/ru/dragonestia/msb3/api/module/PrometheusMetricsModule.java index 5011b86..f622df9 100644 --- a/api/src/main/java/ru/dragonestia/msb3/api/module/PrometheusMetricsModule.java +++ b/api/src/main/java/ru/dragonestia/msb3/api/module/PrometheusMetricsModule.java @@ -1,9 +1,14 @@ package ru.dragonestia.msb3.api.module; +import io.prometheus.metrics.core.metrics.Counter; +import io.prometheus.metrics.core.metrics.GaugeWithCallback; import io.prometheus.metrics.exporter.httpserver.HTTPServer; import io.prometheus.metrics.instrumentation.jvm.JvmMetrics; +import io.prometheus.metrics.instrumentation.jvm.JvmNativeMemoryMetrics; import lombok.Getter; import lombok.extern.log4j.Log4j2; +import net.minestom.server.MinecraftServer; +import net.minestom.server.event.player.AsyncPlayerPreLoginEvent; import java.net.InetSocketAddress; @@ -28,16 +33,26 @@ public class PrometheusMetricsModule { private static void run(InetSocketAddress address) throws Exception { JvmMetrics.builder().register(); + JvmNativeMemoryMetrics.builder().register(); server = HTTPServer.builder() .inetAddress(address.getAddress()) .port(address.getPort()) .buildAndStart(); + registerDefaultMetrics(); } private static void registerDefaultMetrics() { + GaugeWithCallback.builder() + .name("msb3_online_players") + .callback(c -> c.call(MinecraftServer.getConnectionManager().getOnlinePlayerCount())) + .register(); + var joinedPlayers = Counter.builder().name("msb3_joined_players").register(); + MinecraftServer.getGlobalEventHandler().addListener(AsyncPlayerPreLoginEvent.class, event -> { + joinedPlayers.inc(); + }); } } diff --git a/prometheus/grafana_dashboards/jvm.json b/prometheus/grafana_dashboards/jvm.json index a949b01..f987e90 100644 --- a/prometheus/grafana_dashboards/jvm.json +++ b/prometheus/grafana_dashboards/jvm.json @@ -96,7 +96,7 @@ }, "fieldConfig": { "defaults": { - "decimals": 1, + "decimals": 0, "mappings": [ { "options": { @@ -108,6 +108,7 @@ "type": "special" } ], + "min": 0, "thresholds": { "mode": "absolute", "steps": [ @@ -121,13 +122,13 @@ } ] }, - "unit": "s" + "unit": "none" }, "overrides": [] }, "gridPos": { - "h": 3, - "w": 6, + "h": 4, + "w": 2, "x": 0, "y": 1 }, @@ -135,8 +136,8 @@ "maxDataPoints": 100, "options": { "colorMode": "value", - "graphMode": "none", - "justifyMode": "auto", + "graphMode": "area", + "justifyMode": "center", "orientation": "horizontal", "percentChangeColorMode": "standard", "reduceOptions": { @@ -157,16 +158,96 @@ "type": "prometheus", "uid": "${DS_PROMETHEUS}" }, - "expr": "process_uptime_seconds{application=\"$application\", instance=\"$instance\"}", + "disableTextWrap": false, + "editorMode": "builder", + "expr": "msb3_online_players{application=\"$application\", instance=\"$instance\"}", "format": "time_series", + "fullMetaSearch": false, + "includeNullMetadata": true, "intervalFactor": 2, "legendFormat": "", "metric": "", + "range": true, "refId": "A", - "step": 14400 + "step": 14400, + "useBackend": false } ], - "title": "Uptime", + "title": "Online players", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "decimals": 0, + "mappings": [], + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "yellow", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 2, + "x": 2, + "y": 1 + }, + "id": 146, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.3.1", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "msb3_joined_players_total", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + } + } + ], + "title": "Joined players", "type": "stat" }, { @@ -200,12 +281,12 @@ } ] }, - "unit": "dateTimeAsIso" + "unit": "dateTimeAsLocal" }, "overrides": [] }, "gridPos": { - "h": 3, + "h": 4, "w": 6, "x": 6, "y": 1 @@ -250,6 +331,83 @@ "title": "Start time", "type": "stat" }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "mappings": [ + { + "options": { + "match": "null", + "result": { + "text": "N/A" + } + }, + "type": "special" + } + ], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + }, + "unit": "dateTimeFromNow" + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 6, + "x": 12, + "y": 1 + }, + "id": 147, + "maxDataPoints": 100, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "horizontal", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.3.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "process_start_time_seconds{application=\"$application\", instance=\"$instance\"}*1000", + "format": "time_series", + "intervalFactor": 2, + "legendFormat": "", + "metric": "", + "range": true, + "refId": "A", + "step": 14400 + } + ], + "title": "Started", + "type": "stat" + }, { "datasource": { "type": "prometheus", @@ -293,9 +451,9 @@ "overrides": [] }, "gridPos": { - "h": 3, - "w": 6, - "x": 12, + "h": 4, + "w": 3, + "x": 18, "y": 1 }, "id": 65, @@ -388,9 +546,9 @@ "overrides": [] }, "gridPos": { - "h": 3, - "w": 6, - "x": 18, + "h": 4, + "w": 3, + "x": 21, "y": 1 }, "id": 75, @@ -438,7 +596,7 @@ "h": 1, "w": 24, "x": 0, - "y": 4 + "y": 5 }, "id": 141, "panels": [], @@ -508,10 +666,10 @@ "overrides": [] }, "gridPos": { - "h": 7, - "w": 6, + "h": 9, + "w": 8, "x": 0, - "y": 5 + "y": 6 }, "id": 24, "options": { @@ -520,8 +678,8 @@ "lastNotNull", "max" ], - "displayMode": "list", - "placement": "bottom", + "displayMode": "table", + "placement": "right", "showLegend": true }, "tooltip": { @@ -635,10 +793,10 @@ "overrides": [] }, "gridPos": { - "h": 7, - "w": 6, - "x": 6, - "y": 5 + "h": 9, + "w": 8, + "x": 8, + "y": 6 }, "id": 25, "options": { @@ -647,8 +805,8 @@ "lastNotNull", "max" ], - "displayMode": "list", - "placement": "bottom", + "displayMode": "table", + "placement": "right", "showLegend": true }, "tooltip": { @@ -763,10 +921,10 @@ "overrides": [] }, "gridPos": { - "h": 7, - "w": 6, - "x": 12, - "y": 5 + "h": 9, + "w": 8, + "x": 16, + "y": 6 }, "id": 26, "options": { @@ -775,8 +933,8 @@ "lastNotNull", "max" ], - "displayMode": "list", - "placement": "bottom", + "displayMode": "table", + "placement": "right", "showLegend": true }, "tooltip": { @@ -827,286 +985,19 @@ "title": "JVM Total", "type": "timeseries" }, - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "palette-classic" - }, - "custom": { - "axisBorderShow": false, - "axisCenteredZero": false, - "axisColorMode": "text", - "axisLabel": "", - "axisPlacement": "auto", - "barAlignment": 0, - "barWidthFactor": 0.6, - "drawStyle": "line", - "fillOpacity": 10, - "gradientMode": "none", - "hideFrom": { - "legend": false, - "tooltip": false, - "viz": false - }, - "insertNulls": false, - "lineInterpolation": "linear", - "lineWidth": 1, - "pointSize": 5, - "scaleDistribution": { - "type": "linear" - }, - "showPoints": "never", - "spanNulls": false, - "stacking": { - "group": "A", - "mode": "none" - }, - "thresholdsStyle": { - "mode": "off" - } - }, - "mappings": [], - "min": 0, - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] - }, - "unit": "bytes" - }, - "overrides": [] - }, - "gridPos": { - "h": 7, - "w": 6, - "x": 18, - "y": 5 - }, - "id": 86, - "options": { - "legend": { - "calcs": [ - "lastNotNull", - "max" - ], - "displayMode": "list", - "placement": "bottom", - "showLegend": true - }, - "tooltip": { - "mode": "multi", - "sort": "none" - } - }, - "pluginVersion": "11.3.1", - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "expr": "process_memory_vss_bytes{application=\"$application\", instance=\"$instance\"}", - "format": "time_series", - "hide": true, - "intervalFactor": 2, - "legendFormat": "vss", - "metric": "", - "refId": "A", - "step": 2400 - }, - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "expr": "process_memory_rss_bytes{application=\"$application\", instance=\"$instance\"}", - "format": "time_series", - "intervalFactor": 2, - "legendFormat": "rss", - "refId": "B" - }, - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "expr": "process_memory_swap_bytes{application=\"$application\", instance=\"$instance\"}", - "format": "time_series", - "intervalFactor": 2, - "legendFormat": "swap", - "refId": "C" - }, - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "expr": "process_memory_rss_bytes{application=\"$application\", instance=\"$instance\"} + process_memory_swap_bytes{application=\"$application\", instance=\"$instance\"}", - "format": "time_series", - "intervalFactor": 2, - "legendFormat": "total", - "refId": "D" - } - ], - "title": "JVM Process Memory", - "type": "timeseries" - }, { "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, - "y": 12 + "y": 15 }, "id": 142, "panels": [], "title": "JVM Misc", "type": "row" }, - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "palette-classic" - }, - "custom": { - "axisBorderShow": false, - "axisCenteredZero": false, - "axisColorMode": "text", - "axisLabel": "", - "axisPlacement": "auto", - "barAlignment": 0, - "barWidthFactor": 0.6, - "drawStyle": "line", - "fillOpacity": 10, - "gradientMode": "none", - "hideFrom": { - "legend": false, - "tooltip": false, - "viz": false - }, - "insertNulls": false, - "lineInterpolation": "linear", - "lineWidth": 1, - "pointSize": 5, - "scaleDistribution": { - "type": "linear" - }, - "showPoints": "never", - "spanNulls": false, - "stacking": { - "group": "A", - "mode": "none" - }, - "thresholdsStyle": { - "mode": "off" - } - }, - "decimals": 1, - "mappings": [], - "max": 1, - "min": 0, - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] - }, - "unit": "percentunit" - }, - "overrides": [] - }, - "gridPos": { - "h": 9, - "w": 6, - "x": 0, - "y": 13 - }, - "id": 106, - "options": { - "legend": { - "calcs": [ - "lastNotNull", - "max" - ], - "displayMode": "list", - "placement": "bottom", - "showLegend": true - }, - "tooltip": { - "mode": "multi", - "sort": "none" - } - }, - "pluginVersion": "11.3.1", - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "expr": "system_cpu_usage{application=\"$application\", instance=\"$instance\"}", - "format": "time_series", - "hide": false, - "intervalFactor": 1, - "legendFormat": "system", - "metric": "", - "refId": "A", - "step": 2400 - }, - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "expr": "process_cpu_usage{application=\"$application\", instance=\"$instance\"}", - "format": "time_series", - "hide": false, - "intervalFactor": 1, - "legendFormat": "process", - "refId": "B" - }, - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "expr": "avg_over_time(process_cpu_usage{application=\"$application\", instance=\"$instance\"}[15m])", - "format": "time_series", - "hide": false, - "intervalFactor": 1, - "legendFormat": "process-15m", - "refId": "C" - } - ], - "title": "CPU Usage", - "type": "timeseries" - }, { "datasource": { "type": "prometheus", @@ -1174,8 +1065,8 @@ "gridPos": { "h": 9, "w": 6, - "x": 6, - "y": 13 + "x": 0, + "y": 16 }, "id": 93, "options": { @@ -1277,9 +1168,9 @@ }, "gridPos": { "h": 9, - "w": 6, - "x": 12, - "y": 13 + "w": 9, + "x": 6, + "y": 16 }, "id": 32, "options": { @@ -1288,8 +1179,8 @@ "lastNotNull", "max" ], - "displayMode": "list", - "placement": "bottom", + "displayMode": "table", + "placement": "right", "showLegend": true }, "tooltip": { @@ -1539,9 +1430,9 @@ }, "gridPos": { "h": 9, - "w": 6, - "x": 18, - "y": 13 + "w": 9, + "x": 15, + "y": 16 }, "id": 124, "options": { @@ -1550,8 +1441,8 @@ "lastNotNull", "max" ], - "displayMode": "list", - "placement": "bottom", + "displayMode": "table", + "placement": "right", "showLegend": true }, "tooltip": { @@ -1584,7 +1475,7 @@ "h": 1, "w": 24, "x": 0, - "y": 22 + "y": 25 }, "id": 143, "panels": [], @@ -1658,7 +1549,7 @@ "h": 9, "w": 12, "x": 0, - "y": 23 + "y": 26 }, "id": 3, "maxPerRow": 3, @@ -1668,8 +1559,8 @@ "lastNotNull", "max" ], - "displayMode": "list", - "placement": "bottom", + "displayMode": "table", + "placement": "right", "showLegend": true }, "tooltip": { @@ -1796,7 +1687,7 @@ "h": 9, "w": 12, "x": 12, - "y": 23 + "y": 26 }, "id": 78, "maxPerRow": 3, @@ -1806,8 +1697,8 @@ "lastNotNull", "max" ], - "displayMode": "list", - "placement": "bottom", + "displayMode": "table", + "placement": "right", "showLegend": true }, "tooltip": { @@ -1874,7 +1765,7 @@ "h": 1, "w": 24, "x": 0, - "y": 32 + "y": 35 }, "id": 145, "panels": [], @@ -1947,7 +1838,7 @@ "h": 7, "w": 8, "x": 0, - "y": 33 + "y": 36 }, "id": 98, "options": { @@ -2046,7 +1937,7 @@ "h": 7, "w": 8, "x": 8, - "y": 33 + "y": 36 }, "id": 101, "options": { @@ -2159,7 +2050,7 @@ "h": 7, "w": 8, "x": 16, - "y": 33 + "y": 36 }, "id": 99, "options": { @@ -2301,6 +2192,6 @@ "timezone": "browser", "title": "JVM", "uid": "ae5ew9zzh8cu8e", - "version": 13, + "version": 20, "weekStart": "" } \ No newline at end of file