Skip to content

Commit

Permalink
initial checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
pdiemert committed Oct 15, 2013
1 parent 2715b43 commit eee212e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
plugin-cpu_core
===============
graphdat-plugin-cpu-core
========================

This Graphdat Plugin reports the CPU utilization of each CPU core individually.
In the legend will be the hostname followed by "-CX" where X is the core number.
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

var _os = require('os');
var _source = _os.hostname();
var _interval = parseInt(process.argv[1]) || 1000;

var _last;

function poll()
{
var cpus = _os.cpus();

for(var idx = 0; idx < cpus.length; idx++)
{
var e = cpus[idx];
e.total = 0;
for(var t in e.times)
e.total += e.times[t];
}

if (_last)
{
for(var idx = 0; idx < cpus.length; idx++)
{
var e = cpus[idx];
var l = _last[idx];
var user = (e.times.user - l.times.user) /
(e.total - l.total);

console.log('CPU_CORE %d %s-C%d',
user, _source, idx + 1);
}
}

_last = cpus;

setTimeout(poll, _interval);
}

poll();
5 changes: 5 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"description" : "Provides per core CPU utilization",
"command" : "node index.js $(pollInterval)",
"metrics" : ["CPU_CORE"]
}

0 comments on commit eee212e

Please sign in to comment.