-
Notifications
You must be signed in to change notification settings - Fork 16
/
app.js
64 lines (56 loc) · 1.88 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
/* eslint-disable no-alert, no-console */
'use strict';
const pm2 = require('pm2');
const pmx = require('pmx');
const os = require('os');
const hostname = os.hostname();
const conf = pmx.initModule();
var Gelf = require('gelf');
var gelf = new Gelf({
graylogPort: conf.graylogPort,
graylogHostname: conf.graylogHostname,
connection: conf.connection,
maxChunkSizeWan: conf.maxChunkSizeWan,
maxChunkSizeLan: conf.maxChunkSizeLan
});
pm2.Client.launchBus(function(err, bus) {
if (err) return console.error('PM2 Loggly:', err);
console.log('PM2 GELF Connector: Bus connected, sending logs to ' + conf.graylogHostname + ':' + conf.graylogPort);
bus.on('log:out', function(log) {
if (log.process.name !== 'pm2-gelf') {
// console.log(log.process.name, log.data);
// Log to gelf
var message = {
'version': '1.1',
'host': hostname,
'timestamp': (log.at / 1000),
'short_message': log.data,
'level': 6,
'facility': log.process.name
};
gelf.emit('gelf.log', message);
}
});
bus.on('log:err', function(log) {
if (log.process.name !== 'pm2-gelf') {
// console.error(log.process.name, log.data);
// Log to gelf
var message = {
'version': '1.1',
'host': hostname,
'timestamp': (log.at / 1000),
'short_message': log.data,
'level': 3,
'facility': log.process.name
};
gelf.emit('gelf.log', message);
}
});
bus.on('reconnect attempt', function() {
console.log('PM2 GELF Connector: Bus reconnecting');
});
bus.on('close', function() {
console.log('PM2 GELF Connector: Bus closed');
pm2.disconnectBus();
});
});