solve the promlem

This commit is contained in:
Zhaoxuan Chen 2025-09-10 10:44:16 +08:00
parent ab102714b0
commit a497299d26
4 changed files with 177 additions and 217 deletions

View file

@ -4,10 +4,10 @@ pageInfo:
title: Dashy
description: Welcome to your new dashboard!
navLinks:
- title: GitHub
path: https://github.com/Lissy93/dashy
- title: Documentation
path: https://dashy.to/docs
- title: GitHub
path: https://github.com/Lissy93/dashy
- title: Documentation
path: https://dashy.to/docs
# Optional app settings and configuration
appConfig:
@ -16,41 +16,47 @@ appConfig:
# Main content - An array of sections, each containing an array of items
sections:
- name: Getting Started
icon: fas fa-rocket
items:
- title: Dashy Live
description: Developmental project management links for Dashy
icon: https://i.ibb.co/qWWpD0v/astro-dab-128.png
url: https://live.dashy.to/
target: newtab
- title: GitHub
description: Source Code, Issues and Pull Requests
url: https://github.com/lissy93/dashy
icon: fab fa-github
- title: Docs
description: Configuring & Usage Documentation
provider: Dashy.to
icon: far fa-book
url: https://dashy.to/docs
- title: Showcase
description: See how others are using Dashy
url: https://github.com/Lissy93/dashy/blob/master/docs/showcase.md
icon: far fa-grin-hearts
- title: Config Guide
description: See full list of configuration options
url: https://github.com/Lissy93/dashy/blob/master/docs/configuring.md
icon: fas fa-wrench
- title: Support
description: Get help with Dashy, raise a bug, or get in contact
url: https://github.com/Lissy93/dashy/blob/master/.github/SUPPORT.md
icon: far fa-hands-helping
- name: Getting Started
icon: fas fa-rocket
items:
- title: Dashy Live
description: Developmental project management links for Dashy
icon: https://i.ibb.co/qWWpD0v/astro-dab-128.png
url: https://live.dashy.to/
target: newtab
- title: GitHub
description: Source Code, Issues and Pull Requests
url: https://github.com/lissy93/dashy
icon: fab fa-github
- title: Docs
description: Configuring & Usage Documentation
provider: Dashy.to
icon: far fa-book
url: https://dashy.to/docs
- title: Showcase
description: See how others are using Dashy
url: https://github.com/Lissy93/dashy/blob/master/docs/showcase.md
icon: far fa-grin-hearts
- title: Config Guide
description: See full list of configuration options
url: https://github.com/Lissy93/dashy/blob/master/docs/configuring.md
icon: fas fa-wrench
- title: Support
description: Get help with Dashy, raise a bug, or get in contact
url: https://github.com/Lissy93/dashy/blob/master/.github/SUPPORT.md
icon: far fa-hands-helping
- name: System Overview
icon: fas fa-server
widgets:
- type: compact-glance
options:
poll: 3
- name: System Overview
icon: fas fa-server
widgets:
- type: compact-glance
options:
endpoint: http://127.0.0.1:61208/api/4/all
useProxy: false
poll: 5
map:
cpu: $.cpu.total
mem: $.mem.percent
load: $.load.min1

View file

