Anybody know how to add an "Uptime" indicator to the gauge widget?
The way they're doing things in the default gauge is by running command line tools then processing the output to get the data they need. "uptime" is the command-line tool to find uptime. I don't know javascript really at all, so I'd have a hard time rewriting their code, but it's basically just a matter of modifying one of their handler functions to run uptime and process its output.
In the gauge prototype, check out CommandMonitor.js. For example, this is used to do the disk activity gauge:
Code:
function IOStatMonitor (frequency) {
this.commandLine = "/usr/sbin/iostat -d -C -w " + frequency;
}
IOStatMonitor.prototype = new CommandMonitor();
IOStatMonitor.prototype.processLine = function (line)
{
// KB/t tps MB/s KB/t tps MB/s KB/t tps MB/s us sy id
// 20.06 5 0.09 9.70 0 0.00 10.67 0 0.00 4 3 92
// Take off leading and trailing spaces
line = line.replace(/^\s+/, "");
line = line.replace(/\s+$/, "");
// Look for a line of numbers
var match;
if ((match = line.match(/^(\s*[\d\.]+)+$/)) != null) {
var n = match[0].split(/\s+/);
if (n.length > 0 && n.length % 3 == 0) {
// Add up all the MB/s numbers
var mbps = 0.0;
for (var i = 2; i < n.length - 3; i += 3) {
mbps += parseFloat(n[i]);
}
// Grab the inverse of the CPU idle time and call it load
var load = 100 - parseInt(n[n.length - 1]);
// alert("disk io: " + mbps + ", load: " + load);
if (this.ioCallback != null) {
this.ioCallback(mbps);
}
if (this.loadCallback != null) {
this.loadCallback(load);
}
}
else {
alert("iostat format violation: expecting groups of three:");
alert(line);
}
}
}
Dashcode looks good. Easy to use and powerful. However, I think it's going to require a fairly good knowledge of JavaScript. Oh well, that gives me something new to learn!