add online player support for vanilla servers

This commit is contained in:
Joshi425 2020-05-09 20:23:23 +02:00
parent 54422f0259
commit 2ae69d73f8
2 changed files with 20 additions and 19 deletions

View file

@ -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 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: 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 \ docker run -e RCON_HOST=127.0.0.1 \
-e RCON_PORT=25575 \ -e RCON_PORT=25575 \
-e RCON_PASSWORD="Password" \ -e RCON_PASSWORD="Password" \
-e FORGE_SERVER="True" \
-e DYNMAP_ENABLED="True" \ -e DYNMAP_ENABLED="True" \
-p 8000:8000 \ -p 8000:8000 \
-v /opt/all_the_mods_3/world:/world \ -v /opt/all_the_mods_3/world:/world \

View file

@ -67,6 +67,7 @@ class MinecraftCollector(object):
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])
if 'FORGE_SERVER' in os.environ and os.environ['FORGE_SERVER'] == "True":
# dimensions # dimensions
resp = self.rcon_command("forge tps") resp = self.rcon_command("forge tps")
dimtpsregex = re.compile("Dim\s*(-*\d*)\s\((.*?)\)\s:\sMean tick time:\s(.*?) ms\. Mean TPS: (\d*\.\d*)") dimtpsregex = re.compile("Dim\s*(-*\d*)\s\((.*?)\)\s:\sMean tick time:\s(.*?) ms\. Mean TPS: (\d*\.\d*)")
@ -77,6 +78,12 @@ class MinecraftCollector(object):
overall_tps.add_sample('overall_tps',value=overallregex.findall(resp)[0][1],labels={}) 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={}) 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 # dynmap
if 'DYNMAP_ENABLED' in os.environ and os.environ['DYNMAP_ENABLED'] == "True": if 'DYNMAP_ENABLED' in os.environ and os.environ['DYNMAP_ENABLED'] == "True":
dynmap_tile_render_statistics = Metric('dynmap_tile_render_statistics','Tile Render Statistics reported by Dynmap',"counter") dynmap_tile_render_statistics = Metric('dynmap_tile_render_statistics','Tile Render Statistics reported by Dynmap',"counter")
@ -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_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}) 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 # player
resp = self.rcon_command("list") resp = self.rcon_command("list")
playerregex = re.compile("There are \d*\/20 players online:(.*)") playerregex = re.compile("players online:(.*)")
if playerregex.findall(resp): if playerregex.findall(resp):
for player in playerregex.findall(resp)[0].split(","): for player in playerregex.findall(resp)[0].split(","):
if player: if player: