Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings emitted on Node 14 #646

Open
jloveridge opened this issue Sep 15, 2020 · 7 comments
Open

Warnings emitted on Node 14 #646

jloveridge opened this issue Sep 15, 2020 · 7 comments

Comments

@jloveridge
Copy link

When appmetrics is required on node 14 multiple messages are emitted which state:

(node:74412) Warning: Accessing non-existent property '__ddProbeAttached__' of module exports inside circular dependency

The following simple script can reproduce the issue:

require('appmetrics');
@kams2160
Copy link

Same here! Node v14.15.2

Warning: Accessing non-existent property '__ddProbeAttached__' of module exports inside circular dependency

@dnascimb
Copy link

Same here, Node v14.16.1

@jokeyrhyme
Copy link

jokeyrhyme commented Apr 20, 2021

It's internal code unfortunately (so I cannot share it at this time), but my team managed to replace the appmetrics module completely in Node.js 14.x using methods available in the standard library

@realjasonbourne
Copy link

Any update on this issue?

@amanthegreatone
Copy link

@jokeyrhyme can you explain how you removed this package and got the required metrics?

@jokeyrhyme
Copy link

jokeyrhyme commented Aug 30, 2022

@amanthegreatone
Copy link

this is what i could come up with

  // timer start time
  let trackingTime = process.hrtime();

  // last cpu usage to get difference from current cpu usage (the diff will give usage over timer period)
  let lastCpuUsage = process.cpuUsage();

  // histogram for event loop monitoring
  const histogram = perf_hooks.monitorEventLoopDelay();
  histogram.enable();

  // monitor cpu, memory, event loop
  const monitor = () => {

    // end time for the timer (diff from start time by passing as arg)
    // hrtime gives nanosecond resolution ([0] seconds, [1] remaining nanoseconds)
    const delta = process.hrtime(trackingTime);
    const nanosec = delta[0] * 1e9 + delta[1];

    // get cpu usage (user and system)
    const cpuUsage = process.cpuUsage();

    // diff from last cpu usage to get % usage over timer interval
    const userUsage = ((cpuUsage.user - lastCpuUsage.user) / nanosec) * 1000;
    const systemUsage = ((cpuUsage.system - lastCpuUsage.system) / nanosec) * 1000;
    transportClient.gauge('cpu.process', userUsage);
    transportClient.gauge('cpu.system', systemUsage);

    // update last cpu usage for next timer cycle
    lastCpuUsage = cpuUsage;

    // get process memory usage
    // Resident Set Size, is the amount of space occupied in the main memory device
    // (that is a subset of the total allocated memory) for the process
    // including all C++ and JavaScript objects and code
    const memoryUsage = process.memoryUsage();
    transportClient.gauge('memory.process.physical', memoryUsage.rss);

    transportClient.gauge('eventloop.latency.min', histogram.min / 1e6);
    transportClient.gauge('eventloop.latency.max', histogram.max / 1e6);
    transportClient.gauge('eventloop.latency.avg', histogram.mean / 1e6);

    // reset histogram to start new cycle
    histogram.reset();

    // update timer time for getting diff for next cycle
    trackingTime = process.hrtime();
  };

  // collect process metrics every 5 seconds
  setInterval(monitor, 5000);

any comments are welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants