UNPKG

@exceptionless/node

Version:
75 lines 2.77 kB
import { argv, memoryUsage, pid, title, version } from "process"; import { arch, cpus, endianness, freemem, hostname, loadavg, networkInterfaces, platform, release, tmpdir, totalmem, type, uptime } from "os"; import { KnownEventDataKeys } from "@exceptionless/core"; export class NodeEnvironmentInfoPlugin { priority = 80; name = "NodeEnvironmentInfoPlugin"; _environmentInfo; run(context) { if (context.event.data && !context.event.data[KnownEventDataKeys.EnvironmentInfo]) { const info = this.getEnvironmentInfo(context); if (info) { context.event.data[KnownEventDataKeys.EnvironmentInfo] = info; } } return Promise.resolve(); } getEnvironmentInfo(context) { function getIpAddresses() { const ips = []; for (const ni of Object.values(networkInterfaces())) { for (const network of ni || []) { if (!network.internal && "IPv4" === network.family) { ips.push(network.address); } } } return ips.join(", "); } function populateMemoryAndUptimeInfo(ei) { ei.process_memory_size = memoryUsage().heapTotal; ei.total_physical_memory = totalmem(); ei.available_physical_memory = freemem(); ei.data.loadavg = loadavg(); ei.data.uptime = uptime(); } if (!cpus) { return; } if (this._environmentInfo) { populateMemoryAndUptimeInfo(this._environmentInfo); return this._environmentInfo; } const info = { processor_count: cpus().length, command_line: argv.join(" "), process_name: (title || "").replace(/[\uE000-\uF8FF]/g, ""), process_id: pid + "", process_memory_size: memoryUsage().heapTotal, // thread_id: "", architecture: arch(), o_s_name: type(), o_s_version: release(), // install_id: "", runtime_version: version, data: { platform: platform(), tmpdir: tmpdir() } }; const config = context.client.config; if (config.includeMachineName) { info.machine_name = hostname(); } if (config.includeIpAddress) { info.ip_address = getIpAddresses(); } if (endianness) { info.data.endianness = endianness(); } populateMemoryAndUptimeInfo(info); this._environmentInfo = info; return this._environmentInfo; } } //# sourceMappingURL=NodeEnvironmentInfoPlugin.js.map