-
Notifications
You must be signed in to change notification settings - Fork 1
/
probe.js
77 lines (64 loc) · 1.69 KB
/
probe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var pmx = require('pmx');
var pm2 = require('pm2');
var fs = require('fs');
var path = require('path');
var exec = require('child_process').exec;
var shelljs = require('shelljs');
pmx.initModule({
pid: pmx.getPID(path.join(process.env.HOME, '.pm2', 'pm2.pid')),
widget : {
type: 'generic',
theme: ['#1d3b4a', '#1B2228', '#22bbe2', '#22bbe2'],
logo: 'https://raw.githubusercontent.com/Unitech/pm2/master/pres/pm2-v4.png',
el : {
probes : false,
actions : true
},
block : {
errors : true,
main_probes : ['Processes'],
latency : false,
versioning : false,
show_module_meta : false
}
}
});
var probe = pmx.probe();
var pm2_procs = 0;
pm2.connect(function() {
setInterval(function() {
pm2.list(function(err, procs) {
pm2_procs = procs.length;
});
}, 2000);
probe.metric({
name : 'Processes',
value : function() {
return pm2_procs;
}
});
var pm2_instances = probe.metric({name : 'PM2 Instances Running'});
setInterval(function() {
exec('pgrep PM2', function(err, stdout, stderr) {
if (err || stderr) {
pm2_instances = 'N/A'
return;
}
var nb = stdout.split('\n')
nb.splice(-1, 1)
pm2_instances = nb.length;
});
}, 2000)
});
pmx.action('flush pm2 logs', { comment : 'Flush logs' } , function(reply) {
var child = shelljs.exec('pm2 flush');
return reply(child);
});
pmx.action('pm2 ls', { comment : 'Flush logs' } , function(reply) {
var child = shelljs.exec('pm2 ls');
return reply(child);
});
pmx.action('report', function(reply) {
var child = shelljs.exec('pm2 report');
return reply(child);
});