import os, json, re, subprocess, time, collections, http.client, ssl base='/www/backup/txiaw-mysql-fix-20260831' r={'time':time.strftime('%Y-%m-%d %H:%M:%S')} def run(args,env=None): return subprocess.check_output(args,stderr=subprocess.STDOUT,env=env,timeout=12).decode('utf-8','replace') ng=run(['/www/server/nginx/sbin/nginx','-T']) r['nginx_test_ok']='test is successful' in ng r['loaded_txiaw_home_rules']=ng.count('txiaw_home') r['bt_status']=run(['/etc/init.d/bt','status']).strip() r['uptime']=run(['uptime']).strip() def net(): return {l.split(':')[0].strip():list(map(int,l.split(':')[1].split())) for l in open('/proc/net/dev') if ':' in l} a=net();t=time.monotonic();vm=run(['vmstat','1','3']);b=net();dt=time.monotonic()-t r['network_Mbps']={k:{'rx':round((v[0]-a[k][0])*8/dt/1e6,2),'tx':round((v[8]-a[k][8])*8/dt/1e6,2)} for k,v in b.items() if k!='lo'} rows=[l.split() for l in vm.splitlines()[-2:]] r['cpu_idle_pct']=sum(int(l[14]) for l in rows)/len(rows) r['socket_summary']=run(['ss','-s'])[:700] ua='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36' for name,port,path,host,useragent in [('home',80,'/','www.txiaw.com',ua),('observed_abuse_signature',80,'/?r=rollback-diagnostic','www.txiaw.com',''),('panel',8686,'/gaorui','47.106.181.28:8686',ua)]: c=None;t=time.monotonic() try: c=http.client.HTTPSConnection('127.0.0.1',port,timeout=6,context=ssl._create_unverified_context()) if port==8686 else http.client.HTTPConnection('127.0.0.1',port,timeout=6) c.request('GET',path,headers={'Host':host,'User-Agent':useragent}) q=c.getresponse();body=q.read();title=re.search(br'