(host, mark, port)
| 202 | monitorServer = {} |
| 203 | |
| 204 | def _ping_thread(host, mark, port): |
| 205 | lostPacket = 0 |
| 206 | packet_queue = Queue(maxsize=PING_PACKET_HISTORY_LEN) |
| 207 | |
| 208 | while True: |
| 209 | # flush dns , every time. |
| 210 | IP = host |
| 211 | if host.count(':') < 1: # if not plain ipv6 address, means ipv4 address or hostname |
| 212 | try: |
| 213 | if PROBE_PROTOCOL_PREFER == 'ipv4': |
| 214 | IP = socket.getaddrinfo(host, None, socket.AF_INET)[0][4][0] |
| 215 | else: |
| 216 | IP = socket.getaddrinfo(host, None, socket.AF_INET6)[0][4][0] |
| 217 | except Exception: |
| 218 | pass |
| 219 | |
| 220 | if packet_queue.full(): |
| 221 | if packet_queue.get() == 0: |
| 222 | lostPacket -= 1 |
| 223 | try: |
| 224 | b = timeit.default_timer() |
| 225 | socket.create_connection((IP, port), timeout=1).close() |
| 226 | pingTime[mark] = int((timeit.default_timer() - b) * 1000) |
| 227 | packet_queue.put(1) |
| 228 | except socket.error as error: |
| 229 | if error.errno == errno.ECONNREFUSED: |
| 230 | pingTime[mark] = int((timeit.default_timer() - b) * 1000) |
| 231 | packet_queue.put(1) |
| 232 | #elif error.errno == errno.ETIMEDOUT: |
| 233 | else: |
| 234 | lostPacket += 1 |
| 235 | packet_queue.put(0) |
| 236 | |
| 237 | if packet_queue.qsize() > 30: |
| 238 | lostRate[mark] = float(lostPacket) / packet_queue.qsize() |
| 239 | |
| 240 | time.sleep(INTERVAL) |
| 241 | |
| 242 | def _net_speed(): |
| 243 | while True: |
nothing calls this directly
no outgoing calls
no test coverage detected