Merge pull request #3 from CasparChou/master

fix issues #2
This commit is contained in:
Joshi 2020-03-07 15:33:58 +01:00 committed by GitHub
commit 0c9cd93e97
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 9 deletions

View file

@ -1,8 +1,7 @@
from python:3 FROM python:3-alpine
RUN pip install nbt mcrcon prometheus_client requests COPY requirements.txt minecraft_exporter.py /
RUN pip install --no-cache-dir -r requirements.txt
COPY minecraft_exporter.py /
EXPOSE 8000 EXPOSE 8000

12
docker-compose.yaml Normal file
View file

@ -0,0 +1,12 @@
version: '3.1'
services:
minecraft-exporter:
image: 'joshi425/minecraft_exporter'
environment:
RCON_HOST:
RCON_PORT:
RCON_PASSWORD:
ports:
- 9700:8000
volumes:
- /path/to/minecraft/world:/world:ro

View file

@ -50,7 +50,7 @@ class MinecraftCollector(object):
for dimid, dimname, meanticktime, meantps in dimtpsregex.findall(resp): 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_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}) dim_ticktime.add_sample('dim_ticktime',value=meanticktime,labels={'dimension_id':dimid,'dimension_name':dimname})
overallregex = re.compile("Overall : Mean tick time: (.*) ms. Mean TPS: (.*)") 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_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={})
@ -95,6 +95,8 @@ class MinecraftCollector(object):
count = 0 count = 0
advancements = json.load(json_file) advancements = json.load(json_file)
for key, value in advancements.items(): for key, value in advancements.items():
if key in ("DataVersion"):
continue
if value["done"] == True: if value["done"] == True:
count += 1 count += 1
data["stat.advancements"] = count data["stat.advancements"] = count
@ -125,6 +127,8 @@ class MinecraftCollector(object):
player_quests_finished = Metric('player_quests_finished', 'Number of quests a Player has finished', 'counter') player_quests_finished = Metric('player_quests_finished', 'Number of quests a Player has finished', 'counter')
player_used_crafting_table = Metric('player_used_crafting_table',"Times a Player used a Crafting Table","counter") player_used_crafting_table = Metric('player_used_crafting_table',"Times a Player used a Crafting Table","counter")
for key, value in data.items(): for key, value in data.items():
if key in ("stats", "DataVersion"):
continue
stat = key.split(".")[1] # entityKilledBy stat = key.split(".")[1] # entityKilledBy
if stat == "mineBlock": if stat == "mineBlock":
blocks_mined.add_sample("blocks_mined",value=value,labels={'player':name,'block':'.'.join((key.split(".")[2],key.split(".")[3]))}) blocks_mined.add_sample("blocks_mined",value=value,labels={'player':name,'block':'.'.join((key.split(".")[2],key.split(".")[3]))})

4
requirements.txt Normal file
View file

@ -0,0 +1,4 @@
mcrcon==0.5.2
NBT==1.5.0
prometheus-client==0.7.1
requests==2.5.1