diff --git a/.eslintrc.json b/.eslintrc.json index ae5919b..e0976d9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -104,7 +104,7 @@ "no-bitwise": "error", "no-caller": "error", "no-catch-shadow": "error", - "no-confusing-arrow": "error", + "no-confusing-arrow": "off", "no-continue": "error", "no-div-regex": "error", "no-duplicate-imports": "error", diff --git a/README.md b/README.md index 5c28739..02ddb4c 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,15 @@ spans: [{ }, { interval: 15, // Every 15 seconds retention: 60 -}] +}], +chartVisibility: { + cpu: true, + mem: true, + load: true, + responseTime: true, + rps: true, + statusCodes: true +} ``` diff --git a/package.json b/package.json index b5df33b..2e4a8f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "express-status-monitor", - "version": "1.0.0", + "version": "1.1.0", "description": "Realtime Monitoring for Express-based Node applications", "main": "index.js", "keywords": [ @@ -20,6 +20,11 @@ "email": "julien.breux@gmail.com", "url": "https://github.com/JulienBreux/" }, + { + "name": "Colin Cummings", + "email": "colinrcummings@gmail.com", + "url": "https://github.com/colinrcummings/" + }, { "name": "Ferdinand Mütsch", "email": "mail@ferdinand-muetsch.de", diff --git a/src/helpers/default-config.js b/src/helpers/default-config.js index 2757dbc..3040b13 100644 --- a/src/helpers/default-config.js +++ b/src/helpers/default-config.js @@ -18,4 +18,12 @@ module.exports = { port: null, websocket: null, iframe: false, + chartVisibility: { + cpu: true, + mem: true, + load: true, + responseTime: true, + rps: true, + statusCodes: true + } }; diff --git a/src/helpers/validate.js b/src/helpers/validate.js index 74a4904..5b5696d 100644 --- a/src/helpers/validate.js +++ b/src/helpers/validate.js @@ -5,12 +5,22 @@ module.exports = config => { return defaultConfig; } + const mungeChartVisibility = configChartVisibility => { + Object.keys(defaultConfig.chartVisibility).forEach(key => { + if (configChartVisibility[key] === false) { + defaultConfig.chartVisibility[key] = false; + } + }); + return defaultConfig.chartVisibility; + }; + config.title = (typeof config.title === 'string') ? config.title : defaultConfig.title; config.path = (typeof config.path === 'string') ? config.path : defaultConfig.path; config.spans = (typeof config.spans === 'object') ? config.spans : defaultConfig.spans; config.port = (typeof config.port === 'number') ? config.port : defaultConfig.port; config.websocket = (typeof config.websocket === 'object') ? config.websocket : defaultConfig.websocket; config.iframe = (typeof config.iframe === 'boolean') ? config.iframe : defaultConfig.iframe; + config.chartVisibility = (typeof config.chartVisibility === 'object') ? mungeChartVisibility(config.chartVisibility) : defaultConfig.chartVisibility; return config; }; diff --git a/src/middleware-wrapper.js b/src/middleware-wrapper.js index 1498649..5f62990 100644 --- a/src/middleware-wrapper.js +++ b/src/middleware-wrapper.js @@ -8,11 +8,19 @@ const socketIoInit = require('./helpers/socket-io-init'); const middlewareWrapper = config => { const validatedConfig = validate(config); + const bodyClasses = Object.keys(validatedConfig.chartVisibility).reduce((accumulator, key) => { + if (config.chartVisibility[key] === false) { + accumulator.push(`hide-${key}`); + } + return accumulator; + }, []).join(' '); + const renderedHtml = fs.readFileSync(path.join(__dirname, '/public/index.html')) .toString() .replace(/{{title}}/g, validatedConfig.title) .replace(/{{port}}/g, validatedConfig.port) + .replace(/{{bodyClasses}}/g, bodyClasses) .replace(/{{script}}/g, fs.readFileSync(path.join(__dirname, '/public/javascripts/app.js'))) .replace(/{{style}}/g, fs.readFileSync(path.join(__dirname, '/public/stylesheets/style.css'))); diff --git a/src/public/index.html b/src/public/index.html index b65c867..8d40292 100644 --- a/src/public/index.html +++ b/src/public/index.html @@ -8,14 +8,14 @@ {{style}} - +
{{title}}
-
+
CPU Usage

- %

@@ -24,7 +24,7 @@

- %

-
+
Memory Usage

- %

@@ -33,7 +33,7 @@

- %

-
+
One Minute Load Avg

-

@@ -42,7 +42,7 @@

-

-
+
Response Time

-

@@ -51,7 +51,7 @@

-

-
+
Requests per Second

-

@@ -60,7 +60,7 @@

-

-
+
Status Codes
2xx
diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index fd6cbe3..02e1465 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -2,6 +2,15 @@ font-family: Helvetica Neue, Helvetica, Arial, sans-serif; } +body.hide-cpu .container.cpu, +body.hide-mem .container.mem, +body.hide-load .container.load, +body.hide-responseTime .container.responseTime, +body.hide-rps .container.rps, +body.hide-statusCodes .container.statusCodes { + display: none; +} + h1 { font-size: 3em; color: #222;