describe("Test utils.getNodeID", () => { let os = require("os"); it("should give the computer hostname", () => { expect(utils.getNodeID()).toBe(os.hostname().toLowerCase() + "-" + process.pid); }); });
const getOsInfo = () => { return { uptime: os.uptime(), type: os.type(), release: os.release(), hostname: os.hostname(), arch: os.arch(), platform: os.platform(), user: getUserInfo() }; }
/** * Get default NodeID (computerName) * * @returns */ getNodeID() { return os.hostname().toLowerCase() + "-" + process.pid; }
/** * Creates an instance of DatadogLogger. * @param {Object} opts * @memberof DatadogLogger */ constructor(opts) { super(opts); this.opts = _.defaultsDeep(this.opts, { url: "https://http-intake.logs.datadoghq.com/v1/input/", apiKey: process.env.DATADOG_API_KEY, ddSource: "moleculer", env: undefined, hostname: os.hostname(), objectPrinter: null, interval: 10 * 1000 }); this.queue = []; this.timer = null; if (!this.opts.apiKey) throw new MoleculerError("Datadog API key is missing. Set DATADOG_API_KEY environment variable."); }
/** * Create local node with local information * * @returns * @memberof NodeCatalog */ createLocalNode() { const node = new Node(this.broker.nodeID); node.local = true; node.ipList = getIpList(); node.instanceID = this.broker.instanceID; node.hostname = os.hostname(); node.client = { type: "nodejs", version: this.broker.MOLECULER_VERSION, langVersion: process.version }; node.metadata = this.broker.metadata; node.seq = 1; this.add(node.id, node); this.localNode = node; return node; }
it("should return node list", () => { const localNode = broker.registry.nodes.localNode; return broker.call("$node.list").then(res => { expect(res).toEqual([{ "available": true, "client": { "langVersion": process.version, "type": "nodejs", "version": broker.MOLECULER_VERSION }, "config": {}, "cpu": null, "cpuSeq": null, "id": "node-master", "instanceID": localNode.instanceID, "ipList": localNode.ipList, "hostname": hostname(), "lastHeartbeatTime": localNode.lastHeartbeatTime, "offlineSince": null, "port": null, "seq": localNode.seq, "local": true, "metadata": { a: 5 }, "udpAddress": null }]); }); });
hostname: os.hostname(), type: os.type(), platform: os.platform(),
/** * Constructor of DatadogReporters * @param {Object} opts * @memberof DatadogReporter */ constructor(opts) { super(opts); this.opts = _.defaultsDeep(this.opts, { host: os.hostname(), baseUrl: BASE_URL, apiVersion: "v1", path: "/series", apiKey: process.env.DATADOG_API_KEY, //appKey: process.env.DATADOG_APP_KEY, defaultLabels: (registry) => ({ namespace: registry.broker.namespace, nodeID: registry.broker.nodeID }), interval: 10 }); if (!this.opts.apiKey) throw new MoleculerError("Datadog API key is missing. Set DATADOG_API_KEY environment variable."); }
test('bindings formatter', async ({ match }) => { const stream = sink() const logger = pino({ formatters: { bindings (bindings) { return { process: { pid: bindings.pid }, host: { name: bindings.hostname } } } } }, stream) const o = once(stream, 'data') logger.info('hello world') match(await o, { process: { pid: process.pid }, host: { name: hostname() } }) })
test('asynchronous logging', async ({ is, teardown }) => { const now = Date.now const hostname = os.hostname const proc = process global.process = {
ddSource: "moleculer", env: undefined, hostname: os.hostname(), objectPrinter: null, interval: 10 * 1000
test('sync false with child', async ({ is, teardown }) => { const now = Date.now const hostname = os.hostname const proc = process global.process = {
hostname: os.hostname(), type: os.type(), platform: os.platform(),