Coder Social home page Coder Social logo

Comments (2)

amanthegreatone avatar amanthegreatone commented on June 26, 2024

i have tried using internal node tools to get similar metrics. any comments are welcome. i did not add gc yet but it can be added in a similar manner.

  // 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);

i am using statsd as the transport client to gauge metrics to my influxdb via telegraf and then graph it using grafana.

from appmetrics.

jloveridge avatar jloveridge commented on June 26, 2024

Near as I can tell no, it isn't being maintained.

from appmetrics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.