Fixes for the SpigotMC plugin
* Added plugin to python.d.conf * Fixed code quality issue with mcrcon module * Added preliminary support for reeconnecting (doesn't work completely yet).
Austin S. Hemmelgarn committed
Apr 30, 2018 at 08:37 UTC
3770911705d62d70fbc689e96ce3cf6106a30750
3 files changed
+15
-8
conf.d/python.d.conf
+1
@@ -70,6 +70,7 @@ nginx_log: no
70
# redis: yes
71
# retroshare: yes
72
# sensors: yes
73
+# spigotmc: yes
74
# samba: yes
75
# smartd_log: yes
76
# squid: yes
python.d/python_modules/third_party/mcrcon.py
+1
-1
@@ -68,7 +68,7 @@ class MCRcon(object):
68
# Read a packet
69
in_length, = struct.unpack('<i', self.read(4))
70
in_payload = self.read(in_length)
71
- in_id, in_type = struct.unpack('<ii', in_payload[:8])
71
+ in_id = struct.unpack('<ii', in_payload[:8])
72
in_data_partial, in_padding = in_payload[8:-2], in_payload[-2:]
73
74
# Sanity checks
python.d/spigotmc.chart.py
+13
-7
@@ -40,11 +40,21 @@ class Service(SimpleService):
40
self.console = mcrcon.MCRcon()
41
42
def check(self):
43
- '''Check plugin configuration validity.
43
+ try:
44
+ self.connect()
45
+ except (mcrcon.MCRconException, socket.error):
46
+ return False
47
+ return True
48
+
49
+ def connect(self):
50
+ self.console.connect(self.host, self.port, self.password)
51
45
- This really just makes sure we can connect and authenticate
46
- correctly.'''
52
+ def reconnect(self):
53
try:
54
+ try:
55
+ self.console.disconnect()
56
+ except mcrcon.MCRconException:
57
+ pass
58
self.console.connect(self.host, self.port, self.password)
59
except (mcrcon.MCRconException, socket.error):
60
return False
@@ -62,9 +72,6 @@ class Service(SimpleService):
72
data['tps5'] = float(tmp[1].lstrip()[2:]) * PRECISION
73
data['tps15'] = float(tmp[2].lstrip().rstrip()[2:]) * PRECISION
74
except (mcrcon.MCRconException, socket.error):
65
- data['tps1'] = None
66
- data['tps5'] = None
67
- data['tps15'] = None
75
self.error('Unable to fetch TPS values.')
76
try:
77
raw = self.console.command('list')
@@ -73,6 +80,5 @@ class Service(SimpleService):
80
# We care about the first number here.
81
data['users'] = int(raw.split()[2].split('/')[0])
82
except (mcrcon.MCRconException, socket.error):
76
- data['users'] = None
83
self.error('Unable to fetch user counts.')
84
return data