Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jperkin/node-statusmon
base: 8071a0d270
...
head fork: jperkin/node-statusmon
compare: e86977f2be
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Feb 29, 2012
@jperkin Rename the executable "statusmon.js", the "node-" is pretty redundant
here (though useful for the project name).
f62bdab
@jperkin Move system.mpstat out into its own cpu.js probe and put it under
a cpu.* namespace which better matches other probes, and allows
for future growth.
baaeb33
@jperkin Simplify things with better use of split(). e86977f
View
35 probes/cpu.js
@@ -0,0 +1,35 @@
+/*
+ * CPU statistics
+ */
+
+var exec = require('child_process').exec;
+
+/*
+ * Unfortunately the majority of systems are en_US based, so we go with
+ * the wrong spelling of 'utilisation' for the least hassle ;)
+ */
+function get_cpu_utilization(callback)
+{
+ switch (process.platform) {
+ case 'linux':
+ exec('mpstat -u -P ALL 1 1', function (err, stdout, stderr) {
+ stdout.split('\n\n')[1].split('\n').forEach(function (line) {
+ var ret = {};
+ var vals = line.split(/\s+/);
+ if (!vals[1].match(/\d+/)) {
+ return;
+ }
+ ret['cpu.utilization.cpu' + vals[1] + '.user'] = vals[2];
+ ret['cpu.utilization.cpu' + vals[1] + '.system'] = vals[4];
+ ret['cpu.utilization.cpu' + vals[1] + '.iowait'] = vals[5];
+ ret['cpu.utilization.cpu' + vals[1] + '.idle'] = vals[10];
+ callback(ret);
+ });
+ });
+ break;
+ }
+}
+
+module.exports.probes = {
+ 'cpu.utilization': get_cpu_utilization,
+}
View
30 probes/system.js
@@ -5,35 +5,6 @@
var os = require('os');
var exec = require('child_process').exec;
-function get_mpstat(callback)
-{
- switch (process.platform) {
- case 'linux':
- exec('mpstat -u -P ALL 1 1', function (err, stdout, stderr) {
- var capture = 0;
- stdout.split('\n').forEach(function (line) {
- var ret = {};
- if (line.length === 0) {
- capture = (capture) ? 0 : 1;
- return;
- }
- if (capture) {
- var vals = line.split(/\s+/);
- if (!vals[1].match(/\d+/)) {
- return;
- }
- ret['system.mpstat.cpu' + vals[1] + '.user'] = vals[2];
- ret['system.mpstat.cpu' + vals[1] + '.system'] = vals[4];
- ret['system.mpstat.cpu' + vals[1] + '.iowait'] = vals[5];
- ret['system.mpstat.cpu' + vals[1] + '.idle'] = vals[10];
- callback(ret);
- }
- });
- });
- break;
- }
-}
-
function get_loadavg(callback)
{
var vals = os.loadavg();
@@ -74,7 +45,6 @@ function get_users(callback)
}
module.exports.probes = {
- 'system.mpstat': get_mpstat,
'system.loadavg': get_loadavg,
'system.uptime': get_uptime,
'system.users': get_users,
View
0  node-statusmon.js → statusmon.js
File renamed without changes

No commit comments for this range

Something went wrong with that request. Please try again.