Skip to content

Commit 5947304

Browse files
author
Aymeric Lavit d'Hautefort
committed
reworked nbr of open files
1 parent def8a88 commit 5947304

File tree

6 files changed

+34
-9
lines changed

6 files changed

+34
-9
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ PM2 module to automatically monitor vital signs of your server :
1212
* Free and used memory space
1313
* Operating System
1414
* All processes running
15+
* TTY/SSH opened
16+
* Total opened files
1517
* Network speed (input and output)
1618

19+
##Requirements
20+
21+
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`.
22+
1723
# pm2-server-monit
1824

1925
## Install
@@ -24,6 +30,18 @@ $ npm install pm2 -g
2430
$ pm2 install pm2-server-monit
2531
```
2632

33+
##Configuration
34+
35+
Default settings:
36+
37+
* `drive` is `/`
38+
39+
To modify the config values you can use Keymetrics dashboard or the following commands:
40+
41+
```bash
42+
pm2 set pm2-server-monit:drive /
43+
```
44+
2745
## Uninstall
2846

2947
```bash

app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var users = require('./lib/users.js');
1010
var netstat = require('./lib/netstat.js');
1111
var proc = require('./lib/proc');
1212
var actions = require('./lib/actions.js');
13-
var lsof = require('./lib/lsof.js');
13+
var lsof = require('./lib/openfiles.js');
1414

1515
pmx.initModule({
1616
widget : {

lib/actions.js

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ function initActions() {
6262
return reply(result);
6363
});
6464
});
65+
66+
pmx.action('ifconfig', function(reply) {
67+
var open_ports = shelljs.exec('ifconfig', { async : true, silent : true }, function(err, out) {
68+
var result = out.replace(/\n/g, "<br />");
69+
return reply(result);
70+
});
71+
});
6572
}
6673

6774
module.exports.initActions = initActions;

lib/drive.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ var diskPattern = /^(\S+)\n?\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+?)\n/mg;
99
function refreshMetrics(conf) {
1010
shelljs.exec('df -k', { async : true, silent : true }, function(err, out) {
1111

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

1616
var total = 0;
@@ -24,7 +24,7 @@ function refreshMetrics(conf) {
2424
var disk_info = lines[i];
2525
}
2626

27-
if (typeof(disk_info) == 'undefined') {
27+
if (typeof(disk_info) === 'undefined') {
2828
return pmx.notify('disk name invalid');
2929
}
3030

lib/netstat.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ function startNetstat() {
2626
});
2727
}
2828

29-
console.log(stats.interface);
3029
if (metrics[stats.interface]) {
3130
metrics[stats.interface]['output'].set(((stats.outputBytes)/1048576).toFixed(2) + 'MB/s');
3231
metrics[stats.interface]['input'].set(((stats.inputBytes)/1048576).toFixed(2) + 'MB/s');
@@ -37,7 +36,7 @@ function startNetstat() {
3736
if (i == (Object.keys(metrics).length - 1)) {
3837
metrics.total.input.set(totalIn.toFixed(2) + 'MB/S');
3938
metrics.total.output.set(totalOut.toFixed(2) + 'MB/s');
40-
console.log(totalIn.toFixed(2) + 'MB/S');
39+
4140
i = 0;
4241
totalIn = 0;
4342
totalOut = 0;

lib/lsof.js renamed to lib/openfiles.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ var metrics = {};
66
var REFRESH_RATE = 30000;
77

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

2626
function init() {
2727
initMetrics();
28+
2829
refreshMetrics();
2930
setInterval(refreshMetrics.bind(this), REFRESH_RATE);
3031
}

0 commit comments

Comments
 (0)