diff --git a/docs/widgets.md b/docs/widgets.md index 842a996b..d65a0f52 100644 --- a/docs/widgets.md +++ b/docs/widgets.md @@ -445,6 +445,24 @@ Pull recent load usage in 1, 5 and 15 minute intervals, from NetData. --- +### System Info + +Displays info about the server which Dashy is hosted on. Includes user + host, operating system, uptime and basic memory & load data. + +

+ +##### Options + +No config options. + +##### Example + +```yaml +- type: system-info +``` + +--- + ## Dynamic Widgets ### Iframe Widget diff --git a/server.js b/server.js index f3455f46..52703461 100644 --- a/server.js +++ b/server.js @@ -24,7 +24,8 @@ require('./services/config-validator'); // Include and kicks off the config file const statusCheck = require('./services/status-check'); // Used by the status check feature, uses GET const saveConfig = require('./services/save-config'); // Saves users new conf.yml to file-system const rebuild = require('./services/rebuild-app'); // A script to programmatically trigger a build -const sslServer = require('./services/ssl-server'); +const systemInfo = require('./services/system-info'); // Basic system info, for resource widget +const sslServer = require('./services/ssl-server'); // TLS-enabled web server /* Helper functions, and default config */ const printMessage = require('./services/print-message'); // Function to print welcome msg on start @@ -91,6 +92,16 @@ const app = express() }).catch((response) => { res.end(JSON.stringify(response)); }); + }) + // GET endpoint to return system info, for widget + .use(ENDPOINTS.systemInfo, (req, res) => { + try { + const results = systemInfo(); + systemInfo.success = true; + res.end(JSON.stringify(results)); + } catch (e) { + res.end(JSON.stringify({ success: false, message: e })); + } }); /* Create HTTP server from app on port, and print welcome message */ diff --git a/services/system-info.js b/services/system-info.js new file mode 100644 index 00000000..baf10012 --- /dev/null +++ b/services/system-info.js @@ -0,0 +1,24 @@ +/** + * Gets basic system info, for the resource usage widget + */ +const os = require('os'); + +module.exports = () => { + const meta = { + timestamp: new Date(), + uptime: os.uptime(), + hostname: os.hostname(), + username: os.userInfo().username, + system: `${os.version()} (${os.platform()})`, + }; + + const memory = { + total: `${Math.round(os.totalmem() / (1024 * 1024 * 1024))} GB`, + freePercent: (os.freemem() / os.totalmem()).toFixed(2), + }; + + const loadAv = os.loadavg(); + const load = { one: loadAv[0], five: loadAv[1], fifteen: loadAv[2] }; + + return { meta, memory, load }; +}; diff --git a/src/components/Widgets/SystemInfo.vue b/src/components/Widgets/SystemInfo.vue new file mode 100644 index 00000000..78853d77 --- /dev/null +++ b/src/components/Widgets/SystemInfo.vue @@ -0,0 +1,158 @@ + + + + + diff --git a/src/components/Widgets/WidgetBase.vue b/src/components/Widgets/WidgetBase.vue index ae56ab88..5057979e 100644 --- a/src/components/Widgets/WidgetBase.vue +++ b/src/components/Widgets/WidgetBase.vue @@ -102,6 +102,13 @@ @error="handleError" :ref="widgetRef" /> +