Commit f864cd51 authored by mercury233's avatar mercury233

fix

parent 30e8d494
...@@ -12,14 +12,17 @@ log = bunyan.createLogger name: "mycard-room" ...@@ -12,14 +12,17 @@ log = bunyan.createLogger name: "mycard-room"
#获取可用内存 #获取可用内存
get_memory_usage = ()-> get_memory_usage = ()->
prc_free = spawnSync("free", []) prc_free = spawnSync("free", [])
lines = prc_free.stdout.toString().split(/\n/g) if (prc_free.stdout)
line = lines[1].split(/\s+/) lines = prc_free.stdout.toString().split(/\n/g)
total = parseInt(line[1], 10) line = lines[1].split(/\s+/)
free = parseInt(line[3], 10) total = parseInt(line[1], 10)
buffers = parseInt(line[5], 10) free = parseInt(line[3], 10)
cached = parseInt(line[6], 10) buffers = parseInt(line[5], 10)
actualFree = free + buffers + cached cached = parseInt(line[6], 10)
percentUsed = parseFloat(((1 - (actualFree / total)) * 100).toFixed(2)) actualFree = free + buffers + cached
percentUsed = parseFloat(((1 - (actualFree / total)) * 100).toFixed(2))
else
percentUsed = 0
return percentUsed return percentUsed
class Room class Room
......
...@@ -25,14 +25,18 @@ ...@@ -25,14 +25,18 @@
get_memory_usage = function() { get_memory_usage = function() {
var actualFree, buffers, cached, free, line, lines, percentUsed, prc_free, total; var actualFree, buffers, cached, free, line, lines, percentUsed, prc_free, total;
prc_free = spawnSync("free", []); prc_free = spawnSync("free", []);
lines = prc_free.stdout.toString().split(/\n/g); if (prc_free.stdout) {
line = lines[1].split(/\s+/); lines = prc_free.stdout.toString().split(/\n/g);
total = parseInt(line[1], 10); line = lines[1].split(/\s+/);
free = parseInt(line[3], 10); total = parseInt(line[1], 10);
buffers = parseInt(line[5], 10); free = parseInt(line[3], 10);
cached = parseInt(line[6], 10); buffers = parseInt(line[5], 10);
actualFree = free + buffers + cached; cached = parseInt(line[6], 10);
percentUsed = parseFloat(((1 - (actualFree / total)) * 100).toFixed(2)); actualFree = free + buffers + cached;
percentUsed = parseFloat(((1 - (actualFree / total)) * 100).toFixed(2));
} else {
percentUsed = 0;
}
return percentUsed; return percentUsed;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment