From c5c4c217dd37fee9bdcb1b97fdf866a28f931a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= Date: Tue, 28 Jan 2020 14:28:50 -0500 Subject: [PATCH] tools: add script for following dhtproxy's stats --- tools/dhtproxy_stats.py | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tools/dhtproxy_stats.py diff --git a/tools/dhtproxy_stats.py b/tools/dhtproxy_stats.py new file mode 100644 index 000000000..a03ecbec9 --- /dev/null +++ b/tools/dhtproxy_stats.py @@ -0,0 +1,57 @@ +import requests +import time + +ts = time.time() + +stats_total = {"users":0, "pushListenersCount":0, "listenCount":0, "totalListeners":0, "totalPermanentPuts":0, "timestamp": str(ts)} + +for i in range(80,101): + print("Collecting stats for proxy " + str(i)) + response = requests.request('STATS', 'http://dhtproxy.jami.net:' + str(i)) + + if response.status_code == 200: + result = response.json() + + stats = {} + # Get Total users + try: + stats['users'] = int(int(result["putCount"])/2) + stats_total['users'] += int(int(result["putCount"])/2) + except: + pass + # Get android push + try: + stats['pushListenersCount'] = int(result["pushListenersCount"]) + stats_total['pushListenersCount'] += int(result["pushListenersCount"]) + except: + pass + # Get Listeners + try: + stats['listenCount'] = int(result["listenCount"]) + stats_total['listenCount'] += int(result["listenCount"]) + except: + pass + # Get permanents put nb + try: + stats['totalListeners'] = int(result["pushListenersCount"]) + int(result["listenCount"]) + stats_total['totalListeners'] += int(result["pushListenersCount"]) + int(result["listenCount"]) + except: + pass + try: + total = 0 + for h,v in result["puts"].items(): + total += int(v) + stats['totalPermanentPuts'] = total + stats_total['totalPermanentPuts'] += total + except: + pass + + stats['timestamp'] = str(ts) + + with open("stats_proxy_" + str(i), "a") as stat_file: + stat_file.write(str(stats)) + stat_file.write('\n') + +with open("stats_proxy_total", "a") as stat_file: + stat_file.write(str(stats_total)) + stat_file.write('\n') \ No newline at end of file