handle MCRconException
This commit is contained in:
parent
aac5f59e9f
commit
1a3599363d
2 changed files with 22 additions and 7 deletions
|
@ -5,4 +5,4 @@ RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
ENTRYPOINT ["python","minecraft_exporter.py"]
|
ENTRYPOINT ["python","-u","minecraft_exporter.py"]
|
||||||
|
|
|
@ -62,13 +62,23 @@ class MinecraftCollector(object):
|
||||||
print(e)
|
print(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def rcon_disconnect(self):
|
||||||
|
self.rcon.disconnect()
|
||||||
|
self.rcon_connected = False
|
||||||
|
|
||||||
def rcon_command(self, command):
|
def rcon_command(self, command):
|
||||||
try:
|
try:
|
||||||
response = self.rcon.command(command)
|
response = self.rcon.command(command)
|
||||||
except (ConnectionResetError, ConnectionAbortedError, BrokenPipeError, MCRconException):
|
except MCRconException as e:
|
||||||
|
response = None
|
||||||
|
if e == "Connection timeout error":
|
||||||
|
print("Lost RCON Connection")
|
||||||
|
self.rcon_disconnect()
|
||||||
|
else:
|
||||||
|
print("RCON command failed")
|
||||||
|
except (ConnectionResetError, ConnectionAbortedError, BrokenPipeError):
|
||||||
print("Lost RCON Connection")
|
print("Lost RCON Connection")
|
||||||
self.rcon.disconnect()
|
self.rcon_disconnect()
|
||||||
self.rcon_connected = False
|
|
||||||
response = None
|
response = None
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
@ -359,9 +369,14 @@ class MinecraftCollector(object):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
collector = MinecraftCollector()
|
||||||
start_http_server(8000)
|
start_http_server(8000)
|
||||||
REGISTRY.register(MinecraftCollector())
|
REGISTRY.register(collector)
|
||||||
print("Exporter started on Port 8000")
|
print("Exporter started on Port 8000")
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
try:
|
||||||
schedule.run_pending()
|
time.sleep(1)
|
||||||
|
schedule.run_pending()
|
||||||
|
except MCRconException:
|
||||||
|
# RCON timeout
|
||||||
|
collector.rcon_disconnect()
|
||||||
|
|
Loading…
Reference in a new issue