storage_mgr/wwwroot/api/storage_stats.dspy

19 lines
1.0 KiB
Plaintext

env = request._run_ns
dbname = get_module_dbname('storage_mgr')
try:
async with DBPools().sqlorContext(dbname) as sor:
servers = await sor.R('storage_server', {})
exports = await sor.R('storage_export', {})
mounts = await sor.R('storage_mount', {})
total_gb = sum(int(getattr(e,'size_limit_gb',0) or 0) for e in (exports or []))
used_gb = 0
for e in (exports or []):
for m in (mounts or []):
if getattr(m,'export_id','') == e.id and getattr(m,'status','') == 'mounted':
used_gb += int(getattr(e,'size_limit_gb',0) or 0)
break
txt = '存储: ' + str(len(servers or [])) + ' 服务器 | 导出: ' + str(len(exports or [])) + '(' + str(total_gb) + 'GB) | 挂载: ' + str(len(mounts or [])) + '(已用 ' + str(used_gb) + 'GB)'
return {'widgettype': 'Text', 'options': {'otext': txt, 'cfontsize': 0.9, 'color': '#1e293b'}}
except:
return {'widgettype': 'Text', 'options': {'otext': '存储: 加载失败', 'color': '#dc2626'}}