From e30436aa5133b85669f197cd93ef1e1eaa6bd5c1 Mon Sep 17 00:00:00 2001 From: weihao <31719556+weihao@users.noreply.github.com> Date: Sat, 7 Jan 2023 15:50:07 -0500 Subject: [PATCH 1/2] Add whitelist players count --- README.md | 2 + dashboards/minecraft-general-dashboard.json | 1283 +++++++++++++++++ .../mc/config/PrometheusExporterConfig.java | 1 + .../sldk/mc/metrics/WhitelistedPlayers.java | 22 + 4 files changed, 1308 insertions(+) create mode 100644 dashboards/minecraft-general-dashboard.json create mode 100644 src/main/java/de/sldk/mc/metrics/WhitelistedPlayers.java diff --git a/README.md b/README.md index 4dfebd4e..4677291a 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ enable_metrics: jvm_threads: true jvm_gc: true players_total: true + whitelisted_players: true entities_total: true living_entities_total: true loaded_chunks_total: true @@ -95,6 +96,7 @@ These are the stats that are currently exported by the plugin. Label | Description ------------ | ------------- mc_players_total | Unique players on server (online + offline) +mc_whitelisted_players | Players count on the white list mc_loaded_chunks_total | Chunks loaded per world mc_players_online_total | Online players per world mc_entities_total | Entities loaded per world (living + non-living) diff --git a/dashboards/minecraft-general-dashboard.json b/dashboards/minecraft-general-dashboard.json new file mode 100644 index 00000000..55c5e40c --- /dev/null +++ b/dashboards/minecraft-general-dashboard.json @@ -0,0 +1,1283 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "datasource", + "uid": "grafana" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 1, + "links": [], + "liveNow": false, + "panels": [ + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "decimals": 0, + "fieldConfig": { + "defaults": { + "links": [] + }, + "overrides": [] + }, + "fill": 0, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 0 + }, + "hiddenSeries": false, + "id": 1, + "legend": { + "alignAsTable": false, + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "9.3.2", + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "$$hashKey": "object:70", + "alias": "Unique", + "color": "#C0D8FF", + "dashes": true, + "lines": false + }, + { + "$$hashKey": "object:71", + "alias": "/Online/", + "stack": true + }, + { + "$$hashKey": "object:289", + "alias": "Whitelisted", + "dashes": true, + "lines": false + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": true, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "editorMode": "code", + "exemplar": false, + "expr": "mc_players_total{server_name=~\"$server_name\"}", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 2, + "legendFormat": "Unique", + "metric": "mc_players_total", + "range": true, + "refId": "A", + "step": 4 + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "expr": "sum(mc_players_online_total{server_name=~\"$server_name\"}) by (world)", + "legendFormat": "Online ({{world}})", + "refId": "B" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "editorMode": "code", + "exemplar": false, + "expr": "mc_whitelisted_players{server_name=~\"$server_name\"}", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 2, + "legendFormat": "Whitelisted", + "metric": "mc_players_total", + "range": true, + "refId": "C", + "step": 4 + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Players", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "$$hashKey": "object:235", + "decimals": 0, + "format": "short", + "logBase": 1, + "min": "0", + "show": true + }, + { + "$$hashKey": "object:236", + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [ + { + "options": { + "match": "null", + "result": { + "text": "N/A" + } + }, + "type": "special" + } + ], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "rgba(245, 54, 54, 0.9)", + "value": null + }, + { + "color": "rgba(237, 129, 40, 0.89)", + "value": 0 + }, + { + "color": "rgba(50, 172, 45, 0.97)", + "value": 1 + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 4, + "x": 12, + "y": 0 + }, + "id": 2, + "links": [], + "maxDataPoints": 100, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "text": {}, + "textMode": "auto" + }, + "pluginVersion": "9.3.2", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "expr": "sum(mc_players_online_total{server_name=~\"$server_name\"})", + "format": "time_series", + "interval": "", + "intervalFactor": 2, + "legendFormat": "", + "metric": "mc_players_total", + "refId": "A", + "step": 40 + } + ], + "title": "Players Online", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "displayName": "", + "links": [], + "mappings": [], + "max": 10000000000, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 8000000000 + } + ] + }, + "unit": "bytes" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 4, + "x": 16, + "y": 0 + }, + "id": 9, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "last" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "text": {} + }, + "pluginVersion": "9.3.2", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "expr": "mc_jvm_memory{type='allocated', server_name=~\"$server_name\"} - scalar(mc_jvm_memory{type='free', server_name=~\"$server_name\"})", + "instant": false, + "refId": "A" + } + ], + "title": "JVM Memory", + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "displayName": "", + "links": [], + "mappings": [], + "max": 20, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "red", + "value": null + }, + { + "color": "light-orange", + "value": 15 + }, + { + "color": "green", + "value": 18 + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 4, + "x": 20, + "y": 0 + }, + "id": 10, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "text": {} + }, + "pluginVersion": "9.3.2", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "expr": "mc_tps{server_name=~\"$server_name\"}", + "instant": true, + "legendFormat": "", + "refId": "A" + } + ], + "title": "TPS", + "type": "gauge" + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "links": [] + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 7 + }, + "hiddenSeries": false, + "id": 3, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "9.3.2", + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "expr": "mc_loaded_chunks_total{server_name=~\"$server_name\"}", + "format": "time_series", + "intervalFactor": 2, + "legendFormat": "{{world}}", + "metric": "mc_loaded_chunks_total", + "refId": "A", + "step": 4 + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Loaded Chunks", + "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": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "links": [] + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 7 + }, + "hiddenSeries": false, + "id": 5, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "9.3.2", + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": true, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "expr": "mc_jvm_memory{type='max', server_name=~\"$server_name\"}", + "format": "time_series", + "hide": false, + "intervalFactor": 1, + "legendFormat": "Allocated", + "metric": "mc_jvm_memory", + "refId": "A", + "step": 4 + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "expr": "mc_jvm_memory{type='allocated', server_name=~\"$server_name\"} - scalar(mc_jvm_memory{type='free', server_name=~\"$server_name\"})", + "format": "time_series", + "instant": false, + "intervalFactor": 1, + "legendFormat": "Used", + "refId": "B", + "step": 4 + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "expr": "mc_jvm_memory{type='allocated', server_name=~\"$server_name\"}", + "hide": true, + "refId": "C" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "JVM Memory", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "bytes", + "label": "", + "logBase": 1, + "min": "0", + "show": true + }, + { + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "links": [] + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 14 + }, + "hiddenSeries": false, + "id": 4, + "legend": { + "alignAsTable": false, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "9.3.2", + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "exemplar": true, + "expr": "sum (mc_entities_total{server_name=~\"$server_name\"}) by (world)", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 2, + "legendFormat": "{{world}}_total", + "metric": "mc_entities_total", + "refId": "A", + "step": 4 + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Entities", + "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": "PBFA97CFB590B2093" + }, + "decimals": 2, + "description": "", + "fieldConfig": { + "defaults": { + "links": [] + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 14 + }, + "hiddenSeries": false, + "id": 7, + "legend": { + "avg": false, + "current": true, + "hideEmpty": false, + "max": false, + "min": true, + "rightSide": false, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "9.3.2", + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": true, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "expr": "mc_tps{server_name=~\"$server_name\"}", + "format": "time_series", + "intervalFactor": 2, + "legendFormat": "TPS", + "metric": "mc_tps", + "refId": "A", + "step": 4 + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Tickrate", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "none", + "label": "", + "logBase": 1, + "max": "20", + "min": "0", + "show": true + }, + { + "format": "short", + "logBase": 1, + "show": false + } + ], + "yaxis": { + "align": false + } + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 55, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 10, + "w": 12, + "x": 0, + "y": 21 + }, + "id": 17, + "options": { + "legend": { + "calcs": [ + "min", + "max", + "mean", + "last" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "exemplar": true, + "expr": "sum(mc_jvm_threads_current{server_name=~\"$server_name\"})", + "interval": "", + "legendFormat": "TOTAL", + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "exemplar": true, + "expr": "sum by (state) (mc_jvm_threads_state{server_name=~\"$server_name\"})", + "hide": false, + "interval": "", + "legendFormat": "{{state}}", + "refId": "B" + } + ], + "title": "Threads", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "hue", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": true, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 10, + "w": 12, + "x": 12, + "y": 21 + }, + "id": 13, + "options": { + "legend": { + "calcs": [ + "lastNotNull" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "exemplar": true, + "expr": "mc_players_total{server_name=~\"$server_name\"}", + "interval": "", + "legendFormat": "unique players", + "refId": "A" + } + ], + "title": "Unique Players", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "stepAfter", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "decimals": 0, + "links": [], + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "short" + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 24, + "x": 0, + "y": 31 + }, + "id": 11, + "links": [], + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "8.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "expr": "sum (mc_villagers_total{server_name=~\"$server_name\"}) by (world, level, profession)", + "format": "time_series", + "hide": false, + "intervalFactor": 2, + "legendFormat": "{{world}}: {{profession}} (lv{{level}})", + "metric": "mc_entities_total", + "refId": "A", + "step": 4 + } + ], + "title": "Villagers", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "#EAB839", + "value": 60 + }, + { + "color": "red", + "value": 120 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 27, + "w": 24, + "x": 0, + "y": 42 + }, + "id": 15, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "last" + ], + "fields": "", + "values": false + }, + "text": {}, + "textMode": "auto" + }, + "pluginVersion": "9.3.2", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "exemplar": true, + "expr": "sort_desc(sum (mc_entities_total{server_name=~\"$server_name\"}) by (type))", + "instant": true, + "interval": "", + "legendFormat": "{{type}}", + "refId": "A" + } + ], + "title": "Entity", + "type": "stat" + } + ], + "refresh": false, + "schemaVersion": 37, + "style": "dark", + "tags": [ + "minecraft" + ], + "templating": { + "list": [ + { + "allValue": ".+", + "current": { + "selected": false, + "text": "smp", + "value": "smp" + }, + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "definition": "", + "hide": 0, + "includeAll": false, + "label": "Server Name", + "multi": false, + "name": "server_name", + "options": [], + "query": { + "query": "label_values(mc_players_total, server_name)", + "refId": "Prometheus-server_name-Variable-Query" + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 1, + "tagValuesQuery": "", + "tagsQuery": "", + "type": "query", + "useTags": false + } + ] + }, + "time": { + "from": "now-30m", + "to": "now" + }, + "timepicker": { + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ], + "time_options": [ + "5m", + "15m", + "1h", + "6h", + "12h", + "24h", + "2d", + "7d", + "30d" + ] + }, + "timezone": "browser", + "title": "Minecraft", + "uid": "aEn29YOnz", + "version": 4, + "weekStart": "" +} \ No newline at end of file diff --git a/src/main/java/de/sldk/mc/config/PrometheusExporterConfig.java b/src/main/java/de/sldk/mc/config/PrometheusExporterConfig.java index 672981be..77dcc83b 100644 --- a/src/main/java/de/sldk/mc/config/PrometheusExporterConfig.java +++ b/src/main/java/de/sldk/mc/config/PrometheusExporterConfig.java @@ -21,6 +21,7 @@ public class PrometheusExporterConfig { metricConfig("jvm_memory", true, Memory::new), metricConfig("players_online_total", true, PlayersOnlineTotal::new), metricConfig("players_total", true, PlayersTotal::new), + metricConfig("whitelisted_players", true, WhitelistedPlayers::new), metricConfig("tps", true, Tps::new), metricConfig("world_size", true, WorldSize::new), diff --git a/src/main/java/de/sldk/mc/metrics/WhitelistedPlayers.java b/src/main/java/de/sldk/mc/metrics/WhitelistedPlayers.java new file mode 100644 index 00000000..f0488b09 --- /dev/null +++ b/src/main/java/de/sldk/mc/metrics/WhitelistedPlayers.java @@ -0,0 +1,22 @@ +package de.sldk.mc.metrics; + +import io.prometheus.client.Gauge; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; + +public class WhitelistedPlayers extends Metric { + + private static final Gauge PLAYERS = Gauge.build() + .name(prefix("whitelisted_players")) + .help("players count on the white list") + .create(); + + public WhitelistedPlayers(Plugin plugin) { + super(plugin, PLAYERS); + } + + @Override + public void doCollect() { + PLAYERS.set(Bukkit.getWhitelistedPlayers().size()); + } +} From d725aa42f537f711de9d4a2d390dfdaaa3d6e92a Mon Sep 17 00:00:00 2001 From: weihao <31719556+weihao@users.noreply.github.com> Date: Wed, 11 Jan 2023 16:17:56 -0800 Subject: [PATCH 2/2] Update src/main/java/de/sldk/mc/config/PrometheusExporterConfig.java Co-authored-by: Leonid Koftun --- src/main/java/de/sldk/mc/config/PrometheusExporterConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/sldk/mc/config/PrometheusExporterConfig.java b/src/main/java/de/sldk/mc/config/PrometheusExporterConfig.java index 77dcc83b..7e9d5e8b 100644 --- a/src/main/java/de/sldk/mc/config/PrometheusExporterConfig.java +++ b/src/main/java/de/sldk/mc/config/PrometheusExporterConfig.java @@ -21,7 +21,7 @@ public class PrometheusExporterConfig { metricConfig("jvm_memory", true, Memory::new), metricConfig("players_online_total", true, PlayersOnlineTotal::new), metricConfig("players_total", true, PlayersTotal::new), - metricConfig("whitelisted_players", true, WhitelistedPlayers::new), + metricConfig("whitelisted_players", false, WhitelistedPlayers::new), metricConfig("tps", true, Tps::new), metricConfig("world_size", true, WorldSize::new),