fix 1.15 issues

This commit is contained in:
Caspar Chou 2020-03-07 19:09:24 +08:00
parent 8310bcca85
commit f69a06f4ec
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

@ -2,7 +2,7 @@ from prometheus_client import start_http_server, REGISTRY, Metric
import time import time
import requests import requests
import json import json
import nbt import nbt
import re import re
import os import os
from mcrcon import MCRcon from mcrcon import MCRcon
@ -26,7 +26,7 @@ class MinecraftCollector(object):
def uuid_to_player(self,uuid): def uuid_to_player(self,uuid):
uuid = uuid.replace('-','') uuid = uuid.replace('-','')
if uuid in self.map: if uuid in self.map:
return self.map[uuid] return self.map[uuid]
else: else:
result = requests.get('https://api.mojang.com/user/profiles/'+uuid+'/names') result = requests.get('https://api.mojang.com/user/profiles/'+uuid+'/names')
self.map[uuid] = result.json()[0]['name'] self.map[uuid] = result.json()[0]['name']
@ -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,7 +95,9 @@ 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 value["done"] == True: if key in ("DataVersion"):
continue
if value["done"] == True:
count += 1 count += 1
data["stat.advancements"] = count data["stat.advancements"] = count
if self.questsEnabled: if self.questsEnabled:
@ -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]))})
@ -199,4 +203,4 @@ if __name__ == '__main__':
REGISTRY.register(MinecraftCollector()) REGISTRY.register(MinecraftCollector())
print("Exporter started on Port 8000") print("Exporter started on Port 8000")
while True: while True:
time.sleep(1) time.sleep(1)

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