27 lines
1.8 KiB
Python
27 lines
1.8 KiB
Python
import hashlib
|
|
import json
|
|
import os
|
|
import shutil
|
|
import sys
|
|
import urllib.request
|
|
from pathlib import Path
|
|
sys.path.insert(0, '/www/server/xingyu-im/ops')
|
|
from baota_publish_test_users import BT, WEB, database, digest, env_values, query
|
|
conn, _ = database(env_values())
|
|
try:
|
|
counts = {table: query(conn, 'SELECT COUNT(*) FROM ' + table)[0][0] for table in ['users','user_profiles','media_assets','admin_users','im_messages']}
|
|
migrations = dict(query(conn, 'SELECT version,checksum FROM schema_migrations'))
|
|
release_sources = {str(path.parent): digest(path) for path in Path('/www/server/xingyu-im/releases').glob('*/backend-source.zip')}
|
|
avatars = query(conn, 'SELECT user_id,avatar_url FROM user_profiles ORDER BY user_id')
|
|
configs = query(conn, 'SELECT config_key,config_value FROM system_configs ORDER BY config_key')
|
|
pids=[]
|
|
for proc in Path('/proc').iterdir():
|
|
if proc.name.isdigit():
|
|
try:
|
|
if os.readlink(str(proc/'exe')) == str(BT/'xingyu-api'): pids.append(int(proc.name))
|
|
except (FileNotFoundError,PermissionError): pass
|
|
with urllib.request.urlopen('http://127.0.0.1:18888/healthz', timeout=10) as response:
|
|
health_status=response.status
|
|
print(json.dumps({'backendSha256':digest(BT/'xingyu-api'),'pids':pids,'health':health_status,'frontend':{name:str((WEB/name).resolve()) for name in ['admin','app']},'sourceArchives':release_sources,'migrations':migrations,'counts':counts,'avatarsSha256':hashlib.sha256(repr(avatars).encode()).hexdigest(),'configSha256':hashlib.sha256(repr(configs).encode()).hexdigest(),'storageProvider':query(conn,"SELECT config_value FROM system_configs WHERE config_key='storage.provider'")[0][0],'freeDiskBytes':shutil.disk_usage('/www').free}))
|
|
finally: conn.close()
|