From 45dabc2723bff373c1afa31f5dbf71ca9eed9590 Mon Sep 17 00:00:00 2001 From: Nathan Easton Date: Sun, 5 Dec 2021 02:02:09 -0500 Subject: [PATCH 1/2] Added tps monitoring for paper server type. --- Dockerfile | 2 +- dashboard/server-stats.json | 831 +++++++++++++++++++++++------------- minecraft_exporter.py | 15 +- 3 files changed, 539 insertions(+), 309 deletions(-) diff --git a/Dockerfile b/Dockerfile index 548189f..aa4638d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3-alpine +FROM python:3.8.12-alpine3.14 COPY requirements.txt minecraft_exporter.py / RUN pip install --no-cache-dir -r requirements.txt diff --git a/dashboard/server-stats.json b/dashboard/server-stats.json index 8091c16..d9591e2 100644 --- a/dashboard/server-stats.json +++ b/dashboard/server-stats.json @@ -9,17 +9,18 @@ "pluginName": "Prometheus" } ], + "__elements": [], "__requires": [ { "type": "grafana", "id": "grafana", "name": "Grafana", - "version": "6.5.2" + "version": "8.3.0" }, { "type": "panel", "id": "graph", - "name": "Graph", + "name": "Graph (old)", "version": "" }, { @@ -30,8 +31,8 @@ }, { "type": "panel", - "id": "table", - "name": "Table", + "id": "table-old", + "name": "Table (old)", "version": "" } ], @@ -44,32 +45,100 @@ "hide": true, "iconColor": "rgba(0, 211, 255, 1)", "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, "type": "dashboard" } ] }, + "description": "for usage \r\nhttps://github.com/Joshi425/minecraft-exporter", "editable": true, - "gnetId": null, + "fiscalYearStartMonth": 0, + "gnetId": 11993, "graphTooltip": 0, "id": null, "links": [], + "liveNow": false, "panels": [ + { + "columns": [], + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fontSize": "100%", + "gridPos": { + "h": 17, + "w": 3, + "x": 0, + "y": 0 + }, + "id": 9, + "showHeader": true, + "sort": { + "col": 0, + "desc": true + }, + "styles": [ + { + "alias": "Time", + "align": "auto", + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "pattern": "Time", + "type": "hidden" + }, + { + "alias": "", + "align": "auto", + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "decimals": 2, + "pattern": "/Value/", + "thresholds": [], + "type": "hidden", + "unit": "short" + } + ], + "targets": [ + { + "expr": "player_online", + "instant": true, + "legendFormat": "{{player}}", + "refId": "A" + } + ], + "title": "Players Online", + "transform": "timeseries_to_rows", + "type": "table-old" + }, { "aliasColors": {}, "bars": false, "dashLength": 10, "dashes": false, - "datasource": "${DS_PROMETHEUS}", + "fieldConfig": { + "defaults": { + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { - "h": 8, - "w": 12, - "x": 0, + "h": 9, + "w": 9, + "x": 3, "y": 0 }, "hiddenSeries": false, - "id": 13, + "id": 7, "legend": { "avg": false, "current": false, @@ -83,9 +152,10 @@ "linewidth": 1, "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "8.3.0", "pointradius": 2, "points": false, "renderer": "flot", @@ -95,16 +165,29 @@ "steppedLine": false, "targets": [ { - "expr": "player_quests_finished", - "legendFormat": "{{player}}", + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "exemplar": true, + "expr": "dim_ticktime", + "interval": "", + "legendFormat": "{{dimension_name}}", "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "expr": "overall_ticktime", + "legendFormat": "Overall", + "refId": "B" } ], "thresholds": [], - "timeFrom": null, "timeRegions": [], - "timeShift": null, - "title": "Quests finished", + "title": "Ticktime", "tooltip": { "shared": true, "sort": 0, @@ -112,33 +195,26 @@ }, "type": "graph", "xaxis": { - "buckets": null, "mode": "time", - "name": null, "show": true, "values": [] }, "yaxes": [ { - "format": "short", - "label": null, + "$$hashKey": "object:70", + "format": "ms", "logBase": 1, - "max": null, - "min": null, "show": true }, { + "$$hashKey": "object:71", "format": "short", - "label": null, "logBase": 1, - "max": null, - "min": null, "show": true } ], "yaxis": { - "align": false, - "alignLevel": null + "align": false } }, { @@ -146,7 +222,16 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": "${DS_PROMETHEUS}", + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { @@ -170,9 +255,10 @@ "linewidth": 1, "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "8.3.0", "pointradius": 2, "points": false, "renderer": "flot", @@ -193,9 +279,7 @@ } ], "thresholds": [], - "timeFrom": null, "timeRegions": [], - "timeShift": null, "title": "TPS ", "tooltip": { "shared": true, @@ -204,281 +288,170 @@ }, "type": "graph", "xaxis": { - "buckets": null, "mode": "time", - "name": null, "show": true, "values": [] }, "yaxes": [ { + "$$hashKey": "object:276", "format": "short", - "label": null, "logBase": 1, "max": "20", "min": "0", "show": true }, { + "$$hashKey": "object:277", "format": "short", - "label": null, "logBase": 1, - "max": null, - "min": null, "show": true } ], "yaxis": { - "align": false, - "alignLevel": null + "align": false } }, - { - "columns": [], - "datasource": "${DS_PROMETHEUS}", - "fontSize": "100%", - "gridPos": { - "h": 9, - "w": 3, - "x": 0, - "y": 8 - }, - "id": 9, - "options": {}, - "pageSize": null, - "showHeader": true, - "sort": { - "col": 0, - "desc": true - }, - "styles": [ - { - "alias": "Time", - "dateFormat": "YYYY-MM-DD HH:mm:ss", - "pattern": "Time", - "type": "hidden" - }, - { - "alias": "", - "colorMode": null, - "colors": [ - "rgba(245, 54, 54, 0.9)", - "rgba(237, 129, 40, 0.89)", - "rgba(50, 172, 45, 0.97)" - ], - "decimals": 2, - "pattern": "/Value/", - "thresholds": [], - "type": "hidden", - "unit": "short" - } - ], - "targets": [ - { - "expr": "player_online", - "instant": true, - "legendFormat": "{{player}}", - "refId": "A" - } - ], - "timeFrom": null, - "timeShift": null, - "title": "Players Online", - "transform": "timeseries_to_rows", - "type": "table" - }, { "aliasColors": {}, "bars": false, "dashLength": 10, "dashes": false, - "datasource": "${DS_PROMETHEUS}", + "fieldConfig": { + "defaults": { + "links": [] + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 8 + }, + "hiddenSeries": false, + "id": 18, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "8.3.0", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "exemplar": true, + "expr": "sum(paper_tps_1m)", + "interval": "", + "legendFormat": "1 Minute", + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "exemplar": true, + "expr": "sum(paper_tps_5m)", + "hide": false, + "interval": "", + "legendFormat": "5 Minute", + "refId": "C" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "exemplar": true, + "expr": "sum(paper_tps_15m)", + "hide": false, + "interval": "", + "legendFormat": "15 Minute", + "refId": "D" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Paper TPS", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "$$hashKey": "object:276", + "format": "short", + "label": "", + "logBase": 1, + "max": "20", + "min": "0", + "show": true + }, + { + "$$hashKey": "object:277", + "format": "short", + "label": "", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 9, "w": 9, "x": 3, - "y": 8 - }, - "hiddenSeries": false, - "id": 7, - "legend": { - "avg": false, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": false - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "null", - "options": { - "dataLinks": [] - }, - "percentage": false, - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "expr": "dim_ticktime", - "legendFormat": "{{dimension_name}}", - "refId": "A" - }, - { - "expr": "overall_ticktime", - "legendFormat": "Overall", - "refId": "B" - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Ticktime", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "ms", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "${DS_PROMETHEUS}", - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 9, - "w": 12, - "x": 12, - "y": 8 - }, - "hiddenSeries": false, - "id": 3, - "legend": { - "avg": false, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": false - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "null", - "options": { - "dataLinks": [] - }, - "percentage": false, - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "expr": "player_playtime / 20", - "legendFormat": "{{ player }}", - "refId": "A" - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Play Time", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "s", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "${DS_PROMETHEUS}", - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 9, - "w": 12, - "x": 0, - "y": 17 + "y": 9 }, "hiddenSeries": false, "id": 11, @@ -495,9 +468,10 @@ "linewidth": 1, "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "8.3.0", "pointradius": 2, "points": false, "renderer": "flot", @@ -513,9 +487,7 @@ } ], "thresholds": [], - "timeFrom": null, "timeRegions": [], - "timeShift": null, "title": "Entities Loaded", "tooltip": { "shared": true, @@ -524,33 +496,24 @@ }, "type": "graph", "xaxis": { - "buckets": null, "mode": "time", - "name": null, "show": true, "values": [] }, "yaxes": [ { "format": "short", - "label": null, "logBase": 1, - "max": null, - "min": null, "show": true }, { "format": "short", - "label": null, "logBase": 1, - "max": null, - "min": null, "show": true } ], "yaxis": { - "align": false, - "alignLevel": null + "align": false } }, { @@ -558,14 +521,195 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": "${DS_PROMETHEUS}", + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "links": [] + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 9, "w": 12, "x": 12, - "y": 17 + "y": 16 + }, + "hiddenSeries": false, + "id": 3, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "8.3.0", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "player_playtime / 20", + "legendFormat": "{{ player }}", + "refId": "A" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Play Time", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "s", + "logBase": 1, + "show": true + }, + { + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "links": [] + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 18 + }, + "hiddenSeries": false, + "id": 17, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "8.3.0", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "sum(dynmap_tile_render_statistics) by (type)", + "legendFormat": "{{ type }}", + "refId": "A" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Dynmap Tile render Statistics", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "short", + "logBase": 1, + "show": true + }, + { + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "links": [] + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 12, + "x": 12, + "y": 25 }, "hiddenSeries": false, "id": 2, @@ -582,9 +726,10 @@ "linewidth": 1, "nullPointMode": "null", "options": { - "dataLinks": [] + "alertThreshold": true }, "percentage": false, + "pluginVersion": "8.3.0", "pointradius": 2, "points": false, "renderer": "flot", @@ -600,9 +745,7 @@ } ], "thresholds": [], - "timeFrom": null, "timeRegions": [], - "timeShift": null, "title": "Score", "tooltip": { "shared": true, @@ -611,38 +754,115 @@ }, "type": "graph", "xaxis": { - "buckets": null, "mode": "time", - "name": null, "show": true, "values": [] }, "yaxes": [ { "format": "short", - "label": null, "logBase": 1, - "max": null, - "min": null, "show": true }, { "format": "short", - "label": null, "logBase": 1, - "max": null, - "min": null, "show": true } ], "yaxis": { - "align": false, - "alignLevel": null + "align": false + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "links": [] + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 34 + }, + "hiddenSeries": false, + "id": 15, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "8.3.0", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "dynmap_chunk_loading_duration", + "legendFormat": "{{ type }}", + "refId": "A" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Dynmap Chunk loading duration", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "ms", + "logBase": 1, + "show": true + }, + { + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false } } ], "refresh": "5s", - "schemaVersion": 21, + "schemaVersion": 33, "style": "dark", "tags": [], "templating": { @@ -656,5 +876,6 @@ "timezone": "", "title": "Minecraft Server", "uid": "LhW0bV0Wz", - "version": 4 -} + "version": 3, + "weekStart": "" +} \ No newline at end of file diff --git a/minecraft_exporter.py b/minecraft_exporter.py index dda7822..4f78a87 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -65,10 +65,19 @@ class MinecraftCollector(object): overall_ticktime = Metric('overall_ticktime',"overall Ticktime","counter") player_online = Metric('player_online',"is 1 if player is online","counter") entities = Metric('entities',"type and count of active entites", "counter") + tps_1m = Metric('paper_tps_1m','1 Minute TPS',"counter") + tps_5m = Metric('paper_tps_5m','5 Minute TPS',"counter") + tps_15m = Metric('paper_tps_15m','15 Minute TPS',"counter") - metrics.extend([dim_tps,dim_ticktime,overall_tps,overall_ticktime,player_online,entities]) - - + metrics.extend([dim_tps,dim_ticktime,overall_tps,overall_ticktime,player_online,entities,tps_1m,tps_5m,tps_15m]) + if 'PAPER_SERVER' in os.environ and os.environ['PAPER_SERVER'] == "True": + resp = str(self.rcon_command("tps")).strip().replace("§a","") + tpsregex = re.compile("TPS from last 1m, 5m, 15m: (\d*\.\d*), (\d*\.\d*), (\d*\.\d*)") + for m1,m5,m15 in tpsregex.findall(resp): + self.rcon_command("say "+str(m1)) + tps_1m.add_sample('paper_tps_1m',value=m1,labels={'tps':'1m'}) + tps_5m.add_sample('paper_tps_5m',value=m5,labels={'tps':'5m'}) + tps_15m.add_sample('paper_tps_15m',value=m15,labels={'tps':'15m'}) if 'FORGE_SERVER' in os.environ and os.environ['FORGE_SERVER'] == "True": # dimensions resp = self.rcon_command("forge tps") From 6474a5c290005e08049b011a0e10afecb269021d Mon Sep 17 00:00:00 2001 From: Nathan Easton Date: Sun, 5 Dec 2021 15:35:40 -0500 Subject: [PATCH 2/2] Update minecraft_exporter.py --- minecraft_exporter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/minecraft_exporter.py b/minecraft_exporter.py index 4f78a87..c768ea0 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -74,7 +74,6 @@ class MinecraftCollector(object): resp = str(self.rcon_command("tps")).strip().replace("§a","") tpsregex = re.compile("TPS from last 1m, 5m, 15m: (\d*\.\d*), (\d*\.\d*), (\d*\.\d*)") for m1,m5,m15 in tpsregex.findall(resp): - self.rcon_command("say "+str(m1)) tps_1m.add_sample('paper_tps_1m',value=m1,labels={'tps':'1m'}) tps_5m.add_sample('paper_tps_5m',value=m5,labels={'tps':'5m'}) tps_15m.add_sample('paper_tps_15m',value=m15,labels={'tps':'15m'})