@cryptotaxi247 / netdata-1 / commits / 00f0f8007

fix spigotmc plugin bugs (#6635)

* :bug: Fix spigotmc plugin can't reconnect. Prior to this, the connection will continue to try to reconnect when it is normal. After the connection is interrupted, it will not try to reconnect. * :sparkles: Improve the compatibility of spigotmc plugin player count check Previously, the color output would give the wrong result. And does not support counting the number of invisible players. * :memo: Add an example for the regularity of the spigotmc plugin

Cat73 committed Aug 12, 2019 at 17:48 UTC 00f0f80078316ccc6003bb7595d98a938674f9b1
1 file changed +16 -3
collectors/python.d.plugin/spigotmc/spigotmc.chart.py
+16 -3
@@ -52,7 +52,13 @@ _TPS_REGEX = re.compile(
52 re.X
53 )
54 _LIST_REGEX = re.compile(
55 - r'(\d+)', # Current user count.
55 + # Examples:
56 + # There are 4 of a max 50 players online: player1, player2, player3, player4
57 + # §6There are §c4§6 out of maximum §c50§6 players online.
58 + # §6There are §c3§6/§c1§6 out of maximum §c50§6 players online.
59 + # §6当前有 §c4§6 个玩家在线,最大在线人数为 §c50§6 个玩家.
60 + # §c4§6 人のプレイヤーが接続中です。最大接続可能人数\:§c 50
61 + r'[^§](\d+)(?:.*?(?=/).*?[^§](\d+))?', # Current user count.
62 re.X
63 )
64
@@ -85,6 +91,7 @@ class Service(SimpleService):
91 self.console.connect(self.host, self.port, self.password)
92
93 def reconnect(self):
94 + self.error('try reconnect.')
95 try:
96 try:
97 self.console.disconnect()
@@ -99,7 +106,7 @@ class Service(SimpleService):
106 return True
107
108 def is_alive(self):
102 - if not any(
109 + if any(
110 [
111 not self.alive,
112 self.console.socket.getsockopt(socket.IPPROTO_TCP, socket.TCP_INFO, 0) != 1
@@ -139,7 +146,13 @@ class Service(SimpleService):
146 raw = self.console.command(COMMAND_ONLINE)
147 match = _LIST_REGEX.search(raw)
148 if match:
142 - data['users'] = int(match.group(1))
149 + users = int(match.group(1))
150 + hidden_users = match.group(2)
151 + if hidden_users:
152 + hidden_users = int(hidden_users)
153 + else:
154 + hidden_users = 0
155 + data['users'] = users + hidden_users
156 else:
157 if not raw:
158 self.error("'{0}' and '{1}' commands returned no value, make sure you set correct password".format(