1 |
|
2 |
|
3 |
|
4 |
|
5 | var EventEmitter = require('events').EventEmitter;
|
6 | var _ = require('lodash');
|
7 |
|
8 | var application = require('./application');
|
9 | var properties = require('./properties');
|
10 | var logger = require('./logger')('hubiquitus:core:monitoring');
|
11 | var actors = require('./actors');
|
12 | var discovery = require('./discovery');
|
13 | var adapters = {
|
14 | inproc: require('./adapters/inproc'),
|
15 | remote: require('./adapters/remote')
|
16 | };
|
17 |
|
18 | exports.__proto__ = new EventEmitter();
|
19 | exports.setMaxListeners(0);
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | actors.on('actor added', function (aid, scope) {
|
26 | exports.emit('actor added', aid, scope);
|
27 | });
|
28 |
|
29 | actors.on('actor removed', function (aid, scope) {
|
30 | exports.emit('actor removed', aid, scope);
|
31 | });
|
32 |
|
33 | discovery.on('discovery started', function (aid) {
|
34 | exports.emit('discovery started', aid);
|
35 | });
|
36 |
|
37 | discovery.on('discovery stopped', function (aid) {
|
38 | exports.emit('discovery stopped', aid);
|
39 | });
|
40 |
|
41 | discovery.on('discovery', function (aid) {
|
42 | exports.emit('discovery', aid);
|
43 | });
|
44 |
|
45 | _.forEach(adapters, function (adapter) {
|
46 | adapter.on('req sent', function (req) {
|
47 | exports.emit('req sent', req);
|
48 | });
|
49 |
|
50 | adapter.on('req received', function (req) {
|
51 | exports.emit('req received', req);
|
52 | });
|
53 |
|
54 | adapter.on('res sent', function (res) {
|
55 | exports.emit('res sent', res);
|
56 | });
|
57 |
|
58 | adapter.on('res received', function (res) {
|
59 | exports.emit('res received', res);
|
60 | });
|
61 | });
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | exports.actors = function (scope) {
|
69 | return actors.all(scope);
|
70 | };
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | exports.discoveries = function () {
|
77 | return discovery.discoveries();
|
78 | };
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | application.addActor(properties.ID + '_ping', function (req) {
|
85 | logger.makeLog('trace', 'hub-51', 'ping', {req: req});
|
86 | req.reply();
|
87 | });
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | exports.pingContainer = function (cid, cb) {
|
95 | application.send(properties.ID, cid + '_ping', 'PING', properties.containerPingTimeout, function (err) {
|
96 | cb(err);
|
97 | });
|
98 | };
|