add online player support for vanilla servers
This commit is contained in:
parent
54422f0259
commit
2ae69d73f8
2 changed files with 20 additions and 19 deletions
|
@ -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 \
|
||||||
|
|
|
@ -67,15 +67,22 @@ 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])
|
||||||
|
|
||||||
|
|
||||||
# dimensions
|
if 'FORGE_SERVER' in os.environ and os.environ['FORGE_SERVER'] == "True":
|
||||||
resp = self.rcon_command("forge tps")
|
# dimensions
|
||||||
dimtpsregex = re.compile("Dim\s*(-*\d*)\s\((.*?)\)\s:\sMean tick time:\s(.*?) ms\. Mean TPS: (\d*\.\d*)")
|
resp = self.rcon_command("forge tps")
|
||||||
for dimid, dimname, meanticktime, meantps in dimtpsregex.findall(resp):
|
dimtpsregex = re.compile("Dim\s*(-*\d*)\s\((.*?)\)\s:\sMean tick time:\s(.*?) ms\. Mean TPS: (\d*\.\d*)")
|
||||||
dim_tps.add_sample('dim_tps',value=meantps,labels={'dimension_id':dimid,'dimension_name':dimname})
|
for dimid, dimname, meanticktime, meantps in dimtpsregex.findall(resp):
|
||||||
dim_ticktime.add_sample('dim_ticktime',value=meanticktime,labels={'dimension_id':dimid,'dimension_name':dimname})
|
dim_tps.add_sample('dim_tps',value=meantps,labels={'dimension_id':dimid,'dimension_name':dimname})
|
||||||
overallregex = re.compile("Overall\s?: Mean tick time: (.*) ms. Mean TPS: (.*)")
|
dim_ticktime.add_sample('dim_ticktime',value=meanticktime,labels={'dimension_id':dimid,'dimension_name':dimname})
|
||||||
overall_tps.add_sample('overall_tps',value=overallregex.findall(resp)[0][1],labels={})
|
overallregex = re.compile("Overall\s?: Mean tick time: (.*) ms. Mean TPS: (.*)")
|
||||||
overall_ticktime.add_sample('overall_ticktime',value=overallregex.findall(resp)[0][0],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={})
|
||||||
|
|
||||||
|
# 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":
|
||||||
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue