50 lines
3.4 KiB
Plaintext
50 lines
3.4 KiB
Plaintext
env = request._run_ns
|
|
dbname = get_module_dbname('pcc')
|
|
try:
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
clusters = await sor.R('cluster', {})
|
|
total = len(clusters or [])
|
|
running = sum(1 for c in (clusters or []) if getattr(c,'status','') == 'running')
|
|
deploying = sum(1 for c in (clusters or []) if getattr(c,'status','') == 'deploying')
|
|
stopped = sum(1 for c in (clusters or []) if getattr(c,'status','') == 'stopped')
|
|
total_nodes = 0; total_cpu = 0; total_gpu = 0; total_mem = 0
|
|
for c in (clusters or []):
|
|
nodes = await sor.R('cluster_node', {'cluster_id': c.id})
|
|
total_nodes += len(nodes or [])
|
|
for n in (nodes or []):
|
|
total_cpu += int(getattr(n,'cpu_cores',0) or 0)
|
|
total_gpu += int(getattr(n,'gpu_count',0) or 0)
|
|
total_mem += int(getattr(n,'memory_gb',0) or 0)
|
|
return {
|
|
'widgettype': 'HBox',
|
|
'options': {'gap': '16px'},
|
|
'subwidgets': [
|
|
{'widgettype': 'VBox', 'options': {'bgcolor': '#eff6ff', 'padding': '16px', 'width': '25%', 'border': '1px solid #dbeafe', 'borderRadius': '8px'},
|
|
'subwidgets': [
|
|
{'widgettype': 'Text', 'options': {'otext': '集群', 'cfontsize': 0.7, 'color': '#64748b'}},
|
|
{'widgettype': 'Text', 'options': {'otext': str(total) + ' 个', 'cfontsize': 2, 'fontWeight': 'bold', 'color': '#2563eb'}},
|
|
{'widgettype': 'Text', 'options': {'otext': str(running) + '运行/' + str(deploying) + '部署/' + str(stopped) + '停', 'cfontsize': 0.7, 'color': '#94a3b8'}}
|
|
]},
|
|
{'widgettype': 'VBox', 'options': {'bgcolor': '#f5f3ff', 'padding': '16px', 'width': '25%', 'border': '1px solid #ede9fe', 'borderRadius': '8px'},
|
|
'subwidgets': [
|
|
{'widgettype': 'Text', 'options': {'otext': '节点', 'cfontsize': 0.7, 'color': '#64748b'}},
|
|
{'widgettype': 'Text', 'options': {'otext': str(total_nodes) + ' 个', 'cfontsize': 2, 'fontWeight': 'bold', 'color': '#7c3aed'}},
|
|
{'widgettype': 'Text', 'options': {'otext': '已加入集群', 'cfontsize': 0.7, 'color': '#94a3b8'}}
|
|
]},
|
|
{'widgettype': 'VBox', 'options': {'bgcolor': '#ecfdf5', 'padding': '16px', 'width': '25%', 'border': '1px solid #d1fae5', 'borderRadius': '8px'},
|
|
'subwidgets': [
|
|
{'widgettype': 'Text', 'options': {'otext': 'CPU', 'cfontsize': 0.7, 'color': '#64748b'}},
|
|
{'widgettype': 'Text', 'options': {'otext': str(total_cpu) + ' 核', 'cfontsize': 2, 'fontWeight': 'bold', 'color': '#059669'}},
|
|
{'widgettype': 'Text', 'options': {'otext': '集群总核数', 'cfontsize': 0.7, 'color': '#94a3b8'}}
|
|
]},
|
|
{'widgettype': 'VBox', 'options': {'bgcolor': '#fff7ed', 'padding': '16px', 'width': '25%', 'border': '1px solid #ffedd5', 'borderRadius': '8px'},
|
|
'subwidgets': [
|
|
{'widgettype': 'Text', 'options': {'otext': 'GPU/内存', 'cfontsize': 0.7, 'color': '#64748b'}},
|
|
{'widgettype': 'Text', 'options': {'otext': str(total_gpu) + ' GPU', 'cfontsize': 2, 'fontWeight': 'bold', 'color': '#ea580c'}},
|
|
{'widgettype': 'Text', 'options': {'otext': str(total_mem) + ' GB 内存', 'cfontsize': 0.7, 'color': '#94a3b8'}}
|
|
]}
|
|
]
|
|
}
|
|
except:
|
|
return {'widgettype': 'Text', 'options': {'otext': '加载失败', 'color': '#dc2626'}}
|