From f88eeafafa990b1fe878c62f038d544da177c47a Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Thu, 26 May 2022 22:28:59 -0400 Subject: [PATCH] Added a page for memory stats --- assets/coffee/memory.coffee | 24 ++++++++++++++++++++++++ assets/coffee/sentry.coffee | 19 +++++++++++++++++++ assets/sass/sentry.sass | 4 ++++ assets/twig/index.twig | 10 +++++++++- assets/twig/memory.twig | 26 ++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 assets/coffee/memory.coffee create mode 100644 assets/twig/memory.twig diff --git a/assets/coffee/memory.coffee b/assets/coffee/memory.coffee new file mode 100644 index 0000000..34d7c66 --- /dev/null +++ b/assets/coffee/memory.coffee @@ -0,0 +1,24 @@ +si = require('systeminformation') + +window.onload = () -> + # Grab the static CPU information + si.mem() + .then((data) -> + document.getElementById('memoryTotal').innerText = @formatBytes(data.total) + ).catch((error) -> + console.error(error) + ) + + # Start the CPU temperature loop + getMemoryUsage() + +getMemoryUsage = () -> + si.mem() + .then((data) -> + document.getElementById('memoryFree').innerText = @formatBytes(data.free) + document.getElementById('memoryActive').innerText = @formatBytes(data.active) + document.getElementById('memoryBuffCache').innerText = @formatBytes(data.buffcache) + ).catch((error) -> + console.error(error) + ) + setTimeout(getMemoryUsage, 2000) diff --git a/assets/coffee/sentry.coffee b/assets/coffee/sentry.coffee index ea75851..9f50e7a 100644 --- a/assets/coffee/sentry.coffee +++ b/assets/coffee/sentry.coffee @@ -1,2 +1,21 @@ @loadPage = (pagePath) -> window.location.href = pagePath + '.html' + +@formatBytes = (bytes, decimals = 2) -> + if bytes == 0 + return '0 Bytes' + k = 1024 + dm = if decimals < 0 then 0 else decimals + sizes = [ + 'Bytes' + 'KB' + 'MB' + 'GB' + 'TB' + 'PB' + 'EB' + 'ZB' + 'YB' + ] + i = Math.floor(Math.log(bytes) / Math.log(k)) + parseFloat((bytes / k ** i).toFixed(dm)) + ' ' + sizes[i] diff --git a/assets/sass/sentry.sass b/assets/sass/sentry.sass index 52cc0a1..3377874 100644 --- a/assets/sass/sentry.sass +++ b/assets/sass/sentry.sass @@ -57,3 +57,7 @@ button p.no-margin margin-bottom: 0 + +#systemPages + > div:nth-child(2n + 3) + margin-left: 0 diff --git a/assets/twig/index.twig b/assets/twig/index.twig index b84c98d..502cfbe 100644 --- a/assets/twig/index.twig +++ b/assets/twig/index.twig @@ -8,7 +8,7 @@ -
+
+ + +
{% endblock %} diff --git a/assets/twig/memory.twig b/assets/twig/memory.twig new file mode 100644 index 0000000..4b9dffb --- /dev/null +++ b/assets/twig/memory.twig @@ -0,0 +1,26 @@ +{% extends 'layout.twig' %} + +{% block scripts %} + +{% endblock %} + +{% block content %} + +
+
+

Memory Info

+
+
+ +
+

N/a free out of N/a.

+

N/a is actively used | N/a is used in buffers/cache.

+
+ +
+
+ Back +
+
+ +{% endblock %}