Skip to content

Commit

Permalink
Merge pull request #89 from colinrcummings/master
Browse files Browse the repository at this point in the history
Add the ability to hide selected charts
  • Loading branch information
RafalWilinski authored Oct 18, 2017
2 parents 34a7ff5 + 3853bd7 commit b782618
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

```

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -20,6 +20,11 @@
"email": "[email protected]",
"url": "https://github.com/JulienBreux/"
},
{
"name": "Colin Cummings",
"email": "[email protected]",
"url": "https://github.com/colinrcummings/"
},
{
"name": "Ferdinand Mütsch",
"email": "[email protected]",
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};
10 changes: 10 additions & 0 deletions src/helpers/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
8 changes: 8 additions & 0 deletions src/middleware-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')));

Expand Down
14 changes: 7 additions & 7 deletions src/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
{{style}}
</style>
</head>
<body>
<body class="{{bodyClasses}}">
<div class="content">
<div class="header">
<b>{{title}}</b>
<div id="span-controls" class="span-controls">
</div>
</div>
<div class="container">
<div class="container cpu">
<div class="stats-column">
<h5>CPU Usage</h5>
<h1 id="cpuStat">- %</h1>
Expand All @@ -24,7 +24,7 @@ <h1 id="cpuStat">- %</h1>
<canvas id="cpuChart" width="400" height="100"></canvas>
</div>
</div>
<div class="container">
<div class="container mem">
<div class="stats-column">
<h5>Memory Usage</h5>
<h1 id="memStat">- %</h1>
Expand All @@ -33,7 +33,7 @@ <h1 id="memStat">- %</h1>
<canvas id="memChart" width="200" height="100"></canvas>
</div>
</div>
<div class="container">
<div class="container load">
<div class="stats-column">
<h5>One Minute Load Avg</h5>
<h1 id="loadStat">-</h1>
Expand All @@ -42,7 +42,7 @@ <h1 id="loadStat">-</h1>
<canvas id="loadChart" width="200" height="100"></canvas>
</div>
</div>
<div class="container">
<div class="container responseTime">
<div class="stats-column">
<h5>Response Time</h5>
<h1 id="responseTimeStat">-</h1>
Expand All @@ -51,7 +51,7 @@ <h1 id="responseTimeStat">-</h1>
<canvas id="responseTimeChart" width="200" height="100"></canvas>
</div>
</div>
<div class="container">
<div class="container rps">
<div class="stats-column">
<h5>Requests per Second</h5>
<h1 id="rpsStat">-</h1>
Expand All @@ -60,7 +60,7 @@ <h1 id="rpsStat">-</h1>
<canvas id="rpsChart" width="200" height="100"></canvas>
</div>
</div>
<div class="container">
<div class="container statusCodes">
<div class="stats-column">
<h5>Status Codes</h5>
<h6 class="status-code status-code-2xx">2xx</h6>
Expand Down
9 changes: 9 additions & 0 deletions src/public/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b782618

Please sign in to comment.