From 2ae69d73f83d0a20b714f3d5114cf66f3cb1bb9b Mon Sep 17 00:00:00 2001 From: Joshi425 Date: Sat, 9 May 2020 20:23:23 +0200 Subject: [PATCH] add online player support for vanilla servers --- README.md | 4 +++- minecraft_exporter.py | 35 +++++++++++++++++------------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1cb21ba..1743309 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ This exporter reads minecrafts nbt files, the advancements files and can optiona to use it mount your world to /world in the container -rcon connection only works on forge servers, it only executes `forge tps` to get tps and tick time informations +rcon connection is used to get online Players +On Forge Servers enable FORGE_SERVER to get tps information to enable rcon on your minecraft server add the following to the server.properties file: @@ -25,6 +26,7 @@ The RCON Module is only enabled if `RCON_HOST` and `RCON_PASSWORD` is set docker run -e RCON_HOST=127.0.0.1 \ -e RCON_PORT=25575 \ -e RCON_PASSWORD="Password" \ + -e FORGE_SERVER="True" \ -e DYNMAP_ENABLED="True" \ -p 8000:8000 \ -v /opt/all_the_mods_3/world:/world \ diff --git a/minecraft_exporter.py b/minecraft_exporter.py index 581fb17..39a886e 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -67,15 +67,22 @@ class MinecraftCollector(object): metrics.extend([dim_tps,dim_ticktime,overall_tps,overall_ticktime,player_online,entities]) - # dimensions - resp = self.rcon_command("forge tps") - dimtpsregex = re.compile("Dim\s*(-*\d*)\s\((.*?)\)\s:\sMean tick time:\s(.*?) ms\. Mean TPS: (\d*\.\d*)") - for dimid, dimname, meanticktime, meantps in dimtpsregex.findall(resp): - dim_tps.add_sample('dim_tps',value=meantps,labels={'dimension_id':dimid,'dimension_name':dimname}) - dim_ticktime.add_sample('dim_ticktime',value=meanticktime,labels={'dimension_id':dimid,'dimension_name':dimname}) - overallregex = re.compile("Overall\s?: 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={}) + if 'FORGE_SERVER' in os.environ and os.environ['FORGE_SERVER'] == "True": + # dimensions + resp = self.rcon_command("forge tps") + dimtpsregex = re.compile("Dim\s*(-*\d*)\s\((.*?)\)\s:\sMean tick time:\s(.*?) ms\. Mean TPS: (\d*\.\d*)") + for dimid, dimname, meanticktime, meantps in dimtpsregex.findall(resp): + dim_tps.add_sample('dim_tps',value=meantps,labels={'dimension_id':dimid,'dimension_name':dimname}) + dim_ticktime.add_sample('dim_ticktime',value=meanticktime,labels={'dimension_id':dimid,'dimension_name':dimname}) + overallregex = re.compile("Overall\s?: 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={}) + + # entites + resp = self.rcon_command("forge entity list") + entityregex = re.compile("(\d+): (.*?:.*?)\s") + for entitycount, entityname in entityregex.findall(resp): + entities.add_sample('entities',value=entitycount,labels={'entity':entityname}) # dynmap if 'DYNMAP_ENABLED' in os.environ and os.environ['DYNMAP_ENABLED'] == "True": @@ -97,17 +104,9 @@ class MinecraftCollector(object): dynmap_chunk_loading_statistics_count.add_sample('dynmap_chunk_loading_statistics',value=count,labels={'type': state}) dynmap_chunk_loading_statistics_duration.add_sample('dynmap_chunk_loading_duration',value=duration_per_chunk,labels={'type': state}) - - - # entites - resp = self.rcon_command("forge entity list") - entityregex = re.compile("(\d+): (.*?:.*?)\s") - for entitycount, entityname in entityregex.findall(resp): - entities.add_sample('entities',value=entitycount,labels={'entity':entityname}) - # player resp = self.rcon_command("list") - playerregex = re.compile("There are \d*\/20 players online:(.*)") + playerregex = re.compile("players online:(.*)") if playerregex.findall(resp): for player in playerregex.findall(resp)[0].split(","): if player: