forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeEnvironmentInfoCollector.ts
More file actions
57 lines (50 loc) · 1.71 KB
/
NodeEnvironmentInfoCollector.ts
File metadata and controls
57 lines (50 loc) · 1.71 KB
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
import { IEnvironmentInfo } from '../models/IEnvironmentInfo';
import { IEnvironmentInfoCollector } from './IEnvironmentInfoCollector';
import { EventPluginContext } from '../plugins/EventPluginContext';
import os = require('os');
export class NodeEnvironmentInfoCollector implements IEnvironmentInfoCollector {
public getEnvironmentInfo(context:EventPluginContext): IEnvironmentInfo {
function getIpAddresses():string {
var ips:string[] = [];
var interfaces = os.networkInterfaces();
Object.keys(interfaces).forEach((name) => {
interfaces[name].forEach((iface:any) => {
if ('IPv4' === iface.family && !iface.internal) {
ips.push(iface.address);
}
});
});
return ips.join(', ');
}
if (!os) {
return null;
}
var environmentInfo: IEnvironmentInfo = {
processor_count: os.cpus().length,
total_physical_memory: os.totalmem(),
available_physical_memory: os.freemem(),
command_line: process.argv.join(' '),
process_name: (process.title || '').replace(/[\uE000-\uF8FF]/g, ''),
process_id: process.pid + '',
process_memory_size: process.memoryUsage().heapTotal,
//thread_id: '',
architecture: os.arch(),
o_s_name: os.type(),
o_s_version: os.release(),
ip_address: getIpAddresses(),
machine_name: os.hostname(),
//install_id: '',
runtime_version: process.version,
data: {
loadavg: os.loadavg(),
platform: os.platform(),
tmpdir: os.tmpdir(),
uptime: os.uptime()
}
};
if ((<any>os).endianness) {
environmentInfo.data.endianness = (<any>os).endianness();
}
return environmentInfo;
}
}