Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #80 from naparuba/master
Browse files Browse the repository at this point in the history
Résolution du soucis de mesure de la mémoire disponible
  • Loading branch information
DjLeChuck committed May 31, 2018
2 parents 62be8c2 + 7f87c43 commit 7a0bddc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 21 additions & 3 deletions src/lib/osutils.js
Expand Up @@ -18,11 +18,29 @@ exports.processUptime = function(){
return process.uptime();
};

// Memory
exports.freemem = function(){
return _os.freemem() / ( 1024 * 1024 );
// Memory: read directly into /proc/meminfo because _os.freemem() do not count cached as available
exports.freemem = function() {
var fs = require( 'fs' );
var array = fs.readFileSync( '/proc/meminfo' ).toString().split( "\n" );
var free_memory = 0;
for ( var idx in array ) {
var line = array[ idx ];
var elts = line.split( /\s+/ ); // looks like key value KB <= some value are without KB but we do not look at them
var key = elts[ 0 ];
// Total memory of the system (physical): MemTotal
// Free memory =
// * MemFree:
// * Buffers: (into files)
// * Cached: (file flushed but before the disks)
// * SReclaimable: (kernel slabs that can be release)
if ( key === 'MemFree:' || key === 'Buffers:' || key === 'Cached:' || key === 'SReclaimable:' ) {
free_memory += parseInt( elts[ 1 ] ); // Note: values are in KB
}
}
return free_memory / 1024; // into MB, to match totalmem
};


exports.totalmem = function(){
return _os.totalmem() / ( 1024 * 1024 );
};
Expand Down
2 changes: 1 addition & 1 deletion src/routes/get.js
Expand Up @@ -127,7 +127,7 @@ router.get('/', async (req, res, next) => {
data = await getEsSystems();
break;
case 'temperature':
const currentTemp = execSync('cat /sys/class/thermal/thermal_zone0/temp').toString() / 1000;
const currentTemp = execSync('cat /sys/class/thermal/thermal_zone0/temp 2> /dev/null || echo 0').toString() / 1000;
const maxTemp = 100;
const currentPercent = Math.floor(currentTemp * 100 / maxTemp);

Expand Down

0 comments on commit 7a0bddc

Please sign in to comment.