Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

✨ Kuma widget shows uptime history sparkbar

Alicia Sykes547cd33e0523
diff --git a/docs/widgets.md b/docs/widgets.md
index 868c4990..bf02d075 100644
--- a/docs/widgets.md
+++ b/docs/widgets.md
@@ -73,8 +73,8 @@ Dashy has support for displaying dynamic content in the form of widgets. There a
- [Drone CI Build](#drone-ci-builds)
- [Filebrowser](#filebrowser)
- [Linkding](#linkding)
- - [Uptime Kuma](#uptime-kuma)
- [Uptime Kuma Status Page](#uptime-kuma-status-page)
+ - [Uptime Kuma](#uptime-kuma)
- [Tactical RMM](#tactical-rmm)
- **[System Resource Monitoring](#system-resource-monitoring)**
- [CPU Usage Current](#current-cpu-usage)
@@ -2796,63 +2796,72 @@ Linkding is a self-hosted bookmarking service, which has a clean interface and i
---
-### Uptime Kuma
+### Uptime Kuma Status Page
[Uptime Kuma](https://github.com/louislam/uptime-kuma) is an easy-to-use self-hosted monitoring tool.
+This widget displays the status of your Uptime Kuma monitors from a given status page, including their current history, uptime history, response times and recent failures.
#### Options
-| **Field** | **Type** | **Required** | **Description** |
-| ------------ | -------- | ------------ | ------------------------------------------------------------------------ |
-| **`url`** | `string` | Required | The URL of the Uptime Kuma instance |
-| **`apiKey`** | `string` | Required | The API key (see https://github.com/louislam/uptime-kuma/wiki/API-Keys). |
+| **Field** | **Type** | **Required** | **Description** |
+| ------------------ | -------- | ------------ | --------------------------------------------------------------------------------- |
+| **`host`** | `string` | Required | The URL of the Uptime Kuma instance |
+| **`slug`** | `string` | Required | The slug of the status page |
+| **`monitorNames`** | `string[]` | _Optional_ | Optional labels to override the monitor names from Uptime Kuma, in the same order as they appear on the status page |
+| **`hideHistory`** | `boolean` | _Optional_ | Optionally hide the strip of recent heartbeats |
+| **`hideUptime`** | `boolean` | _Optional_ | Optionally hide the 24-hour uptime percentage |
+| **`hideStatus`** | `boolean` | _Optional_ | Optionally hide the up/ down status pill |
#### Example
```yaml
-- type: uptime-kuma
+- type: uptime-kuma-status-page
useProxy: true
options:
- apiKey: uk2_99H0Yd3I2pPNIRfn0TqBFu4g5q85R1Mh75yZzw6H
- url: http://192.168.1.106:3691/metrics
+ host: https://uptime.as93.net
+ slug: domain-locker
```
#### Info
-- **CORS**: πŸ”΄ Proxied
-- **Auth**: 🟒 Required
+- **CORS**: πŸ”΄ Proxied (Uptime Kuma only sends CORS headers when running in development mode, so `useProxy: true` is required)
+- **Auth**: 🟒 Not Needed
- **Price**: 🟒 Free
- **Host**: Self-Hosted (see [Uptime Kuma](https://github.com/louislam/uptime-kuma) )
- **Privacy**: _See [Uptime Kuma](https://github.com/louislam/uptime-kuma)_
---
-### Uptime Kuma Status Page
+### Uptime Kuma
[Uptime Kuma](https://github.com/louislam/uptime-kuma) is an easy-to-use self-hosted monitoring tool.
#### Options
-| **Field** | **Type** | **Required** | **Description** |
-| ------------------ | -------- | ------------ | --------------------------------------------------------------------------------- |
-| **`host`** | `string` | Required | The URL of the Uptime Kuma instance |
-| **`slug`** | `string` | Required | The slug of the status page |
-| **`monitorNames`** | `string[]` | _Optional_ | Optional labels to override the monitor names from Uptime Kuma, in the same order as they appear on the status page |
+| **Field** | **Type** | **Required** | **Description** |
+| ------------ | -------- | ------------ | ------------------------------------------------------------------------ |
+| **`url`** | `string` | Required | The URL of the Uptime Kuma instance |
+| **`apiKey`** | `string` | Required | The API key (see https://github.com/louislam/uptime-kuma/wiki/API-Keys). |
+| **`hideStatus`** | `boolean` | _Optional_ | Optionally hide the up/ down status pill |
+| **`hideResponseTime`** | `boolean` | _Optional_ | Optionally hide the response time |
+| **`hideUptime`** | `boolean` | _Optional_ | Optionally hide the 24-hour uptime percentage |
+
+Each monitor shows its status, response time and 24-hour uptime. Hover a monitor for its 30-day and 1-year uptime, and average response times. Hide any of the columns with the options above.
#### Example
```yaml
-- type: uptime-kuma-status-page
+- type: uptime-kuma
useProxy: true
options:
- host: http://localhost:3001
- slug: another-beautiful-status-page
+ apiKey: uk2_99H0Yd3I2pPNIRfn0TqBFu4g5q85R1Mh75yZzw6H
+ url: http://192.168.1.106:3691/metrics
```
#### Info
-- **CORS**: πŸ”΄ Proxied (Uptime Kuma only sends CORS headers when running in development mode, so `useProxy: true` is required)
-- **Auth**: 🟒 Not Needed
+- **CORS**: πŸ”΄ Proxied
+- **Auth**: 🟒 Required
- **Price**: 🟒 Free
- **Host**: Self-Hosted (see [Uptime Kuma](https://github.com/louislam/uptime-kuma) )
- **Privacy**: _See [Uptime Kuma](https://github.com/louislam/uptime-kuma)_
diff --git a/src/components/Widgets/UptimeKuma.vue b/src/components/Widgets/UptimeKuma.vue
index c6695e27..e125616e 100644
--- a/src/components/Widgets/UptimeKuma.vue
+++ b/src/components/Widgets/UptimeKuma.vue
@@ -2,17 +2,20 @@
<div>
<template v-if="monitors">
<div v-for="monitor in monitors" :key="monitor.name" class="item-wrapper">
- <div class="item monitor-row">
+ <div class="item monitor-row" v-tooltip="monitorTooltip(monitor)">
<div class="title-title"><span class="text">{{ monitor.name }}</span></div>
<div class="monitors-container">
- <div class="status-container">
+ <div v-if="!hideStatus" class="status-container">
<span class="status-pill" :class="getStatusClass(monitor.status)">
{{ getStatusText(monitor.status) }}
</span>
</div>
- <div class="status-container">
+ <div v-if="!hideResponseTime" class="status-container">
<span class="response-time">{{ formatResponseTime(monitor.responseTime) }}</span>
</div>
+ <div v-if="!hideUptime && monitor.uptime" class="status-container">
+ <span class="uptime">{{ monitor.uptime }}</span>
+ </div>
</div>
</div>
</div>
@@ -40,6 +43,8 @@ const STATUSES = {
3: { text: 'Maintenance', class: 'maintenance' },
};
const UNKNOWN = { text: 'Unknown', class: 'unknown' };
+const WINDOWS = [['1d', '24h'], ['30d', '30d'], ['365d', '1y']];
+const formatPercent = (ratio) => `${(ratio * 100).toFixed(2)}%`;
export default {
mixins: [WidgetMixin],
@@ -63,6 +68,15 @@ export default {
url() {
return this.parseAsEnvVar(this.options.url);
},
+ hideStatus() {
+ return this.options.hideStatus || false;
+ },
+ hideResponseTime() {
+ return this.options.hideResponseTime || false;
+ },
+ hideUptime() {
+ return this.options.hideUptime || false;
+ },
/* Create authorisation header for the instance from the apiKey */
authHeaders() {
if (!this.apiKey) {
@@ -98,6 +112,18 @@ export default {
});
},
/* Add ms unit to response time if it valid (-1 means no ping) */
+ summariseWindows(label, values, format) {
+ const parts = WINDOWS
+ .filter(([key]) => Number.isFinite(values?.[key]))
+ .map(([key, name]) => `${format(values[key])} (${name})`);
+ return parts.length ? `${label}: ${parts.join(', ')}` : null;
+ },
+ monitorTooltip(monitor) {
+ return this.tooltip([
+ this.summariseWindows('Uptime', monitor.uptimes, formatPercent),
+ this.summariseWindows('Avg response', monitor.avgResponse, (v) => `${Math.round(v * 1000)}ms`),
+ ].filter(Boolean).join('<br>'), true);
+ },
formatResponseTime(responseTime) {
const ms = Number(responseTime);
return Number.isFinite(ms) && ms >= 0 ? `${ms}ms` : '-';
@@ -133,13 +159,22 @@ export default {
const monitor = monitors.get(monitorName);
const value = this.getRowValue(row);
- const updated = this.setMonitorValue(dataType, monitor, value);
+ const updated = this.setMonitorValue(dataType, monitor, value, this.getRowWindow(row));
monitors.set(monitorName, updated);
},
- setMonitorValue(key, monitor, value) {
+ setMonitorValue(key, monitor, value, timeWindow) {
const copy = { ...monitor };
switch (key) {
+ case 'monitor_uptime_ratio': {
+ copy.uptimes = { ...copy.uptimes, [timeWindow]: Number(value) };
+ if (timeWindow === '1d') copy.uptime = formatPercent(Number(value));
+ break;
+ }
+ case 'monitor_response_time_seconds': {
+ copy.avgResponse = { ...copy.avgResponse, [timeWindow]: Number(value) };
+ break;
+ }
case 'monitor_cert_days_remaining': {
copy.certDaysRemaining = value;
break;
@@ -168,6 +203,9 @@ export default {
getRowMonitorName(row) {
return this.getValueWithRegex(row, /monitor_name="([^"]+)"/);
},
+ getRowWindow(row) {
+ return this.getValueWithRegex(row, /window="([^"]+)"/);
+ },
getRowDataType(row) {
return this.getValueWithRegex(row, /^(.*?)\{/);
},
diff --git a/src/components/Widgets/UptimeKumaStatusPage.vue b/src/components/Widgets/UptimeKumaStatusPage.vue
index 09893828..67e0c029 100644
--- a/src/components/Widgets/UptimeKumaStatusPage.vue
+++ b/src/components/Widgets/UptimeKumaStatusPage.vue
@@ -11,19 +11,23 @@
:key="heartbeat.id"
class="item-wrapper"
>
- <div class="item monitor-row">
+ <div class="item monitor-row" v-tooltip="monitorTooltip(heartbeat)">
<div class="title-title">
<span class="text">{{ heartbeat.name }}</span>
</div>
<div class="monitors-container">
- <div class="status-container">
+ <div v-if="!hideHistory" class="heartbeat-strip">
<span
- class="status-pill"
- :class="getStatusClass(heartbeat.status)"
- >
- {{ getStatusText(heartbeat.status) }}
- </span>
+ v-for="(beat, index) in heartbeat.history"
+ :key="index"
+ class="beat"
+ :class="getStatusClass(beat.status)"
+ ></span>
</div>
+ <span v-if="!hideUptime && heartbeat.uptime" class="uptime">{{ heartbeat.uptime }}</span>
+ <span v-if="!hideStatus" class="status-pill" :class="getStatusClass(heartbeat.status)">
+ {{ getStatusText(heartbeat.status) }}
+ </span>
</div>
</div>
</div>
@@ -33,6 +37,7 @@
<script>
import WidgetMixin from '@/mixins/WidgetMixin';
+import { getTimeAgo } from '@/utils/MiscHelpers';
const STATUSES = {
0: { text: 'Down', class: 'down' },
@@ -41,6 +46,7 @@ const STATUSES = {
3: { text: 'Maintenance', class: 'maintenance' },
};
const UNKNOWN = { text: 'Unknown', class: 'unknown' };
+const HISTORY_BEATS = 30;
export default {
mixins: [WidgetMixin],
@@ -64,6 +70,15 @@ export default {
monitorNames() {
return Array.isArray(this.options.monitorNames) ? this.options.monitorNames : [];
},
+ hideHistory() {
+ return this.options.hideHistory || false;
+ },
+ hideUptime() {
+ return this.options.hideUptime || false;
+ },
+ hideStatus() {
+ return this.options.hideStatus || false;
+ },
endpoint() {
return `${this.host}/api/status-page/heartbeat/${this.slug}`;
},
@@ -100,18 +115,31 @@ export default {
});
},
processData(response, statusPage) {
- const { heartbeatList } = response;
+ const { heartbeatList, uptimeList } = response;
this.errorMessage = null;
this.lastHeartbeats = this.getOrderedMonitors(statusPage, heartbeatList)
.map((monitor, index) => {
const heartbeats = heartbeatList[monitor.id];
+ const uptime = uptimeList?.[`${monitor.id}_24`];
return {
...heartbeats[heartbeats.length - 1],
id: monitor.id,
name: this.monitorNames[index] || monitor.name || `Monitor ${index + 1}`,
+ uptime: typeof uptime === 'number' ? `${(uptime * 100).toFixed(2)}%` : null,
+ history: heartbeats.slice(-HISTORY_BEATS),
};
});
},
+ monitorTooltip(heartbeat) {
+ const failed = heartbeat.history.filter((beat) => beat.status === 0).length;
+ return this.tooltip([
+ Number.isFinite(heartbeat.ping) ? `Response: ${heartbeat.ping}ms` : null,
+ /* Kuma sends UTC, without a zone marker */
+ heartbeat.time ? `Last check: ${getTimeAgo(`${heartbeat.time.replace(' ', 'T')}Z`)}` : null,
+ failed ? `${failed} of ${heartbeat.history.length} recent checks failed` : null,
+ heartbeat.msg,
+ ].filter(Boolean).join('<br>'), true);
+ },
getOrderedMonitors(statusPage, heartbeatList) {
const groups = statusPage?.publicGroupList;
const monitors = groups
@@ -174,6 +202,36 @@ export default {
.clickable-widget {
cursor: pointer;
+ container-type: inline-size;
+}
+.monitors-container {
+ display: flex;
+ align-items: center;
+ gap: 0.5em;
+}
+.uptime {
+ font-size: 0.8em;
+ opacity: 0.8;
+}
+.heartbeat-strip {
+ display: none;
+ gap: 1px;
+
+ .beat {
+ width: 3px;
+ height: 1.1em;
+ border-radius: 1px;
+ background-color: var(--neutral);
+
+ &.up { background-color: var(--success); }
+ &.down { background-color: var(--danger); }
+ &.pending { background-color: var(--warning); }
+ &.maintenance { background-color: var(--info); }
+ }
+}
+/* Only room for the strip once the widget's own column is wide enough */
+@container (min-width: 320px) {
+ .heartbeat-strip { display: flex; }
}
.monitor-row {
display: flex;
diff --git a/tests/components/widgets/uptimekuma.test.js b/tests/components/widgets/uptimekuma.test.js
index 5e3a8285..08a313cf 100644
--- a/tests/components/widgets/uptimekuma.test.js
+++ b/tests/components/widgets/uptimekuma.test.js
@@ -9,8 +9,9 @@ vi.mock('@/utils/request', () => ({ default: vi.fn() }));
vi.mock('@/utils/logging/ErrorHandler', () => ({ default: vi.fn() }));
/* Prometheus rows, as Uptime Kuma writes them on /metrics */
-const row = (metric, name, value) => `${metric}{monitor_id="1",monitor_name="${name}",`
- + `monitor_type="http",monitor_url="https://example.com"} ${value}`;
+const row = (metric, name, value) => `${metric}{monitor_id="1",monitor_name="${name}"} ${value}`;
+const windowed = (metric, name, win, value) => `${metric}{monitor_name="${name}",`
+ + `window="${win}"} ${value}`;
const metrics = [
'# HELP monitor_status Monitor Status (1 = UP, 0= DOWN, 2= PENDING, 3= MAINTENANCE)',
@@ -20,8 +21,14 @@ const metrics = [
row('monitor_response_time', 'App', 83),
row('monitor_response_time', 'Docs', -1),
row('monitor_response_time', 'API', 112),
+ windowed('monitor_uptime_ratio', 'App', '1d', 0.9998),
+ windowed('monitor_uptime_ratio', 'App', '30d', 0.5),
+ windowed('monitor_response_time_seconds', 'App', '1d', 0.083),
].join('\n');
+const tooltips = [];
+const tooltip = { mounted: (el, binding) => tooltips.push(binding.value.content) };
+
async function mount(options = {}) {
const wrapper = shallowMount(UptimeKuma, {
props: {
@@ -32,6 +39,7 @@ async function mount(options = {}) {
...options,
},
},
+ global: { directives: { tooltip } },
});
await flushPromises();
return wrapper;
@@ -41,6 +49,7 @@ const textOf = (wrapper, selector) => wrapper.findAll(selector).map((n) => n.tex
describe('UptimeKuma widget', () => {
beforeEach(() => {
+ tooltips.length = 0;
request.mockReset();
request.mockResolvedValue({ data: metrics });
});
@@ -59,6 +68,22 @@ describe('UptimeKuma widget', () => {
expect(textOf(await mount(), '.response-time')).toEqual(['83ms', '-', '112ms']);
});
+ it('shows 24 hour uptime in the row, and the other windows in a tooltip', async () => {
+ const wrapper = await mount();
+ expect(textOf(wrapper, '.uptime')).toEqual(['99.98%']);
+ expect(tooltips[0]).toBe('Uptime: 99.98% (24h), 50.00% (30d)<br>Avg response: 83ms (24h)');
+ });
+
+ it.each([
+ ['hideStatus', '.status-pill'],
+ ['hideResponseTime', '.response-time'],
+ ['hideUptime', '.uptime'],
+ ])('%s hides it, leaving the rest', async (option, selector) => {
+ const wrapper = await mount({ [option]: true });
+ expect(wrapper.findAll(selector)).toHaveLength(0);
+ expect(textOf(wrapper, '.title-title')).toEqual(['App', 'Docs', 'API']);
+ });
+
it.each([
['apiKey', 'No API key set'],
['url', 'No URL set'],
@@ -72,9 +97,4 @@ describe('UptimeKuma widget', () => {
request.mockRejectedValue(new Error('Request failed with status code 401'));
expect((await mount()).find('.error-message').text()).toContain('401');
});
-
- it('renders nothing when the response is not metrics text', async () => {
- request.mockResolvedValue({ data: { unexpected: 'json' } });
- expect((await mount()).findAll('.monitor-row')).toHaveLength(0);
- });
});
diff --git a/tests/components/widgets/uptimekumastatuspage.test.js b/tests/components/widgets/uptimekumastatuspage.test.js
index 116bd9ba..fa4385c5 100644
--- a/tests/components/widgets/uptimekumastatuspage.test.js
+++ b/tests/components/widgets/uptimekumastatuspage.test.js
@@ -1,5 +1,5 @@
import {
- describe, it, expect, beforeEach, vi,
+ describe, it, expect, beforeEach, afterEach, vi,
} from 'vitest';
import { shallowMount, flushPromises } from '@vue/test-utils';
import request from '@/utils/request';
@@ -8,7 +8,7 @@ import UptimeKumaStatusPage from '@/components/Widgets/UptimeKumaStatusPage.vue'
vi.mock('@/utils/request', () => ({ default: vi.fn() }));
vi.mock('@/utils/logging/ErrorHandler', () => ({ default: vi.fn() }));
-/* Note the display order (App, API, Docs) differs from monitor id order (5, 6, 7) */
+/* Display order (App, API, Docs) differs from monitor id order (5, 6, 7) */
const statusPage = {
publicGroupList: [
{
@@ -19,8 +19,20 @@ const statusPage = {
],
};
-const beats = (status) => [{ status: 1, ping: 91 }, { status, ping: 83 }];
-const heartbeats = { heartbeatList: { 5: beats(1), 7: beats(0), 6: beats(1) } };
+const beats = (status, msg = '') => [
+ { status: 1, ping: 91, time: '2026-08-27 17:15:46' },
+ {
+ status, ping: 83, time: '2026-08-27 17:16:46', msg,
+ },
+];
+
+const heartbeats = {
+ heartbeatList: { 5: beats(1), 7: beats(0, 'timeout'), 6: beats(1) },
+ uptimeList: { '5_24': 1, '7_24': 0.9876, '6_24': 0.5 },
+};
+
+const tooltips = [];
+const tooltip = { mounted: (el, binding) => tooltips.push(binding.value.content) };
/* Heartbeats and monitor names come from two separate endpoints */
function mockApi({ beatData = heartbeats, pageData = statusPage } = {}) {
@@ -38,39 +50,60 @@ async function mount(options = {}) {
useProxy: false, host: 'https://uptime.example.com', slug: 'domain-locker', ...options,
},
},
+ global: { directives: { tooltip } },
});
await flushPromises();
return wrapper;
}
-const names = (wrapper) => wrapper.findAll('.title-title').map((n) => n.text());
+const textOf = (wrapper, selector) => wrapper.findAll(selector).map((n) => n.text());
+const names = (wrapper) => textOf(wrapper, '.title-title');
describe('UptimeKumaStatusPage widget', () => {
beforeEach(() => {
+ vi.useFakeTimers({ toFake: ['Date'] }); // Date only, so promises still flush
+ vi.setSystemTime(new Date('2026-08-27T17:20:46Z'));
+ tooltips.length = 0;
request.mockReset();
mockApi();
});
+ afterEach(() => vi.useRealTimers());
+
it('names each monitor, in the order the status page lists them', async () => {
expect(names(await mount())).toEqual(['App', 'API', 'Docs']);
});
- it('shows each monitor status, from its latest heartbeat', async () => {
- const pills = (await mount()).findAll('.status-pill');
- expect(pills.map((p) => p.text())).toEqual(['Up', 'Down', 'Up']);
- expect(pills[1].classes()).toContain('down');
+ it('shows the status and 24 hour uptime of each monitor', async () => {
+ const wrapper = await mount();
+ expect(textOf(wrapper, '.status-pill')).toEqual(['Up', 'Down', 'Up']);
+ expect(textOf(wrapper, '.uptime')).toEqual(['100.00%', '98.76%', '50.00%']);
});
- it('lets monitorNames override the names from Uptime Kuma', async () => {
- expect(names(await mount({ monitorNames: ['One', 'Two', 'Three'] }))).toEqual(['One', 'Two', 'Three']);
+ it('draws a bar per heartbeat, coloured by its status', async () => {
+ const bars = (await mount()).findAll('.heartbeat-strip')[1].findAll('.beat');
+ expect(bars).toHaveLength(2);
+ expect(bars[1].classes()).toContain('down');
});
- it('keeps the real name where monitorNames runs out', async () => {
- expect(names(await mount({ monitorNames: ['One'] }))).toEqual(['One', 'API', 'Docs']);
+ it('summarises each monitor in a tooltip', async () => {
+ await mount();
+ expect(tooltips[0]).toBe('Response: 83ms<br>Last check: 4 minutes ago');
+ expect(tooltips[1]).toContain('1 of 2 recent checks failed<br>timeout');
});
- it('ignores a monitorNames given as a string rather than a list', async () => {
- expect(names(await mount({ monitorNames: '["One","Two"]' }))).toEqual(['App', 'API', 'Docs']);
+ it.each([
+ ['hideHistory', '.beat'],
+ ['hideUptime', '.uptime'],
+ ['hideStatus', '.status-pill'],
+ ])('%s hides it, leaving the rest', async (option, selector) => {
+ const wrapper = await mount({ [option]: true });
+ expect(wrapper.findAll(selector)).toHaveLength(0);
+ expect(names(wrapper)).toEqual(['App', 'API', 'Docs']);
+ });
+
+ it('lets monitorNames override the names, falling back once it runs out', async () => {
+ expect(names(await mount({ monitorNames: ['One', 'Two'] }))).toEqual(['One', 'Two', 'Docs']);
});
it('numbers the monitors when the status page cannot be reached', async () => {
@@ -78,11 +111,6 @@ describe('UptimeKumaStatusPage widget', () => {
expect(names(await mount())).toEqual(['Monitor 1', 'Monitor 2', 'Monitor 3']);
});
- it('skips monitors with no heartbeats yet', async () => {
- mockApi({ beatData: { heartbeatList: { 5: beats(1), 7: [], 6: beats(1) } } });
- expect(names(await mount())).toEqual(['App', 'Docs']);
- });
-
it('asks for a slug when one is missing', async () => {
const wrapper = await mount({ slug: undefined });
expect(wrapper.find('.error-message').text()).toBe('No slug set');