npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

abacus-perf

v1.1.5

Published

Collect real time function call perf and reliability metrics

Downloads

119

Readme

abacus-perf

Collect real time function call perf and reliability metrics.

This module provides a way to collect function call performance and reliability metrics and compute real time stats on these metrics. The stats are computed using rolling windows of call successes, failures, timeouts, circuit breaker rejections and latencies.

require('abacus-perf')

perf.report(...) && perf.healthy()

Collects real time function call performace and reliability metrics, computes real time stats on these metrics. The stats are computed using rolling windows of call successes, failures, timeouts, rejections and latencies.

The api this library provites is the following:

  • perf.report(name, time, latency, err, timeout, reject, circuit)
    • name is the name of the metric for which you want to report status (required)
    • time is the time of the occurance (not mandatory)
    • latency (not mandatory)
    • err Object of type error. If provided, perf will treat this report as failing
    • timeout If provided, perf will treat this report as failing
    • reject If provided, perf will treat this report as failing
    • circuit (not mandatory)

A little demo of how can you report custom metrics:

const perf = require('abacus-perf');
const moment = require('abacus-moment');
const now = moment.now();

// Report a healthy metric named 'my.custom.metric'
perf.report('my.custom.metric', now);

perf.healthy();                   // True

// Report Error 1 second after the success
perf.report('my.custom.metric', now + 1000, undefined, new Error());

perf.healthy();                   // False

The second healthy check is negative, since we have sent one positive and one negative report for our metric. Which is 50% failure rate in the last 10 seconds, and the perf module by default reports unhealthy if we have more than 5% failure. You can pass another value to perf.healthy() if you want to change the treshold:

perf.healthy(51);                 // True

Note that the function healthy will calculate the % faliure based on the metrics recieved in the last 10 seconds (by default) from the last recieved metric.

It will reroll everytime you sent new metric.

// Send successfull metric 30 seconds later
perf.report('my.custom.metric', now + 30000);
 
perf.healthy();                   // True

Now we are healthy because in the last 10 seconds we have only one report - successfull => 0% faliure.

perf.rollCounts(...)

This is the function that rerolls all the buckets on call of perf.report(...) and descides which make it to the current time window and which are out of date (droped).

Relies on perf.roll(...) which implements the rolling time window algorithm.

perf.roll(...)

Convert a list of buckets to a list of buckets in a rolling time window. Filter out the buckets that are out of the time window, and create a new bucket if necessary for the given time.

Configuration of tracked time window

By default perf module keeps track on reported metrics within the last 10 seconds. This befaviour could be changed by providing additional configuration using PERF_COUNT_SAMPLE enviornment variable. The enviornment variable has the following format

PERF_COUNT_SAMPLE = '{ "granularity": "seconds", "size": 10 }'

The attributes have the following semantics

  • granularity - specifies the time dimension that is used to define the time window size. Accepted values are seconds, minutes and hours.
  • size - specifies the size of the time window. Accepted values are valid integers