@cryptotaxi247 / netdata-1 / commits / 96d718d75

Fix auto-reconnect for the spigotmc plugin.

This fixes the auto-reconnect functionality for the SpigotMC plugin. It adds a check to make sure that the socket is in the 'CONNECTED" state prior to trying to send anything, and tries to reconnect if it isn't. Additionally, a short (0.9s) timeout is added for the socket operations. Unfortunately, the way this check is made is different between Linux and BSD style networking stacks. It's really easy to do on Linux (because the TCP_INFO socket option returns a structure there), but is non-trivial to do from Python on BSD (because on BSD the same socket option takes a pointer to a structure to be filled as an argument, and the return is success or failure). This only implements the Linux method, and additionally adds a check to disable the plugin on non-Linux systems.

Austin S. Hemmelgarn committed Apr 30, 2018 at 10:57 UTC 96d718d751b7113a5cda4f5299fbb96f17840c40
2 files changed +7 -1
python.d/python_modules/third_party/mcrcon.py
+1
@@ -38,6 +38,7 @@ class MCRcon(object):
38 if self.socket is not None:
39 raise MCRconException("Already connected")
40 self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
41 + self.socket.settimeout(0.9)
42 self.socket.connect((host, port))
43 self.send(3, password)
44
python.d/spigotmc.chart.py
+6 -1
@@ -3,6 +3,7 @@
3 # Author: Austin S. Hemmelgarn (Ferroin)
4
5 import socket
6 +import platform
7
8 from bases.FrameworkServices.SimpleService import SimpleService
9
@@ -41,6 +42,9 @@ class Service(SimpleService):
42 self.alive = True
43
44 def check(self):
45 + if platform.system() != 'Linux':
46 + self.error('Only supported on Linux.')
47 + return False
48 try:
49 self.connect()
50 except (mcrcon.MCRconException, socket.error):
@@ -63,7 +67,8 @@ class Service(SimpleService):
67 return True
68
69 def is_alive(self):
66 - if not self.alive:
70 + if (not self.alive) or \
71 + self.console.socket.getsockopt(socket.IPPROTO_TCP, socket.TCP_INFO, 0) != 1:
72 return self.reconnect()
73 return True
74