π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
β¨ Adds widget for GPU monitoring glances (#1440)
Alicia Sykes5dcc150038b7
diff --git a/docs/widgets.md b/docs/widgets.mdindex 7bc0fc76..17f07cde 100644--- a/docs/widgets.md+++ b/docs/widgets.md@@ -90,6 +90,7 @@ Dashy has support for displaying dynamic content in the form of widgets. There a- [Resource Usage Alerts](#resource-usage-alerts)- [Public & Private IP](#ip-address)- [CPU Temperature](#cpu-temp)+ - [GPU](#gpu)- [Compact Metrics](#compact-metrics)- **[Dynamic Widgets](#dynamic-widgets)**- [Iframe Widget](#iframe-widget)@@ -3188,6 +3189,31 @@ You'll need to enable the sensors plugin to use this widget, using: `--enable-pl---+### GPU++Displays usage, memory and temperature for each NVIDIA GPU, plus fan speed where available.++Note: This widget uses the [`gpu`](https://github.com/nicolargo/glances/tree/develop/glances/plugins/gpu) plugin, which requires the `py3nvml` library and is limited to NVIDIA chipsets.++<p align="center"><img width="400" src="https://pixelflare.cc/alicia/dashy/glances-gpu" /></p>++#### Options++**Field** | **Type** | **Required** | **Description**+--- | --- | --- | ---+**`units`** | `string` | _Optional_ | Use `C` to display temperatures in Celsius or `F` to use Fahrenheit. Defaults to `C`.++#### Example++```yaml+- type: gl-gpu+ options:+ hostname: http://192.168.130.2:61208+ units: C+```++---+### Compact MetricsA multi-system overview widget that displays CPU, memory and disk usage for multiple Glances instances in a compact table. Click on a row to see detailed metrics for that system.diff --git a/src/assets/locales/en.json b/src/assets/locales/en.jsonindex 12e2fa91..ee63115a 100644--- a/src/assets/locales/en.json+++ b/src/assets/locales/en.json@@ -460,7 +460,12 @@"disk-file-system": "File System","disk-io-read": "Read","disk-io-write": "Write",- "system-load-desc": "Number of processes waiting in the run-queue, averaged across all cores"+ "system-load-desc": "Number of processes waiting in the run-queue, averaged across all cores",+ "gpu-usage": "Usage",+ "gpu-memory": "Memory",+ "gpu-temperature": "Temp",+ "gpu-fan-speed": "Fan",+ "gpu-none": "No GPU detected"},"system-info": {"uptime": "Uptime"diff --git a/src/components/Widgets/GlGpu.vue b/src/components/Widgets/GlGpu.vuenew file mode 100644index 00000000..9f0bcb89--- /dev/null+++ b/src/components/Widgets/GlGpu.vue@@ -0,0 +1,173 @@+<template>+<div class="glances-gpu-wrapper" v-if="gpus">+ <p v-if="!gpus.length" class="no-gpu">{{ $t('widgets.glances.gpu-none') }}</p>+ <div class="gpu-card" v-for="gpu in gpus" :key="gpu.id">+ <p class="gpu-name">{{ gpu.name }}</p>+ <div class="metric" v-for="bar in gpu.bars" :key="bar.label">+ <p class="label">{{ bar.label }}</p>+ <div class="bar">+ <div+ class="bar-fill"+ :class="`range-${bar.color}`"+ :style="{ width: `${bar.value || 0}%` }"+ ></div>+ <span class="bar-text">{{ bar.value === null ? 'β' : `${bar.value}%` }}</span>+ </div>+ </div>+ <div class="gpu-footer">+ <p class="temp" :class="`range-${gpu.tempColor}`">+ {{ $t('widgets.glances.gpu-temperature') }}: {{ gpu.temp }}+ </p>+ <p class="fan" v-if="gpu.fan !== null">+ {{ $t('widgets.glances.gpu-fan-speed') }}: {{ gpu.fan }} rpm+ </p>+ </div>+ </div>+</div>+</template>++<script>+import WidgetMixin from '@/mixins/WidgetMixin';+import GlancesMixin from '@/mixins/GlancesMixin';+import { celsiusToFahrenheit } from '@/utils/MiscHelpers';++export default {+ mixins: [WidgetMixin, GlancesMixin],+ data() {+ return {+ gpus: null,+ };+ },+ computed: {+ endpoint() {+ return this.makeGlancesUrl('gpu');+ },+ /* Desired temperature unit, either Celsius (default) or Fahrenheit */+ units() {+ return `${this.options.units || 'C'}`.toUpperCase() === 'F' ? 'F' : 'C';+ },+ },+ methods: {+ /* Map raw Glances GPU list into display-ready cards */+ processData(gpuData) {+ if (!Array.isArray(gpuData)) return;+ this.gpus = gpuData.map((gpu, index) => {+ const id = gpu.gpu_id ?? index;+ return {+ id,+ name: gpu.name || `GPU ${id}`,+ bars: [+ this.makeBar(this.$t('widgets.glances.gpu-usage'), gpu.proc),+ this.makeBar(this.$t('widgets.glances.gpu-memory'), gpu.mem),+ ],+ fan: this.round(gpu.fan_speed),+ ...this.makeTemp(gpu.temperature),+ };+ });+ },+ /* Build a labelled progress bar for a percentage metric */+ makeBar(label, value) {+ const percent = this.round(value);+ return { label, value: percent, color: this.usageColor(percent) };+ },+ /* Format temperature, converting units if needed, and pick its color */+ makeTemp(celsius) {+ if (celsius === null || celsius === undefined || Number.isNaN(celsius)) {+ return { temp: 'β', tempColor: 'grey' };+ }+ const value = this.units === 'F' ? celsiusToFahrenheit(celsius) : Math.round(celsius);+ return { temp: `${value}Β°${this.units}`, tempColor: this.tempColor(celsius) };+ },+ round(value) {+ return (value === null || value === undefined || Number.isNaN(value)) ? null : Math.round(value);+ },+ usageColor(percent) {+ if (percent === null) return 'grey';+ if (percent >= 85) return 'red';+ if (percent >= 50) return 'yellow';+ return 'green';+ },+ tempColor(celsius) {+ if (celsius >= 75) return 'red';+ if (celsius >= 50) return 'yellow';+ return 'green';+ },+ },+ created() {+ this.overrideUpdateInterval = 2;+ },+};+</script>++<style scoped lang="scss">+.glances-gpu-wrapper {+ color: var(--widget-text-color);+ .no-gpu {+ text-align: center;+ margin: 1rem 0;+ opacity: var(--dimming-factor);+ }+ .gpu-card {+ padding: 0.5rem 0;+ &:not(:last-child) {+ border-bottom: 1px dashed var(--widget-text-color);+ }+ p.gpu-name {+ margin: 0 0 0.5rem 0;+ font-weight: bold;+ font-size: 1.1rem;+ }+ }+ .metric {+ display: flex;+ align-items: center;+ margin: 0.35rem 0;+ p.label {+ margin: 0;+ width: 4.5rem;+ font-size: 0.9rem;+ }+ .bar {+ position: relative;+ flex: 1;+ height: 1.2rem;+ background: var(--widget-accent-color);+ border-radius: var(--curve-factor);+ overflow: hidden;+ .bar-fill {+ height: 100%;+ transition: width 0.5s ease;+ &.range-green { background: var(--success); }+ &.range-yellow { background: var(--warning); }+ &.range-red { background: var(--danger); }+ &.range-grey { background: var(--medium-grey); }+ }+ .bar-text {+ position: absolute;+ top: 50%;+ left: 50%;+ transform: translate(-50%, -50%);+ font-size: 0.75rem;+ font-family: var(--font-monospace);+ }+ }+ }+ .gpu-footer {+ display: flex;+ justify-content: space-between;+ margin-top: 0.4rem;+ p {+ margin: 0;+ font-size: 0.9rem;+ font-family: var(--font-monospace);+ }+ p.temp {+ font-weight: bold;+ &.range-green { color: var(--success); }+ &.range-yellow { color: var(--warning); }+ &.range-red { color: var(--danger); }+ &.range-grey { color: var(--medium-grey); }+ }+ }+}+</style>diff --git a/src/components/Widgets/WidgetBase.vue b/src/components/Widgets/WidgetBase.vueindex f715ff0c..242cf0d3 100644--- a/src/components/Widgets/WidgetBase.vue+++ b/src/components/Widgets/WidgetBase.vue@@ -95,6 +95,7 @@ const COMPAT = {'gl-system-load': 'GlSystemLoad','gl-uptime': 'GlancesUptime','gl-cpu-temp': 'GlCpuTemp',+ 'gl-gpu': 'GlGpu','gluetun-status': 'GluetunStatus','health-checks': 'HealthChecks','hackernews-trending': 'HackernewsTrending',