This commit is contained in:
Zhaoxuan Chen 2025-09-09 22:31:57 +08:00
parent ae2301c860
commit c08bff1df1
3 changed files with 47 additions and 46 deletions

View file

@ -51,12 +51,6 @@ sections:
widgets: widgets:
- type: compact-glance - type: compact-glance
options: options:
endpoint: http://127.0.0.1:61208/api/4/all poll: 3
useProxy: false
poll: 5
map:
cpu: $.cpu.total
mem: $.mem.percent
load: $.load.min1

View file

@ -85,54 +85,67 @@ export default {
methods: { methods: {
async loadData() { async loadData() {
try { try {
const url = this.useProxy // API
? `/api/proxy?url=${encodeURIComponent(this.endpoint)}` const apiUrl = 'http://127.0.0.1:8888/api/system';
: this.endpoint;
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('Fetching data from:', url); console.log('Fetching real system data from:', apiUrl);
const res = await fetch(url);
const data = await res.json(); const response = await fetch(apiUrl, {
method: 'GET',
headers: {
'Accept': 'application/json',
},
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const data = await response.json();
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('API Response - CPU:', data.cpu?.total, 'MEM:', data.mem?.percent, 'LOAD:', data.load?.min1); console.log('Real system data received:', data);
// CPU // CPU
if (data.cpu) { if (data.cpu) {
this.cpu = data.cpu.total || 0; this.cpu = data.cpu.total || 0;
this.cpuUser = data.cpu.user || 0; this.cpuUser = data.cpu.user || 0;
this.cpuSystem = data.cpu.system || 0; this.cpuSystem = data.cpu.system || 0;
this.cpuIowait = data.cpu.iowait || 0; this.cpuIowait = data.cpu.iowait || 0;
this.coreCount = data.cpu.count || 4;
this.cpuModel = data.cpu.model || 'Unknown CPU';
} }
// //
if (data.mem) { if (data.memory) {
this.memory = data.mem.percent || 0; this.memory = data.memory.percent || 0;
} }
// //
if (data.load) { if (data.load) {
this.load = data.load.min1 || 0; this.load = data.load.avg_1 || 0;
} }
// //
if (data.system) { if (data.system) {
this.hostname = data.system.hostname || 'brick'; this.hostname = data.system.hostname || 'localhost';
if (data.system.os_name && data.system.os_version) { this.systemInfo = `${data.system.os_name || 'Unknown OS'} ${data.system.architecture || ''}`;
this.systemInfo = `${data.system.os_name} ${data.system.os_version}`;
}
} }
// CPU //
if (data.cpu && data.cpu.model) { if (data.network) {
this.cpuModel = `${data.cpu.model.substring(0, 30)}...`; this.ipAddress = `${data.network.ip || '127.0.0.1'}/24`;
} }
this.coreCount = data.cpu?.cpucore || 4;
} catch (e) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error('Glances API Error:', e); console.log(`Real data - CPU: ${this.cpu}%, MEM: ${this.memory}%, LOAD: ${this.load}`);
} catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('Using fallback data - API connection failed'); console.error('Failed to fetch real system data:', error);
// API // 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.cpu = 0;
this.memory = 0; this.memory = 0;
this.load = 0; this.load = 0;

View file

@ -51,12 +51,6 @@ sections:
widgets: widgets:
- type: compact-glance - type: compact-glance
options: options:
endpoint: http://127.0.0.1:61208/api/4/all poll: 3
useProxy: false
poll: 5
map:
cpu: $.cpu.total
mem: $.mem.percent
load: $.load.min1