π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
:sparkles: Adds current memory history widget
Alicia Sykese3b3f3c5a850
diff --git a/docs/widgets.md b/docs/widgets.mdindex 3cfda213..856d5efe 100644--- a/docs/widgets.md+++ b/docs/widgets.md@@ -47,6 +47,7 @@ Dashy has support for displaying dynamic content in the form of widgets. There a- [CPU Usage Per Core](#cpu-usage-per-core)- [CPU Usage History](#cpu-usage-history)- [Memory Usage Current](#current-memory-usage)+ - [Memory Usage History](#memory-usage-history)- [Dynamic Widgets](#dynamic-widgets)- [Iframe Widget](#iframe-widget)- [HTML Embed Widget](#html-embedded-widget)@@ -1257,6 +1258,30 @@ Real-time memory usage gauge, with more info visible on click---+### Memory Usage History++Recent memory usage chart++<p align="center"><img width="500" src="https://i.ibb.co/V3wSgW0/gl-mem-history.png" /></p>++##### Options++**Field** | **Type** | **Required** | **Description**+--- | --- | --- | ---+**`limit`** | `number` | _Optional_ | Limit the number of results returned, rendering more data points will take longer to load. Defaults to `100`+++##### Example++```yaml+- type: gl-mem-history+ options:+ hostname: http://localhost:61208+ limit: 80+```++---+## Dynamic Widgets### Iframe Widgetdiff --git a/src/components/Widgets/GlMemHistory.vue b/src/components/Widgets/GlMemHistory.vuenew file mode 100644index 00000000..a874b22f--- /dev/null+++ b/src/components/Widgets/GlMemHistory.vue@@ -0,0 +1,86 @@+<template>+<div class="glances-cpu-history-wrapper">+ <div class="gl-history-chart" :id="chartId"></div>+</div>+</template>++<script>+import WidgetMixin from '@/mixins/WidgetMixin';+import ChartingMixin from '@/mixins/ChartingMixin';+import { timestampToTime, getTimeAgo } from '@/utils/MiscHelpers';++export default {+ mixins: [WidgetMixin, ChartingMixin],+ components: {},+ data() {+ return {};+ },+ computed: {+ hostname() {+ if (!this.options.hostname) this.error('You must specify a \'hostname\' for Glaces');+ return this.options.hostname;+ },+ limit() {+ return this.options.limit || 100;+ },+ endpoint() {+ return `${this.hostname}/api/3/mem/history/${this.limit}`;+ },+ },+ methods: {+ fetchData() {+ this.makeRequest(this.endpoint).then(this.processData);+ },+ processData(memData) {+ const readings = memData.percent;+ const labels = [];+ const systemValues = [];+ readings.forEach((dataPoint) => {+ labels.push(timestampToTime(dataPoint[0]));+ systemValues.push(dataPoint[1]);+ });++ const chartTitle = this.makeTitle(readings);+ const datasets = [+ { name: 'Memory', type: 'bar', values: systemValues },+ ];+ this.generateChart({ labels, datasets }, chartTitle);+ },+ makeTitle(system) {+ return `Memory Usage over past ${getTimeAgo(system[0][0]).replace('ago', '')}`;+ },+ generateChart(timeChartData, chartTitle) {+ return new this.Chart(`#${this.chartId}`, {+ title: chartTitle,+ data: timeChartData,+ type: 'axis-mixed',+ height: this.chartHeight,+ colors: this.chartColors,+ truncateLegends: true,+ lineOptions: {+ regionFill: 1,+ hideDots: 1,+ },+ axisOptions: {+ xIsSeries: true,+ xAxisMode: 'tick',+ },+ tooltipOptions: {+ formatTooltipY: d => `${Math.round(d)}%`,+ // formatTooltipX: d => timestampToTime(d),+ },+ });+ },++ },+ created() {+ this.overrideUpdateInterval = 20;+ },+};+</script>++<style scoped lang="scss">+.glances-cpu-history-wrapper {+ .gl-history-chart {}+}+</style>diff --git a/src/components/Widgets/WidgetBase.vue b/src/components/Widgets/WidgetBase.vueindex 0e1df96f..597cb98d 100644--- a/src/components/Widgets/WidgetBase.vue+++ b/src/components/Widgets/WidgetBase.vue@@ -137,6 +137,13 @@@error="handleError":ref="widgetRef"/>+ <GlMemHistory+ v-else-if="widgetType === 'gl-mem-history'"+ :options="widgetOptions"+ @loading="setLoaderState"+ @error="handleError"+ :ref="widgetRef"+ /><HealthChecksv-else-if="widgetType === 'health-checks'":options="widgetOptions"@@ -331,6 +338,7 @@ export default {GlCpuGauge: () => import('@/components/Widgets/GlCpuGauge.vue'),GlCpuHistory: () => import('@/components/Widgets/GlCpuHistory.vue'),GlMemGauge: () => import('@/components/Widgets/GlMemGauge.vue'),+ GlMemHistory: () => import('@/components/Widgets/GlMemHistory.vue'),HealthChecks: () => import('@/components/Widgets/HealthChecks.vue'),IframeWidget: () => import('@/components/Widgets/IframeWidget.vue'),Jokes: () => import('@/components/Widgets/Jokes.vue'),