Skip to content

Commit e97bf0f

Browse files
Frontend: update cpu widget to show per-core usage, clock, and temperature
1 parent 59d2cd4 commit e97bf0f

File tree

1 file changed

+137
-8
lines changed

1 file changed

+137
-8
lines changed

core/frontend/src/widgets/Cpu.vue

Lines changed: 137 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,42 @@
11
<template>
2-
<v-card class="d-flex align-center justify-center" height="40">
3-
<v-card-title>
4-
CPU: {{ cpu_usage }} %
5-
</v-card-title>
2+
<v-card class="d-flex align-center justify-center cpu-card" height="40">
3+
<div class="cpu-bars-container">
4+
<div
5+
v-for="(usage, index) in cpus_usage"
6+
:key="`cpu-${index}`"
7+
class="cpu-bar-container"
8+
:title="`CPU ${index}: ${usage.toFixed(1)}%`"
9+
>
10+
<div
11+
class="cpu-bar"
12+
:style="{
13+
height: `${Math.max(usage * 0.32, 1)}px`,
14+
backgroundColor: getBarColor(usage),
15+
}"
16+
/>
17+
</div>
18+
</div>
19+
20+
<div class="cpu-info-container">
21+
<div class="cpu-info-row clock-row">
22+
<v-icon small class="cpu-icon">
23+
mdi-speedometer
24+
</v-icon>
25+
<div v-if="clockDisplay.single">
26+
{{ clockDisplay.single }}GHz
27+
</div>
28+
<div v-else>
29+
{{ clockDisplay.max }}-{{ clockDisplay.min }}GHz
30+
</div>
31+
</div>
32+
33+
<div class="cpu-info-row temp-row">
34+
<v-icon small class="cpu-icon">
35+
mdi-thermometer
36+
</v-icon>
37+
<div>{{ cpu_temperature }}°C</div>
38+
</div>
39+
</div>
640
</v-card>
741
</template>
842

@@ -19,19 +53,114 @@ export default Vue.extend({
1953
}
2054
},
2155
computed: {
22-
cpu_usage(): string {
56+
cpus_usage(): number[] {
57+
const cpus = system_information.system?.cpu
58+
if (!cpus) {
59+
return []
60+
}
61+
return cpus.map((cpu) => cpu.usage)
62+
},
63+
cpu_clock(): number[] {
2364
const cpus = system_information.system?.cpu
2465
if (!cpus) {
25-
return '-'
66+
return []
67+
}
68+
return cpus.map((cpu) => cpu.frequency)
69+
},
70+
cpu_temperature(): string {
71+
const temperature_sensors = system_information.system?.temperature
72+
const main_sensor = temperature_sensors?.find(
73+
(sensor) => sensor.name.toLowerCase().includes('cpu') || sensor.name.toLowerCase().includes('soc'),
74+
)
75+
return main_sensor ? main_sensor.temperature.toFixed(1) : 'Loading..'
76+
},
77+
clockDisplay(): { single: string | null; max?: string | null; min?: string | null } {
78+
if (this.cpu_clock.length === 0) {
79+
return { single: null, max: null, min: null }
80+
}
81+
82+
const clocksInGhz = this.cpu_clock.map((clock: number) => clock / 1000)
83+
const allEqual = clocksInGhz.every((clock: number) => clock === clocksInGhz[0])
84+
85+
if (allEqual) {
86+
return { single: clocksInGhz[0].toFixed(1) }
87+
}
88+
const max = Math.max(...clocksInGhz)
89+
const min = Math.min(...clocksInGhz)
90+
return {
91+
max: max.toFixed(1),
92+
min: min.toFixed(1),
93+
single: null,
2694
}
27-
return (cpus.map((cpu) => cpu.usage).reduce((a, b) => a + b) / cpus.length).toFixed()
2895
},
2996
},
3097
mounted() {
31-
this.timer = setInterval(() => system_information.fetchSystemInformation(FetchType.SystemCpuType), 5000)
98+
this.timer = setInterval(() => {
99+
system_information.fetchSystemInformation(FetchType.SystemCpuType)
100+
}, 5000)
32101
},
33102
beforeDestroy() {
34103
clearInterval(this.timer)
35104
},
105+
methods: {
106+
getBarColor(usage: number): string {
107+
if (usage < 40) return '#4caf50' // Green
108+
if (usage < 75) return '#ff9800' // Orange
109+
return '#f44336' // Red
110+
},
111+
},
36112
})
37113
</script>
114+
115+
<style scoped>
116+
.cpu-card {
117+
border-radius: 4px;
118+
padding-left: 4px;
119+
padding-right: 4px;
120+
}
121+
122+
.cpu-bars-container {
123+
display: flex;
124+
align-items: flex-end;
125+
gap: 2px;
126+
margin-right: 12px;
127+
}
128+
129+
.cpu-bar-container {
130+
width: 8px;
131+
height: 32px;
132+
border: 1px solid var(--v-outline-darken3);
133+
border-radius: 3px;
134+
display: flex;
135+
align-items: flex-end;
136+
background-color: var(--v-sheet_bg-darken1);
137+
}
138+
139+
.cpu-bar {
140+
width: 100%;
141+
border-radius: 1px;
142+
transition: height 0.3s ease, background-color 0.3s ease;
143+
}
144+
145+
.cpu-info-container {
146+
display: flex;
147+
flex-direction: column;
148+
font-size: 0.8rem;
149+
line-height: 1.1;
150+
min-width: 70px;
151+
}
152+
153+
.cpu-icon {
154+
margin-right: 2px;
155+
font-size: 0.9rem !important;
156+
}
157+
158+
.cpu-info-row {
159+
display: flex;
160+
align-items: center;
161+
}
162+
163+
.clock-row .cpu-icon {
164+
margin-bottom: 2px;
165+
}
166+
</style>

0 commit comments

Comments
 (0)