add player-online metric via RCON

This commit is contained in:
Joshua Grimm 2019-10-30 17:37:33 +00:00
parent 3d214680fe
commit bd29915e55
3 changed files with 74 additions and 5 deletions

View file

@ -58,6 +58,7 @@ dim_tps
dim_ticktime
overall_tps
overall_ticktime
player_online
```
# Dashboards

View file

@ -27,6 +27,12 @@
"id": "prometheus",
"name": "Prometheus",
"version": "1.0.0"
},
{
"type": "panel",
"id": "table",
"name": "Table",
"version": ""
}
],
"annotations": {
@ -212,8 +218,8 @@
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"max": "20",
"min": "0",
"show": true
},
{
@ -401,8 +407,63 @@
"align": false,
"alignLevel": null
}
},
{
"columns": [],
"datasource": "${DS_PROMETHEUS}",
"fontSize": "100%",
"gridPos": {
"h": 6,
"w": 3,
"x": 0,
"y": 17
},
"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"
}
],
"refresh": "5s",
"schemaVersion": 20,
"style": "dark",
"tags": [],
@ -410,12 +471,12 @@
"list": []
},
"time": {
"from": "now-6h",
"from": "now-30m",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Minecraft Server",
"uid": "LhW0bV0Wz",
"version": 3
"version": 7
}

View file

@ -34,6 +34,7 @@ class MinecraftCollector(object):
dim_ticktime = Metric('dim_ticktime',"Time a Tick took in a Dimension","counter")
overall_tps = Metric('overall_tps','overall TPS',"counter")
overall_ticktime = Metric('overall_ticktime',"overall Ticktime","counter")
player_online = Metric('player_online',"is 1 if player is online","counter")
mcr = MCRcon(os.environ['RCON_HOST'],os.environ['RCON_PASSWORD'],port=int(os.environ['RCON_PORT']))
mcr.connect()
resp = mcr.command("forge tps")
@ -44,7 +45,13 @@ class MinecraftCollector(object):
overallregex = re.compile("Overall : Mean tick time: (.*) ms. Mean TPS: (.*)")
overall_tps.add_sample('overall_tps',value=overallregex.findall(resp)[0][1],labels={})
overall_ticktime.add_sample('overall_ticktime',value=overallregex.findall(resp)[0][0],labels={})
return[dim_tps,dim_ticktime,overall_tps,overall_ticktime]
resp = mcr.command("list")
playerregex = re.compile("There are \d*\/20 players online:(.*)")
if playerregex.findall(resp):
for player in playerregex.findall(resp)[0].split(","):
if player:
player_online.add_sample('player_online',value=1,labels={'player':player.lstrip()})
return[dim_tps,dim_ticktime,overall_tps,overall_ticktime,player_online]
def get_player_stats(self,uuid):