Skip to content

Commit 1626b94

Browse files
committed
📊 Adds widget to display CPU temps (gchq#452)
1 parent 20b7a6b commit 1626b94

File tree

3 files changed

+112
-1
lines changed

3 files changed

+112
-1
lines changed

docs/widgets.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Dashy has support for displaying dynamic content in the form of widgets. There a
5757
- [Network Traffic](#network-traffic)
5858
- [Resource Usage Alerts](#resource-usage-alerts)
5959
- [Public & Private IP](#ip-address)
60+
- [CPU Temperature](#cpu-temp)
6061
- **[Dynamic Widgets](#dynamic-widgets)**
6162
- [Iframe Widget](#iframe-widget)
6263
- [HTML Embed Widget](#html-embedded-widget)
@@ -1488,6 +1489,25 @@ Shows public and private IP address. Note that the ip plugin is not available on
14881489

14891490
---
14901491

1492+
### CPU Temp
1493+
1494+
Displays temperature data from system CPUs.
1495+
1496+
Note: This widget uses the [`sensors`](https://github.com/nicolargo/glances/blob/develop/glances/plugins/glances_sensors.py) plugin, which is disabled by default, and may cause [performance issues](https://github.com/nicolargo/glances/issues/1664#issuecomment-632063558).
1497+
You'll need to enable the sensors plugin to use this widget, using: `--enable-plugin sensors` when you start Glances.
1498+
1499+
<p align="center"><img width="400" src="https://i.ibb.co/xSs4Gqd/gl-cpu-temp.png" /></p>
1500+
1501+
##### Example
1502+
1503+
```yaml
1504+
- type: gl-cpu-temp
1505+
options:
1506+
hostname: http://192.168.130.2:61208
1507+
```
1508+
1509+
---
1510+
14911511
## Dynamic Widgets
14921512

14931513
### Iframe Widget
@@ -1786,4 +1806,4 @@ For testing purposes, you can use an addon, which will disable the CORS checks.
17861806
17871807
### Raising an Issue
17881808
1789-
If you need to submit a bug report for a failing widget, then please include the full console output (see [how](/docs/troubleshooting.md#how-to-open-browser-console)) as well as the relevant parts of your config file. Before sending the request, ensure you've read the docs. If you're new to GitHub, an haven't previously contributed to the project, then please fist star the repo to avoid your ticket being closed by the anti-spam bot.
1809+
If you need to submit a bug report for a failing widget, then please include the full console output (see [how](/docs/troubleshooting.md#how-to-open-browser-console)) as well as the relevant parts of your config file. Before sending the request, ensure you've read the docs. If you're new to GitHub, an haven't previously contributed to the project, then please fist star the repo to avoid your ticket being closed by the anti-spam bot.

src/components/Widgets/GlCpuTemp.vue

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<template>
2+
<div class="glances-temp-wrapper" v-if="tempData">
3+
<div class="temp-row" v-for="sensor in tempData" :key="sensor.label">
4+
<p class="label">{{ sensor.label | formatLbl }}</p>
5+
<p :class="`temp range-${sensor.color}`">{{ sensor.value | formatVal }}</p>
6+
</div>
7+
</div>
8+
</template>
9+
10+
<script>
11+
import WidgetMixin from '@/mixins/WidgetMixin';
12+
import GlancesMixin from '@/mixins/GlancesMixin';
13+
import { capitalize, fahrenheitToCelsius } from '@/utils/MiscHelpers';
14+
15+
export default {
16+
mixins: [WidgetMixin, GlancesMixin],
17+
data() {
18+
return {
19+
tempData: null,
20+
noResults: false,
21+
};
22+
},
23+
computed: {
24+
endpoint() {
25+
return this.makeGlancesUrl('sensors');
26+
},
27+
},
28+
filters: {
29+
formatLbl(lbl) {
30+
return capitalize(lbl);
31+
},
32+
formatVal(val) {
33+
return `${Math.round(val)}°C`;
34+
},
35+
},
36+
methods: {
37+
getTempColor(temp) {
38+
if (temp <= 50) return 'green';
39+
if (temp > 50 && temp < 75) return 'yellow';
40+
if (temp >= 75) return 'red';
41+
return 'grey';
42+
},
43+
processData(sensorData) {
44+
const results = [];
45+
sensorData.forEach((sensor) => {
46+
const tempC = sensor.unit === 'F' ? fahrenheitToCelsius(sensor.value) : sensor.value;
47+
results.push({
48+
label: sensor.label,
49+
value: tempC,
50+
color: this.getTempColor(tempC),
51+
});
52+
});
53+
this.tempData = results;
54+
},
55+
},
56+
};
57+
</script>
58+
59+
<style scoped lang="scss">
60+
.glances-temp-wrapper {
61+
.temp-row {
62+
display: flex;
63+
align-items: center;
64+
justify-content: space-between;
65+
p.label {
66+
margin: 0.5rem 0;
67+
color: var(--widget-text-color);
68+
}
69+
p.temp {
70+
margin: 0.5rem 0;
71+
font-size: 1.5rem;
72+
font-weight: bold;
73+
&.range-green { color: var(--success); }
74+
&.range-yellow { color: var(--warning); }
75+
&.range-red { color: var(--danger); }
76+
&.range-grey { color: var(--medium-grey); }
77+
}
78+
&:not(:last-child) {
79+
border-bottom: 1px dashed var(--widget-text-color);
80+
}
81+
}
82+
}
83+
</style>

src/components/Widgets/WidgetBase.vue

+8
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@
209209
@error="handleError"
210210
:ref="widgetRef"
211211
/>
212+
<GlCpuTemp
213+
v-else-if="widgetType === 'gl-cpu-temp'"
214+
:options="widgetOptions"
215+
@loading="setLoaderState"
216+
@error="handleError"
217+
:ref="widgetRef"
218+
/>
212219
<HealthChecks
213220
v-else-if="widgetType === 'health-checks'"
214221
:options="widgetOptions"
@@ -413,6 +420,7 @@ export default {
413420
GlNetworkInterfaces: () => import('@/components/Widgets/GlNetworkInterfaces.vue'),
414421
GlNetworkTraffic: () => import('@/components/Widgets/GlNetworkTraffic.vue'),
415422
GlSystemLoad: () => import('@/components/Widgets/GlSystemLoad.vue'),
423+
GlCpuTemp: () => import('@/components/Widgets/GlCpuTemp.vue'),
416424
HealthChecks: () => import('@/components/Widgets/HealthChecks.vue'),
417425
IframeWidget: () => import('@/components/Widgets/IframeWidget.vue'),
418426
Jokes: () => import('@/components/Widgets/Jokes.vue'),

0 commit comments

Comments
 (0)