Atlas - client.py

Home / usr / net / PulseWatch Lines: 1 | Size: 1610 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1import time 2import requests 3import collector 4import sys 5import uuid 6import socket 7 8SERVER = sys.argv[1] if len(sys.argv) > 1 else "http://localhost:9000" 9HOSTNAME = socket.gethostname() 10 11def send_stats(): 12 requests.post( 13 f"{SERVER}/ingest", 14 json=collector.collect(), 15 timeout=2 16 ) 17 18def ping(): 19 ping_id = str(uuid.uuid4()) 20 t0 = time.time_ns() 21 22 r = requests.get( 23 f"{SERVER}/ping", 24 params={"ts": t0, "id": ping_id}, 25 timeout=2 26 ) 27 28 t1 = time.time_ns() 29 r.raise_for_status() 30 31 rtt_ms = (t1 - t0) / 1_000_000 32 33 # agent-side receipt 34 requests.post( 35 f"{SERVER}/ingest", 36 json={ 37 "hostname": HOSTNAME, 38 "event": "ping_received", 39 "ping_id": ping_id, 40 }, 41 timeout=2 42 ) 43 44 # controller-side RTT 45 requests.post( 46 f"{SERVER}/ingest", 47 json={ 48 "hostname": HOSTNAME, 49 "event": "ping_rtt", 50 "ping_id": ping_id, 51 "rtt_ms": round(rtt_ms, 3), 52 }, 53 timeout=2 54 ) 55 56if __name__ == "__main__": 57 while True: 58 try: 59 send_stats() 60 ping_id, rtt = ping() 61 62 # store RTT on controller side 63 requests.post( 64 f"{SERVER}/ingest", 65 json={ 66 "hostname": HOSTNAME, 67 "event": "ping_rtt", 68 "ping_id": ping_id, 69 "rtt_ms": round(rtt, 3), 70 }, 71 timeout=2 72 ) 73 74 except Exception: 75 pass 76 77 time.sleep(5) 78
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.