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

@telemetry-js/collector-incidental

v0.2.2

Published

Record incidental values (rather than on a fixed schedule)

Downloads

4

Readme

collector-incidental

Record incidental values (rather than on a fixed schedule). Meant to be combined with other plugins in a continuous Telemetry Task; if you merely want to publish metrics once, instead use a publisher plugin by itself.
A telemetry plugin.

npm status node Test JavaScript Style Guide

Table of Contents

Usage

const telemetry = require('@telemetry-js/telemetry')()
const incidental = require('@telemetry-js/collector-incidental')
const myCount = incidental.single('my.count', { unit: 'count' })

telemetry.task()
  .collect(myCount)
  .schedule(..)
  .publish(..)

// Elsewhere in your app
myCount.record(1000)
myCount.record(500)

This will publish every recorded value (use sparingly). You will also need a schedule plugin, otherwise the metrics stay queued in collector-incidental and will never be published.

Summarize

If you're calling record many times within short time periods, either consider using the rate variant of the collector-counter plugin, if it is a rate metric you need, or use incidental.summary():

const myCount = incidental.summary('my.count', { unit: 'count' })

telemetry.task()
  .collect(myCount)
  .schedule(..)
  .publish(..)

// Usage is the same
myCount.record(1000)
myCount.record(500)

This will publish one summary at every ping, summarizing the values you recorded between two pings. Pings typically happen every 5 minutes but it depends on your configured schedule.

Reduce

Instead of the summary collector (which collects min, max, sum ánd count), you can also use a "reducer", one of min, max, sum or count. Taking max as an example:

const myCount = incidental.max('my.count.max', { unit: 'count' })

telemetry.task()
  .collect(myCount)
  .schedule(..)
  .publish(..)

// Usage is the same
myCount.record(1000)
myCount.record(500)

This will publish one single value at every ping, reducing the values you recorded between two pings. Here, the first ping will lead to a metric being emitted with value 1000 (the maximum of 500 and 1000). Note that the internal state of the maximum value resets after a ping.

The emitted metrics get a relevant .statistic property which publishers like publisher-appoptics use to control server-side rollup behavior (when it's aggregating values into a lower resolution a.k.a. higher interval).

API

plugin = incidental.single(metricName, options)

Emits every value recorded between pings. It is recommended to end the metric name with the unit, e.g. batch_size.count, size.bytes.

Options:

  • unit: string, required
  • Other options are passed as-is to metric.

plugin = incidental.summary(metricName, options)

Emits a summary of values recorded between pings. Same arguments as incidental.single().

plugin = incidental.min(metricName, options)

Emits the minimum of values recorded between pings. Same arguments as incidental.single().

plugin = incidental.max(metricName, options)

Emits the maximum of values recorded between pings. Same arguments as incidental.single().

plugin = incidental.sum(metricName, options)

Emits the sum of values recorded between pings. Same arguments as incidental.single().

plugin = incidental.count(metricName, options)

Emits the count of values recorded between pings. Same arguments as incidental.single(), except that the unit option defaults to 'count' and does not need to be specified.

Known issue: if no values were recorded, it should emit a metric with value 0 (in order to differentiate that situation from missing metrics) but it doesn't.

plugin

This is a function to be passed to a Telemetry Task. Can be used by multiple tasks, sharing state:

telemetry.task().collect(plugin)
telemetry.task().collect(plugin)

plugin.record(value)

Record a value (as well as the current time when using single; summaries and reducers use ping time). Value must be a number.

Install

With npm do:

npm install @telemetry-js/collector-incidental

Acknowledgements

This project is kindly sponsored by Reason Cybersecurity Ltd.

reason logo

License

MIT © Vincent Weevers