github.com/annchain/OG@v0.0.9/scripts/p2p_sim/monitor.py (about) 1 import datetime 2 import json 3 import multiprocessing 4 import time 5 import traceback 6 7 import pandas as pd 8 import requests 9 10 #pd.set_option('display.height', 1000) 11 pd.set_option('display.max_rows', 500) 12 pd.set_option('display.max_columns', 500) 13 pd.set_option('display.width', 1000) 14 15 16 total = 100 17 18 s = requests.Session() 19 s.trust_env = False 20 21 id_host_map = {} 22 host_id_map = {} 23 24 def doone(host): 25 d = {} 26 try: 27 resp = s.get('http://%s/monitor' % host, timeout=3) 28 j = json.loads(resp.text) 29 d = j 30 except Exception as e: 31 return None 32 33 return d 34 35 36 def doround(hosts): 37 d = {} 38 ever = False 39 40 for host in hosts: 41 v = doone(host) 42 if v is not None: 43 d[host[10:]] = v 44 ever = True 45 46 if not ever: 47 return None 48 49 # return pd.DataFrame.from_dict(d, orient='index') 50 return pd.DataFrame.from_dict(d) 51 52 53 if __name__ == '__main__': 54 hosts = ['127.0.0.1:%d' % (7300 + i*10) for i in range(total)] 55 while True: 56 df = doround(hosts) 57 if df is not None: 58 print("=" * 20) 59 print(datetime.datetime.now()) 60 print(df) 61 time.sleep(3)