Skip to content

Commit 639564a

Browse files
committed
Merge branch 'development' of https://github.com/xcjs/blur-monitor
2 parents 39540ed + 77f1d2d commit 639564a

21 files changed

+413
-143
lines changed

blurmonitor/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
var Hapi = require('hapi');
77
var Inert = require('inert');
8-
var argv = require('yargs').argv;
98
var path = require('path');
109

1110
var env = require('./util/environment');
11+
var startup = require('./util/startup');
1212

1313
var server = new Hapi.Server({
1414
connections: {
@@ -24,7 +24,7 @@ server.connection({
2424
port: env.port
2525
});
2626

27-
server.register(Inert, () => {});
27+
server.register(Inert);
2828

2929
var routers = [
3030
require('./routes/static'),
@@ -43,10 +43,12 @@ routers.forEach(function (router) {
4343
});
4444
});
4545

46-
server.start((err) => {
47-
if (err) {
48-
throw err;
49-
}
46+
startup.run(function() {
47+
server.start(function(err) {
48+
if (err) {
49+
throw err;
50+
}
5051

51-
console.log('Server running at:', server.info.uri);
52+
console.log('Server running at:', server.info.uri);
53+
});
5254
});

blurmonitor/routes/disks.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
'use strict';
44

55
var diskInfo = require('nodejs-disks');
6+
var _ = require('lodash/array');
67

78
module.exports = getRoutes();
89

@@ -36,12 +37,14 @@ function getDisks() {
3637
function (err, data) {
3738
var i = 0;
3839

39-
data.forEach(function(item) {
40+
var uniqueDrives = _.uniq(data, 'mountpoint');
41+
42+
uniqueDrives.forEach(function(item) {
4043
item.id = i;
4144
i++;
4245
});
4346

44-
resolve(data);
47+
resolve(uniqueDrives);
4548
}
4649
)
4750
}
@@ -57,8 +60,10 @@ function getDisk(id) {
5760
function (err, drives) {
5861
diskInfo.drivesDetail(drives,
5962
function (err, data) {
60-
data[id].id = id;
61-
resolve(data[id]);
63+
var uniqueDrives = _.uniq(data, 'mountpoint');
64+
65+
uniqueDrives[id].id = id;
66+
resolve(uniqueDrives[id]);
6267
}
6368
)
6469
}

blurmonitor/routes/memory.js

Lines changed: 86 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,96 @@ function getRoutes() {
2222
}
2323

2424
function getMemoryStats() {
25-
var free = spawn('free', []);
25+
var free = spawn('free', ['-m']);
2626

27-
var promise = new Promise(function (resolve) {
27+
var promise;
28+
promise = new Promise(function (resolve) {
2829
free.stdout.setEncoding("utf8");
29-
free.stdout.on('data', function (data) {
30-
var lines = data.toString().split(/\n/g),
31-
line1 = lines[1].split(/\s+/),
32-
line3 = lines[3].split(/\s+/),
33-
total = parseInt(line1[1], 10),
34-
free = parseInt(line1[3], 10),
35-
buffers = parseInt(line1[5], 10),
36-
cached = parseInt(line1[6], 10),
37-
actualFree = free + buffers + cached,
38-
actualUsed = total - actualFree,
39-
swapTotal = parseInt(line3[1], 10),
40-
swapUsed = parseInt(line3[2], 10),
41-
swapFree = parseInt(line3[3], 10),
42-
memory = {
43-
total: total,
44-
used: parseInt(line1[2], 10),
45-
free: free,
46-
shared: parseInt(line1[4], 10),
47-
buffers: buffers,
48-
cached: cached,
49-
actualUsed: actualUsed,
50-
actualFree: actualFree,
51-
swapTotal: swapTotal,
52-
swapUsed: swapUsed,
53-
swapFree: swapFree
54-
};
55-
56-
resolve(memory);
30+
free.stdout.on('data', function (stdout) {
31+
resolve(parseFree(stdout));
5732
});
5833
});
5934

6035
return promise;
6136
}
37+
38+
function parseFree(stdout) {
39+
if(stdout.indexOf('available') > -1) {
40+
// >= 3.3.10
41+
return parseNewFree(stdout);
42+
} else {
43+
// < 3.3.10
44+
return parseOldFree(stdout);
45+
}
46+
}
47+
48+
function parseOldFree(stdout) {
49+
var lines = stdout.toString().split(/\n/g);
50+
51+
var line1 = lines[1].split(/\s+/);
52+
var line3 = lines[3].split(/\s+/);
53+
54+
var total = parseInt(line1[1], 10);
55+
var free = parseInt(line1[3], 10);
56+
57+
// buffers + cache
58+
var cache = parseInt(line1[5], 10) + parseInt(line1[6], 10);
59+
60+
var available = free + cache;
61+
var used = total - available;
62+
63+
var shared = parseInt(line1[4], 10);
64+
65+
var swapTotal = parseInt(line3[1], 10);
66+
var swapUsed = parseInt(line3[2], 10);
67+
var swapFree = parseInt(line3[3], 10);
68+
69+
return {
70+
total: total,
71+
used: used,
72+
free: free,
73+
cache: cache,
74+
available: available,
75+
shared: shared,
76+
swap: {
77+
total: swapTotal,
78+
used: swapUsed,
79+
free: swapFree
80+
}
81+
};
82+
}
83+
84+
function parseNewFree(stdout) {
85+
var lines = stdout.toString().split(/\n/g);
86+
87+
var line1 = lines[1].split(/\s+/);
88+
var line2 = lines[2].split(/\s+/);
89+
90+
var total = parseInt(line1[1], 10);
91+
var used = parseInt(line1[2], 10);
92+
93+
var free = parseInt(line1[3], 10);
94+
var cache = parseInt(line1[5], 10);
95+
96+
var available = parseInt(line1[6], 10);
97+
98+
var shared = parseInt(line1[4], 10);
99+
100+
var swapTotal = parseInt(line2[1], 10);
101+
var swapUsed = parseInt(line2[2], 10);
102+
var swapFree = parseInt(line2[3], 10);
103+
104+
return {
105+
total: total,
106+
used: used,
107+
free: free,
108+
cache: cache,
109+
available: available,
110+
shared: shared,
111+
swap: {
112+
total: swapTotal,
113+
used: swapUsed,
114+
free: swapFree
115+
}
116+
};
117+
}

blurmonitor/util/environment.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
'use strict';
44

55
var argv = require('yargs').argv;
6+
var conf = require('../../gulp/conf');
7+
var path = require('path');
68

79
var environments = {
810
dev: 'dev',
@@ -15,6 +17,7 @@ module.exports = getEnvironment();
1517

1618
function getEnvironment() {
1719
var env = {
20+
conf: conf,
1821
environments: environments,
1922
current: getCurrentEnvironment(),
2023
port: getPort(),
@@ -40,9 +43,9 @@ function getStaticRoot() {
4043
var staticRoot = null;
4144

4245
if(currentEnvironment === environments.prod) {
43-
staticRoot = './release/';
46+
staticRoot = conf.paths.dist;
4447
} else {
45-
staticRoot = ['./.tmp/serve/', './src/'];
48+
staticRoot = [path.join(conf.paths.tmp, 'serve'), conf.paths.src];
4649
}
4750

4851
return staticRoot;

blurmonitor/util/startup.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*jslint node: true */
2+
/*jslint esversion: 6 */
3+
4+
'use strict';
5+
6+
var env = require('./environment');
7+
var fs = require('fs');
8+
var fsExtra = require('fs.extra');
9+
var path = require('path');
10+
11+
module.exports = {
12+
run: run
13+
};
14+
15+
function run(cb) {
16+
loadDistributorLogo(cb);
17+
}
18+
19+
function loadDistributorLogo(cb) {
20+
var logoName = 'distributor-logo.png';
21+
var systemDistributorLogo = path.join('/usr/share/icons/hicolor/48x48/apps', logoName);
22+
23+
var debugPath = path.join(env.conf.paths.tmp, 'serve', 'assets/img', logoName);
24+
var releasePath = path.join(env.conf.paths.dist, 'assets/img', logoName);
25+
26+
try {
27+
fsExtra.copy(systemDistributorLogo, debugPath, { replace: true }, cb);
28+
fsExtra.copy(systemDistributorLogo, releasePath, { replace: true }, cb);
29+
} catch(e) {
30+
console.error(e);
31+
}
32+
}

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
"angular-xeditable": "~0.1.9",
5656
"ng-js-tree": "~0.0.7",
5757
"angular-resource": "1.4.8",
58-
"angular-moment": "^0.10.3"
58+
"angular-moment": "^0.10.3",
59+
"lodash": "^4.15.0"
5960
},
6061
"overrides": {
6162
"amcharts": {

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@
5555
},
5656
"dependencies": {
5757
"array-includes": "^3.0.2",
58+
"fs.extra": "^1.3.2",
5859
"hapi": "^13.4.1",
5960
"inert": "^4.0.0",
61+
"lodash": "^3.10.1",
6062
"node-json-transform": "^1.0.6",
6163
"nodejs-disks": "^0.2.1",
6264
"ps-node": "^0.1.1",

src/app/config/blur-monitor.config.constants.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
angular.module('BlurMonitor.config')
55
.constant('moment', window.moment)
6+
.constant('_', window._)
67
// The time interval to call the various services in milliseconds.
78
.constant('refreshInterval', 1000)
8-
.constant('maxSnapshots', 20);
9+
.constant('maxSnapshots', 20)
10+
.constant('processorPercentageThreshold', 90)
11+
.constant('memoryPercentageThreshold', 90);
912
})();

0 commit comments

Comments
 (0)