Created
July 15, 2016 06:05
-
-
Save syuhei176/743e827c810c487a830b8d6c45b1c700 to your computer and use it in GitHub Desktop.
push CPU Load Average to Milkcocoa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MilkCocoa = require('milkcocoa'); | |
var milkcocoa = new MilkCocoa('guitarib0a5pfk.mlkcca.com'); | |
var ds = milkcocoa.dataStore('loadaverage'); | |
ds.on('push', function(e) { | |
console.log(e); | |
}); | |
getUptimeLoop(); | |
function getUptimeLoop() { | |
getUptime(function(data) { | |
ds.push({ | |
val1: data[0], | |
val2: data[1] | |
}); | |
setTimeout(getUptimeLoop, 10000); | |
}); | |
} | |
function getUptime(cb) { | |
var exec = require('child_process').exec; | |
var child = exec('uptime', function (error, stdout, stderr) { | |
var la = stdout.split(',')[2].split(':')[1]; | |
var las = la.split(" "); | |
cb([Number(las[1]), Number(las[2])]); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment