Created
January 17, 2015 08:08
-
-
Save hideack/253a24e5f32fba293d97 to your computer and use it in GitHub Desktop.
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
require('date-utils'); | |
var blessed = require('blessed'), | |
contrib = require('blessed-contrib'), | |
screen = blessed.screen(), | |
grid = new contrib.grid({rows: 1, cols: 2}), | |
grid2 = new contrib.grid({rows: 2, cols: 1}), | |
smc = require('smc'), | |
Tail = require('tail').Tail; | |
// Panel settings | |
grid.set(0, 0, contrib.line, | |
{ style: { line: "yellow", text: "green", baseline: "black"}, xLabelPadding: 5, xPadding: 5, label: 'SMC temperature'} | |
); | |
grid2.set(0, 0, contrib.log, {fg:"green", label: 'redis Log'}); | |
grid2.set(1, 0, contrib.log, {fg:"blue", label: 'temperature'}); | |
grid.set(0, 1, grid2); | |
grid.applyLayout(screen); | |
var line = grid.get(0, 0); | |
var redisLog = grid2.get(0,0); | |
var tempLog = grid2.get(1,0); | |
var lineData = {x: [],y: []}; | |
line.setData(lineData.x, lineData.y) | |
// --- Update --- | |
// Graph | |
setInterval(function() { | |
if (lineData.x.length > 10) { | |
lineData.x.shift(); | |
lineData.y.shift(); | |
} | |
var date = new Date(); | |
lineData.y.push(smc.temperature()); | |
lineData.x.push(date.toFormat("SS")); | |
line.setData(lineData.x, lineData.y) | |
screen.render(); | |
}, 2000); | |
screen.key(['escape', 'q', 'C-c'], function(ch, key) { | |
return process.exit(0); | |
}); | |
// Log(redis) | |
tail = new Tail("/usr/local/var/log/redis.log"); | |
tail.on("line", function(data) { | |
redisLog.log(data); | |
}); | |
// Log(smc temperature) | |
setInterval(function() { | |
var date = new Date(); | |
tempLog.log(date.toFormat("[HH:MM:SS] ") + smc.temperature()); | |
screen.render(); | |
}, 1000); | |
screen.render(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment