Commit f864cd51 authored by mercury233's avatar mercury233

fix

parent 30e8d494
...@@ -12,6 +12,7 @@ log = bunyan.createLogger name: "mycard-room" ...@@ -12,6 +12,7 @@ log = bunyan.createLogger name: "mycard-room"
#获取可用内存 #获取可用内存
get_memory_usage = ()-> get_memory_usage = ()->
prc_free = spawnSync("free", []) prc_free = spawnSync("free", [])
if (prc_free.stdout)
lines = prc_free.stdout.toString().split(/\n/g) lines = prc_free.stdout.toString().split(/\n/g)
line = lines[1].split(/\s+/) line = lines[1].split(/\s+/)
total = parseInt(line[1], 10) total = parseInt(line[1], 10)
...@@ -20,6 +21,8 @@ get_memory_usage = ()-> ...@@ -20,6 +21,8 @@ get_memory_usage = ()->
cached = parseInt(line[6], 10) cached = parseInt(line[6], 10)
actualFree = free + buffers + cached actualFree = free + buffers + cached
percentUsed = parseFloat(((1 - (actualFree / total)) * 100).toFixed(2)) percentUsed = parseFloat(((1 - (actualFree / total)) * 100).toFixed(2))
else
percentUsed = 0
return percentUsed return percentUsed
class Room class Room
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
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", []);
if (prc_free.stdout) {
lines = prc_free.stdout.toString().split(/\n/g); lines = prc_free.stdout.toString().split(/\n/g);
line = lines[1].split(/\s+/); line = lines[1].split(/\s+/);
total = parseInt(line[1], 10); total = parseInt(line[1], 10);
...@@ -33,6 +34,9 @@ ...@@ -33,6 +34,9 @@
cached = parseInt(line[6], 10); cached = parseInt(line[6], 10);
actualFree = free + buffers + cached; actualFree = free + buffers + cached;
percentUsed = parseFloat(((1 - (actualFree / total)) * 100).toFixed(2)); 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