-
Notifications
You must be signed in to change notification settings - Fork 375
/
nodeInfo.ts
69 lines (60 loc) · 2.01 KB
/
nodeInfo.ts
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
/*!
* Pomelo -- consoleModule nodeInfo processInfo
* Copyright(c) 2012 fantasyni <fantasyni@163.com>
* MIT Licensed
*/
import * as monitor from 'pinus-monitor';
import { getLogger } from 'pinus-logger';import { IModule, ModuleType, MonitorCallback, MasterCallback } from '../consoleService';
import { MonitorAgent } from '../monitor/monitorAgent';
import { MasterAgent } from '../master/masterAgent';
import { PsParam } from 'pinus-monitor/dist/lib/processMonitor';
let logger = getLogger('pinus-admin', __filename);
let DEFAULT_INTERVAL = 5 * 60; // in second
let DEFAULT_DELAY = 10; // in second
export class NodeInfoModule implements IModule
{
type: ModuleType;
interval: number;
delay: number;
static moduleId = 'nodeInfo';
constructor(opts ?: {type?:ModuleType , interval?:number,delay?:number})
{
opts = opts || {};
this.type = opts.type || ModuleType.pull;
this.interval = opts.interval || DEFAULT_INTERVAL;
this.delay = opts.delay || DEFAULT_DELAY;
};
monitorHandler(agent : MonitorAgent, msg : any, cb : MonitorCallback)
{
let serverId = agent.id;
let pid = process.pid;
let params : PsParam= {
serverId: serverId,
pid: String(pid)
};
monitor.psmonitor.getPsInfo(params, function (err : Error, data : any)
{
agent.notify(NodeInfoModule.moduleId, { serverId: agent.id, body: data });
});
};
masterHandler(agent : MasterAgent, msg : any, cb : MasterCallback)
{
if (!msg)
{
agent.notifyAll(NodeInfoModule.moduleId);
return;
}
let body = msg.body;
let data = agent.get(NodeInfoModule.moduleId);
if (!data)
{
data = {};
agent.set(NodeInfoModule.moduleId, data);
}
data[msg.serverId] = body;
};
clientHandler(agent : MasterAgent, msg : any, cb : MasterCallback)
{
cb(null, agent.get(NodeInfoModule.moduleId) || {});
};
}