forked from Franco-Poveda/pm2-amqp-logstash
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
65 lines (59 loc) · 1.49 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
const bunyan = require('bunyan');
const pm2 = require('pm2');
const pmx = require('pmx');
pmx.initModule({
widget: {
logo: 'http://semicomplete.com/presentations/logstash-monitorama-2013/images/elasticsearch.png',
theme: ['#141A1F', '#222222', '#3ff', '#3ff'],
el: {
probes: false,
actions: false
},
block: {
actions: false,
issues: false,
meta: false,
}
}
}, (err, conf) => {
if (err) {
console.log('error', err);
return;
}
const amqpStream = require('bunyan-logstash-amqp').createStream({
host: conf.amqpHost,
vhost: conf.amqpVhost || 'sandbox',
exchange: {
name: conf.amqpExchange,
routingKey: conf.amqpRoutingKey
},
login: conf.amqpUser,
password: conf.amqpPasswd
})
.on('connect', () => console.log("Connected to amqp [module]"))
.on('close', () => console.log("Closed connection to amqp"))
.on('error', console.log);
const log = bunyan.createLogger({
name: conf.logName,
streams: [{
level: conf.logLevel,
type: "raw",
stream: amqpStream
}],
level: conf.logLevel
});
pm2.connect(() => {
console.log('info', 'PM2: forwarding to amqp');
pm2.launchBus((err, bus) => {
bus.on('log:PM2', function (packet) {
log.debug(packet.data);
});
bus.on('log:out', function (packet) {
log.debug(packet.data);
});
bus.on('log:err', function (packet) {
log.error(packet.data);
});
});
});
});