From 4e64ccff3b9afa44c7fc68318d5fa5e303260f2f Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 8 Jan 2022 13:55:26 +0000 Subject: [PATCH] :sparkles: Adds current memory usage widget --- docs/widgets.md | 17 ++++ src/components/Widgets/GlMemGauge.vue | 136 ++++++++++++++++++++++++++ src/components/Widgets/WidgetBase.vue | 10 +- src/utils/MiscHelpers.js | 9 ++ 4 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 src/components/Widgets/GlMemGauge.vue diff --git a/docs/widgets.md b/docs/widgets.md index b21f63a4..3cfda213 100644 --- a/docs/widgets.md +++ b/docs/widgets.md @@ -46,6 +46,7 @@ Dashy has support for displaying dynamic content in the form of widgets. There a - [CPU Usage Current](#current-cpu-usage) - [CPU Usage Per Core](#cpu-usage-per-core) - [CPU Usage History](#cpu-usage-history) + - [Memory Usage Current](#current-memory-usage) - [Dynamic Widgets](#dynamic-widgets) - [Iframe Widget](#iframe-widget) - [HTML Embed Widget](#html-embedded-widget) @@ -1240,6 +1241,22 @@ Recent CPU usage history, across all cores, and displayed by user and system --- +### Current Memory Usage + +Real-time memory usage gauge, with more info visible on click + +

+ +##### Example + +```yaml +- type: gl-current-mem + options: + hostname: http://192.168.130.2:61208 +``` + +--- + ## Dynamic Widgets ### Iframe Widget diff --git a/src/components/Widgets/GlMemGauge.vue b/src/components/Widgets/GlMemGauge.vue new file mode 100644 index 00000000..c43e400d --- /dev/null +++ b/src/components/Widgets/GlMemGauge.vue @@ -0,0 +1,136 @@ + + + + + diff --git a/src/components/Widgets/WidgetBase.vue b/src/components/Widgets/WidgetBase.vue index 55d555c0..0e1df96f 100644 --- a/src/components/Widgets/WidgetBase.vue +++ b/src/components/Widgets/WidgetBase.vue @@ -130,6 +130,13 @@ @error="handleError" :ref="widgetRef" /> + import('@/components/Widgets/ExchangeRates.vue'), Flights: () => import('@/components/Widgets/Flights.vue'), GitHubTrending: () => import('@/components/Widgets/GitHubTrending.vue'), + GitHubProfile: () => import('@/components/Widgets/GitHubProfile.vue'), GlCpuCores: () => import('@/components/Widgets/GlCpuCores.vue'), GlCpuGauge: () => import('@/components/Widgets/GlCpuGauge.vue'), GlCpuHistory: () => import('@/components/Widgets/GlCpuHistory.vue'), - GitHubProfile: () => import('@/components/Widgets/GitHubProfile.vue'), + GlMemGauge: () => import('@/components/Widgets/GlMemGauge.vue'), HealthChecks: () => import('@/components/Widgets/HealthChecks.vue'), IframeWidget: () => import('@/components/Widgets/IframeWidget.vue'), Jokes: () => import('@/components/Widgets/Jokes.vue'), diff --git a/src/utils/MiscHelpers.js b/src/utils/MiscHelpers.js index bee89e6f..5e998048 100644 --- a/src/utils/MiscHelpers.js +++ b/src/utils/MiscHelpers.js @@ -90,6 +90,15 @@ export const capitalize = (str) => { return words.replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase()))); }; +/* Given a mem size in bytes, will return it in appropriate unit */ +export const convertBytes = (bytes, decimals = 2) => { + if (bytes === 0) return '0 Bytes'; + const k = 1024; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return `${parseFloat((bytes / (k ** i)).toFixed(decimals))} ${sizes[i]}`; +}; + /* Round price to appropriate number of decimals */ export const roundPrice = (price) => { if (Number.isNaN(price)) return price;