MCPcopy Create free account
hub / github.com/cppla/ServerStatus / _ping_thread

Function _ping_thread

clients/client-psutil.py:179–215  ·  view source on GitHub ↗
(host, mark, port)

Source from the content-addressed store, hash-verified

177monitorServer = {}
178
179def _ping_thread(host, mark, port):
180 lostPacket = 0
181 packet_queue = Queue(maxsize=PING_PACKET_HISTORY_LEN)
182
183 while True:
184 # flush dns, every time.
185 IP = host
186 if host.count(':') < 1: # if not plain ipv6 address, means ipv4 address or hostname
187 try:
188 if PROBE_PROTOCOL_PREFER == 'ipv4':
189 IP = socket.getaddrinfo(host, None, socket.AF_INET)[0][4][0]
190 else:
191 IP = socket.getaddrinfo(host, None, socket.AF_INET6)[0][4][0]
192 except Exception:
193 pass
194
195 if packet_queue.full():
196 if packet_queue.get() == 0:
197 lostPacket -= 1
198 try:
199 b = timeit.default_timer()
200 socket.create_connection((IP, port), timeout=1).close()
201 pingTime[mark] = int((timeit.default_timer() - b) * 1000)
202 packet_queue.put(1)
203 except socket.error as error:
204 if error.errno == errno.ECONNREFUSED:
205 pingTime[mark] = int((timeit.default_timer() - b) * 1000)
206 packet_queue.put(1)
207 #elif error.errno == errno.ETIMEDOUT:
208 else:
209 lostPacket += 1
210 packet_queue.put(0)
211
212 if packet_queue.qsize() > 30:
213 lostRate[mark] = float(lostPacket) / packet_queue.qsize()
214
215 time.sleep(INTERVAL)
216
217def _net_speed():
218 while True:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected