-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
176 lines (147 loc) · 4.06 KB
/
app.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
var pmx = require('pmx');
const pm2 = require('pm2');
const messenger = require('./src/messenger')
/******************************
* ______ _______ ______
* | __ \ | |__ |
* | __/ | __|
* |___| |__|_|__|______|
*
* PM2 Module Sample
*
******************************/
/**
* Module system documentation
* http://bit.ly/1hnpcgu
*
* Start module in development mode
* $ cd to my-module
* $ pm2 install .
*
* Official modules are published here
* https://github.com/pm2-hive
*/
/**
* Module Entry Point
*
* We first initialize the module by calling
* pmx.initModule({}, cb);
*
*
* More options: http://bit.ly/1EpagZS
*
*/
// pmx.initModule({
// // Options related to the display style on Keymetrics
// widget : {
// // Logo displayed
// logo : 'https://app.keymetrics.io/img/logo/keymetrics-300.png',
// // Module colors
// // 0 = main element
// // 1 = secondary
// // 2 = main border
// // 3 = secondary border
// theme : ['#141A1F', '#222222', '#3ff', '#3ff'],
// // Section to show / hide
// el : {
// probes : true,
// actions : true
// },
// // Main block to show / hide
// block : {
// actions : false,
// issues : true,
// meta : true,
// // Custom metrics to put in BIG
// main_probes : ['test-probe']
// }
// }
// }, function(err, conf) {
// /**
// * Module specifics like connecting to a database and
// * displaying some metrics
// */
// /**
// * Custom Metrics
// *
// * Let's expose some metrics that will be displayed into Keymetrics
// * For more documentation about metrics: http://bit.ly/1PZrMFB
// */
// var Probe = pmx.probe();
// var value_to_inspect = 0;
// /**
// * .metric, .counter, .meter, .histogram are also available (cf doc)
// */
// var val = Probe.metric({
// name : 'test-probe',
// value : function() {
// return value_to_inspect;
// },
// /**
// * Here we set a default value threshold, to receive a notification
// * These options can be overriden via Keymetrics or via pm2
// * More: http://bit.ly/1O02aap
// */
// alert : {
// mode : 'threshold',
// value : 20,
// msg : 'test-probe alert!',
// action : function(val) {
// // Besides the automatic alert sent via Keymetrics
// // You can also configure your own logic to do something
// console.log('Value has reached %d', val);
// }
// }
// });
// setInterval(function() {
// // Then we can see that this value increase over the time in Keymetrics
// value_to_inspect++;
// }, 300);
// /**
// * Simple Actions
// *
// * Now let's expose some triggerable functions
// * Once created you can trigger this from Keymetrics
// *
// */
// pmx.action('env', function(reply) {
// return reply({
// env: process.env
// });
// });
// /**
// * Scoped Actions
// *
// * This are for long running remote function
// * This allow also to res.emit logs to see the progress
// *
// **/
// var spawn = require('child_process').spawn;
// pmx.scopedAction('lsof cmd', function(options, res) {
// var child = spawn('lsof', []);
// child.stdout.on('data', function(chunk) {
// chunk.toString().split('\n').forEach(function(line) {
// /**
// * Here we send logs attached to this command
// */
// res.send(line);
// });
// });
// child.stdout.on('end', function(chunk) {
// /**
// * Then we emit end to finalize the function
// */
// res.end('end');
// });
// });
// });
const mConfig = pmx.initModule();
const mess = messenger(mConfig);
pm2.launchBus(function(err, bus) {
bus.on('process:event', (data) => {
mess.send({type: 'EVENT', data});
});
bus.on('log:err',(data)=> {
mess.send({type: 'LOG_ERROR', data});
})
});