@ -1,51 +1,30 @@
<template>
<div class="glance-card">
<!-- 系统信息头部 -->
<div class="system-header">
<div class="hostname">{{ hostname || 'brick' }}</div>
<div class="system-info">{{ systemInfo }}</div>
<div class="ip-info">IP {{ ipAddress }}</div>
<div class="compact-glance">
<div class="system-info">
<div class="hostname">{{ hostname }}</div>
<div class="os-info">{{ osInfo }}</div>
</div>
<!-- CPU信息 -->
<div class="cpu-section">
<div class="cpu-title">{{ cpuModel }}</div>
<div class="metric-row">
<span class="metric-label">CPU</span>
<div class="progress-bar">
<div class="progress-fill cpu-fill" :style="{ width: cpu + '%' }"></div>
<div class="metrics">
<div class="metric">
<span class="label">CPU</span>
<div class="bar">
<div class="fill cpu-fill" :style="{ width: cpu + '%' }"></div>
</div>
<span class="metric-value">{{ cpu.toFixed(1) }}%</span>
<span class="value">{{ cpu.toFixed(1) }}%</span>
</div>
<div class="metric-row">
<span class="metric-label">MEM</span>
<div class="progress-bar">
<div class="progress-fill mem-fill" :style="{ width: memory + '%' }"></div>
<div class="metric">
<span class="label">MEM</span>
<div class="bar">
<div class="fill mem-fill" :style="{ width: memory + '%' }"></div>
</div>
<span class="metric-value">{{ memory.toFixed(1) }}%</span>
<span class="value">{{ memory.toFixed(1) }}%</span>
</div>
<div class="metric-row">
<span class="metric-label">LOAD</span>
<div class="progress-bar">
<div class="progress-fill load-fill" :style="{ width: loadPercent + '%' }"></div>
<div class="metric">
<span class="label">LOAD</span>
<div class="bar">
<div class="fill load-fill" :style="{ width: loadPercent + '%' }"></div>
</div>
<span class="metric-value">{{ loadPercent.toFixed(1) }}%</span>
</div>
</div>
<!-- 右侧系统状态 -->
<div class="system-stats">
<div class="stat-item">
<span class="stat-label">user:</span>
<span class="stat-value">{{ cpuUser.toFixed(1) }}%</span>
</div>
<div class="stat-item">
<span class="stat-label">system:</span>
<span class="stat-value">{{ cpuSystem.toFixed(1) }}%</span>
</div>
<div class="stat-item">
<span class="stat-label">iowait:</span>
<span class="stat-value">{{ cpuIowait.toFixed(1) }}%</span>
<span class="value">{{ load.toFixed(1) }}</span>
</div>
</div>
</div>
@ -63,124 +42,88 @@ export default {
cpu: 0,
memory: 0,
load: 0,
cpuUser: 0,
cpuSystem: 0,
cpuIowait: 0,
cpuModel: 'Intel(R) Core(TM) i5 CPU M ...',
systemInfo: 'NixOS 24.11 64bit / Linux 6.6.63',
ipAddress: '10.0.0.203/24',
hostname: 'brick',
timer: null,
hostname: 'localhost',
osInfo: 'Windows',
coreCount: 4,
timer: null,
};
},
computed: {
pollMs() { return (this.options.poll || 5) * 1000; },
endpoint() { return this.options.endpoint; },
useProxy() { return this.options.useProxy === true; },
loadPercent() {
return Math.min(100, (this.load / this.coreCount) * 100);
},
},
methods: {
async loadData() {
async fetchSystemData() {
console.log('开始获取系统数据...');
try {
// API
const apiUrl = 'http://127.0.0.1:8888/api/system';
// eslint-disable-next-line no-console
console.log('Fetching real system data from:', apiUrl);
const response = await fetch(apiUrl, {
method: 'GET',
headers: {
Accept: 'application/json',
},
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
console.log('正在连接 http://localhost:61208/');
const response = await fetch('http://localhost:61208/');
console.log('API响应状态:', response.status);
if (!response.ok) throw new Error(`API响应错误: ${response.status}`);
const data = await response.json();
// eslint-disable-next-line no-console
console.log('Real system data received:', data);
// CPU
console.log('收到的数据:', data);
// Update CPU
if (data.cpu) {
this.cpu = data.cpu.total || 0;
this.cpuUser = data.cpu.user || 0;
this.cpuSystem = data.cpu.system || 0;
this.cpuIowait = data.cpu.iowait || 0;
this.coreCount = data.cpu.count || 4;
this.cpuModel = data.cpu.model || 'Unknown CPU';
console.log('CPU使用率:', this.cpu + '%');
}
//
if (data.memory) {
this.memory = data.memory.percent || 0;
// Update Memory
if (data.mem) {
this.memory = data.mem.percent || 0;
console.log('内存使用率:', this.memory + '%');
}
//
// Update Load
if (data.load) {
this.load = data.load.avg_1 || 0;
this.load = data.load.min1 || 0;
console.log('系统负载:', this.load);
}
//
// Update System Info
if (data.system) {
this.hostname = data.system.hostname || 'localhost';
this.systemInfo = `${data.system.os_name || 'Unknown OS'} ${data.system.architecture || ''}`;
this.osInfo = data.system.os_name || 'Unknown OS';
console.log('主机名:', this.hostname);
console.log('系统信息:', this.osInfo);
}
//
if (data.network) {
this.ipAddress = `${data.network.ip || '127.0.0.1'}/24`;
}
// eslint-disable-next-line no-console
console.log(`Real data - CPU: ${this.cpu}%, MEM: ${this.memory}%, LOAD: ${this.load}`);
console.log('数据更新完成!');
} catch (error) {
// eslint-disable-next-line no-console
console.error('Failed to fetch real system data:', error);
// eslint-disable-next-line no-console
console.log('Please make sure system-api.py is running on http://127.0.0.1:8888');
// 使
this.cpu = 0;
this.memory = 0;
this.load = 0;
this.cpuUser = 0;
this.cpuSystem = 0;
this.cpuIowait = 0;
console.error('连接API失败:', error);
console.log('错误详情:', error.message);
this.hostname = '连接失败';
this.osInfo = '请运行 python system-api.py';
}
},
},
mounted() {
// eslint-disable-next-line no-console
console.log('CompactGlance mounted! Endpoint:', this.endpoint);
this.loadData();
this.timer = setInterval(this.loadData, this.pollMs);
this.fetchSystemData();
this.timer = setInterval(this.fetchSystemData, 5000);
},
beforeDestroy() {
clearInterval(this.timer);
if (this.timer) {
clearInterval(this.timer);
}
},
};
</script>
<style scoped>
.glance-card {
.compact-glance {
background: #2a2a2a;
border-radius: 8px;
padding: 16px;
color: #ffffff;
font-family: 'Courier New', monospace;
font-size: 14px;
min-height: 200px;
color: white;
font-family: monospace;
}
.system-header {
display: flex;
justify-content: space-between;
align-items: center;
.system-info {
margin-bottom: 16px;
padding-bottom: 8px;
border-bottom: 1px solid #444;
@ -189,52 +132,41 @@ export default {
.hostname {
font-size: 18px;
font-weight: bold;
color: #ffffff;
margin-bottom: 4px;
}
.system-info {
.os-info {
font-size: 12px;
color: #cccccc;
opacity: 0.7;
}
.ip-info {
font-size: 12px;
color: #cccccc;
.metrics {
display: flex;
flex-direction: column;
gap: 8px;
}
.cpu-section {
margin-bottom: 16px;
}
.cpu-title {
color: #cccccc;
margin-bottom: 12px;
font-size: 13px;
}
.metric-row {
.metric {
display: flex;
align-items: center;
margin-bottom: 8px;
gap: 12px;
}
.metric-label {
width: 50px;
color: #ffffff;
.label {
min-width: 50px;
font-weight: bold;
font-size: 14px;
}
.progress-bar {
.bar {
flex: 1;
height: 20px;
height: 16px;
background: #1a1a1a;
border-radius: 2px;
border-radius: 4px;
overflow: hidden;
border: 1px solid #444;
}
.progress-fill {
.fill {
height: 100%;
transition: width 0.3s ease;
}
@ -244,41 +176,17 @@ export default {
}
.mem-fill {
background: #4CAF50;
background: #FF9800;
}
.load-fill {
background: #333;
background: #2196F3;
}
.metric-value {
width: 60px;
.value {
min-width: 60px;
text-align: right;
color: #ffffff;
font-weight: bold;
font-size: 14px;
}
.system-stats {
position: absolute;
top: 60px;
right: 16px;
display: flex;
flex-direction: column;
gap: 4px;
}
.stat-item {
display: flex;
gap: 8px;
font-size: 12px;
}
.stat-label {
color: #cccccc;
}
.stat-value {
color: #4CAF50;
font-weight: bold;
}
</style>
</style>

41
system-api.py Normal file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env python3
import json
import time
import socket
import platform
from http.server import HTTPServer, BaseHTTPRequestHandler
import psutil
class SystemAPIHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.send_header('Access-Control-Allow-Origin', '*')
self.end_headers()
# 获取系统数据
data = {
"cpu": {
"total": round(psutil.cpu_percent(interval=1), 1)
},
"mem": {
"percent": round(psutil.virtual_memory().percent, 1)
},
"load": {
"min1": round(psutil.cpu_percent() / 100 * psutil.cpu_count(), 2)
},
"system": {
"hostname": socket.gethostname(),
"os_name": f"{platform.system()} {platform.release()}"
}
}
self.wfile.write(json.dumps(data).encode())
def log_message(self, format, *args):
pass # 禁用日志输出
if __name__ == '__main__':
server = HTTPServer(('localhost', 61208), SystemAPIHandler)
print("系统监控API启动在 http://localhost:61208")
server.serve_forever()

5
tatus Normal file
View file

@ -0,0 +1,5 @@
ab102714 (HEAD -> master) recover
c08bff1d correct
ae2301c8 correct
ead21a2f connect the real api
286f13e0 connect the real api