Files
2026-09-03 08:38:17 +08:00

33 lines
2.6 KiB
Python

import os, subprocess, time, json, collections, http.client, ssl
r={'time':time.strftime('%Y-%m-%d %H:%M:%S')}
def run(args):
return subprocess.check_output(args,stderr=subprocess.STDOUT,universal_newlines=True,timeout=6)
for name,args in [('uptime',['uptime']),('queue',['tc','-s','qdisc','show']),('panel_process',['ps','-p','737470,737482','-o','pid,lstart,etime,%cpu,%mem,comm'])]:
try:r[name]=run(args)[:1500]
except Exception as e:r[name]=str(e)
try:
lines=run(['ss','-tan']).splitlines()[1:]
r['tcp_by_port_and_state']=dict(collections.Counter(l.split()[3].rsplit(':',1)[-1]+' '+l.split()[0] for l in lines if len(l.split())>4))
except Exception as e:r['ss_error']=str(e)
try:
r['firewall']=[l for l in run(['iptables','-S']).splitlines() if '8686' in l or l.startswith('-P') or ('-j DROP' in l and '--dport' not in l)][:25]
except Exception as e:r['firewall_error']=str(e)
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();started=time.monotonic();time.sleep(3);b=net();dt=time.monotonic()-started
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),'rx_drops':v[3]-a[k][3],'tx_drops':v[11]-a[k][11]} for k,v in b.items() if k!='lo'}
p='/www/wwwlogs/www.txiaw.com.log'
if os.path.isfile(p):
lines=run(['tail','-n','2000',p]).splitlines()
r['access_last2000']={'status':dict(collections.Counter(l.split('"')[2].split()[0] for l in lines if l.count('"')>=3)), 'first_time':lines[0].split('[',1)[-1].split(']',1)[0], 'last_time':lines[-1].split('[',1)[-1].split(']',1)[0], 'bytes':sum(int(l.split('"')[2].split()[1]) for l in lines if l.count('"')>=3 and l.split('"')[2].split()[1].isdigit())}
for path in ['/www/server/panel/data/admin_path.pl','/www/server/panel/data/limitip.conf','/www/server/panel/data/domain.conf','/www/server/panel/data/ssl.pl']:
if os.path.exists(path):r[path]=open(path).read()[:500]
for target in ['/gaorui','/gaorui/']:
try:
c=http.client.HTTPSConnection('127.0.0.1',8686,timeout=4,context=ssl._create_unverified_context())
c.request('GET',target,headers={'Host':'47.106.181.28:8686','User-Agent':'Mozilla/5.0'})
q=c.getresponse();data=q.read();r['loopback'+target]={'status':q.status,'bytes':len(data),'title':data.decode('utf-8','replace').split('<title>')[-1].split('</title>')[0][:100]};c.close()
except Exception as e:r['loopback'+target]={'error':str(e)}
json.dump(r,open('/www/backup/txiaw-mysql-fix-20260831/panel-detail.json','w'),ensure_ascii=False)
print(json.dumps(r,ensure_ascii=False),flush=True)