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:
- 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
poll: 3

View file

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

View file

@ -51,12 +51,6 @@ sections:
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
poll: 3