Skip to content

Commit

Permalink
reworked nbr of open files
Browse files Browse the repository at this point in the history
  • Loading branch information
Aymeric Lavit d'Hautefort committed Jul 21, 2016
1 parent def8a88 commit 5947304
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ PM2 module to automatically monitor vital signs of your server :
* Free and used memory space
* Operating System
* All processes running
* TTY/SSH opened
* Total opened files
* Network speed (input and output)

##Requirements

This pm2 module currently uses `ifconfig` to get network status on linux machines, usually installed by default. If not, install with `sudo apt-get install net-tools`.

# pm2-server-monit

## Install
Expand All @@ -24,6 +30,18 @@ $ npm install pm2 -g
$ pm2 install pm2-server-monit
```

##Configuration

Default settings:

* `drive` is `/`

To modify the config values you can use Keymetrics dashboard or the following commands:

```bash
pm2 set pm2-server-monit:drive /
```

## Uninstall

```bash
Expand Down
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var users = require('./lib/users.js');
var netstat = require('./lib/netstat.js');
var proc = require('./lib/proc');
var actions = require('./lib/actions.js');
var lsof = require('./lib/lsof.js');
var lsof = require('./lib/openfiles.js');

pmx.initModule({
widget : {
Expand Down
7 changes: 7 additions & 0 deletions lib/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ function initActions() {
return reply(result);
});
});

pmx.action('ifconfig', function(reply) {
var open_ports = shelljs.exec('ifconfig', { async : true, silent : true }, function(err, out) {
var result = out.replace(/\n/g, "<br />");
return reply(result);
});
});
}

module.exports.initActions = initActions;
6 changes: 3 additions & 3 deletions lib/drive.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var diskPattern = /^(\S+)\n?\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+?)\n/mg;
function refreshMetrics(conf) {
shelljs.exec('df -k', { async : true, silent : true }, function(err, out) {

if (err || (typeof(out) === 'undefined')) {
return pmx.notify('Fail: could not retrieve hard drive metrics', err);
if (err || !out || (typeof(out) === 'undefined')) {
return pmx.notify('Fail: could not retrieve hard drive metrics');
}

var total = 0;
Expand All @@ -24,7 +24,7 @@ function refreshMetrics(conf) {
var disk_info = lines[i];
}

if (typeof(disk_info) == 'undefined') {
if (typeof(disk_info) === 'undefined') {
return pmx.notify('disk name invalid');
}

Expand Down
3 changes: 1 addition & 2 deletions lib/netstat.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function startNetstat() {
});
}

console.log(stats.interface);
if (metrics[stats.interface]) {
metrics[stats.interface]['output'].set(((stats.outputBytes)/1048576).toFixed(2) + 'MB/s');
metrics[stats.interface]['input'].set(((stats.inputBytes)/1048576).toFixed(2) + 'MB/s');
Expand All @@ -37,7 +36,7 @@ function startNetstat() {
if (i == (Object.keys(metrics).length - 1)) {
metrics.total.input.set(totalIn.toFixed(2) + 'MB/S');
metrics.total.output.set(totalOut.toFixed(2) + 'MB/s');
console.log(totalIn.toFixed(2) + 'MB/S');

i = 0;
totalIn = 0;
totalOut = 0;
Expand Down
7 changes: 4 additions & 3 deletions lib/lsof.js → lib/openfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ var metrics = {};
var REFRESH_RATE = 30000;

function refreshMetrics() {
shelljs.exec('lsof -i -n -P | wc -l', { async : true, silent : true }, function(err, out) {
shelljs.exec('cat /proc/sys/fs/file-nr', { async : true, silent : true }, function(err, out) {
if (err) {
return pmx.notify('Fail: could not retrieve lsof metrics', err);
}
var result = out.replace(/\n/g, "");
result = parseInt(result) - 1;
var result = out.replace(/\n/g, "").split(' ')[0];
result = parseInt(result);
metrics.lsof.set(result);
});
}
Expand All @@ -25,6 +25,7 @@ function initMetrics() {

function init() {
initMetrics();

refreshMetrics();
setInterval(refreshMetrics.bind(this), REFRESH_RATE);
}
Expand Down

0 comments on commit 5947304

Please sign in to comment.