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-events-quantify

v2.0.0

Published

Helper for creating telemetry events from Quantify metrics.

Downloads

5

Readme

telemetry-events-quantify

Stability: 1 - Experimental

NPM version

Helper for creating and emitting telemetry events for Quantify metrics.

Contributors

@lpearson05, @tristanls

Contents

Installation

npm install telemetry-events-quantify

Usage

To run the below example run:

npm run readme
"use strict";

const events = require("events");
const pkg = require("../package.json");
const Quantify = require("quantify");
const QuantifyTelemetryEvents = require("../index.js");
const TelemetryEvents = require("telemetry-events");

const emitter = new events.EventEmitter();
const metricsRegistry = new Quantify();
const telemetryEvents = new TelemetryEvents(
    {
        emitter,
        package: pkg
    }
);
const quantifyTelemetryEmitter = new QuantifyTelemetryEvents(
    {
        telemetry: telemetryEvents
    }
);

emitter.on("telemetry", event => console.dir(event));

// create some metrics using Quantify
metricsRegistry.counter("errors", "Err",
    {
        server: "foo"
    }
);
metricsRegistry.gauge("cpuLoad", "Load");
metricsRegistry.histogram("searchResultsReturned",
    {
        measureUnit: "Result",
        sampleSizeUnit:  "Req"
    }
);
metricsRegistry.meter("requests",
    {
        rateUnit: "Req/s",
        updateCountUnit: "Req"
    }
);
metricsRegistry.timer("requestLatency",
    {
        measureUnit: "ms",
        rateUnit: "Req/s",
        sampleSizeUnit: "Req"
    },
    {
        some: "other_tag",
        and: "more_metadata"
    }
);

// get the metrics we want to report
const metrics = metricsRegistry.getMetrics();

quantifyTelemetryEmitter.counter("errors", metrics.counters["errors"]);
quantifyTelemetryEmitter.gauge("cpuLoad", metrics.gauges["cpuLoad"]);
quantifyTelemetryEmitter.histogram("searchResultsReturned", metrics.histograms["searchResultsReturned"]);
quantifyTelemetryEmitter.meter("requests", metrics.meters["requests"]);
quantifyTelemetryEmitter.timer("requestLatency", metrics.timers["requestLatency"]);

// ...or just call this
quantifyTelemetryEmitter.metrics(metrics);

Tests

npm test

Documentation

QuantifyTelemetryEvents

Public API

new QuantifyTelemetryEvents(config)

  • config: Object
    • telemetry: TelemetryEvents Instance of TelemetryEvents to use for processing.

Creates a new QuantifyTelemetryEvents instance.

telemetry.counter(name, c)

  • name: String Name of the metric to be used for event.name property.
  • unit: String Unit to be used for the metric event.unit property.
  • c: Object Quantify calculated counter to process.
  • Return: Object The event.

Helper to create "metric" event with 'target_type' of "counter". If emitter was specified in configuration, calling this helper will also emit this event. The created event object will have the following properties (in addition to those added by TelemeteryEvents):

{
    type: 'metric',
    name: <name>,
    target_type: 'counter',
    unit: <c.unit>,
    value: <c.value>
}

If c has metadata, properties of metadata will be included with or override the above template.

telemetry.gauge(name, g)

  • name: String Name of the metric to be used for event.name property.
  • unit: String Unit to be used for the metric event.unit property.
  • g: Object Quantify calculated gauge to process.
  • Return: Object The event.

Helper to create "metric" event with 'target_type' of "gauge". If emitter was specified in configuration, calling this helper will also emit this event. The created event object will have the following properties (in addition to those added by TelemeteryEvents):

{
    type: 'metric',
    name: <name>,
    target_type: 'gauge',
    unit: <g.unit>,
    value: <g.value>
}

If g has metadata, properties of metadata will be included with or override the above template.

telemetry.histogram(name, h)

  • name: String Name of the metric to be used for event.name property.
  • h: Object Quantify calculated histogram to process.
  • Return: Object The event.

Helper to create "metric" event with 'target_type' of "histogram". If emitter was specified in configuration, calling this helper will also emit this event. The created event object will have the following properties (in addition to those added by TelemeteryEvents):

{
    type: 'metric',
    name: <name>,
    target_type: 'histogram',
    value: {
        measureUnit: <h.measureUnit>,
        sampleSize: <h.sampleSize>,
        sampleSizeUnit: <h.sampleSizeUnit>,
        max: <h.max>,
        mean: <h.mean>,
        median: <h.median>,
        min: <h.min>,
        percentile75: <h.percentile75>,
        percentile95: <h.percentile95>,
        percentile98: <h.percentile98>,
        percentile99: <h.percentile99>,
        percentile999: <h.percentile999>,
        standardDeviation: <h.standardDeviation>
    }
}

If h has metadata, properties of metadata will be included with or override the above template.

telemetry.meter(name, m)

  • name: String Name of the metric to be used for event.name property.
  • m: Object Quantify calculated meter to process.
  • Return: Object The event.

Helper to create "metric" event with 'target_type' of "meter". If emitter was specified in configuration, calling this helper will also emit this event. The created event object will have the following properties (in addition to those added by TelemeteryEvents):

{
    type: 'metric',
    name: <name>,
    target_type: 'meter',
    value: {
        rateUnit: <m.rateUnit>,
        updateCount: <m.updateCount>,
        updateCountUnit: <m.updateCountUnit>,
        meanRate: <m.meanRate>,
        oneMinuteRate: <m.oneMinuteRate>,
        fiveMinuteRate: <m.fiveMinuteRate>,
        fifteenMinuteRate: <m.fifteenMinuteRate>
    }
}

If m has metadata, properties of metadata will be included with or override the above template.

telemetry.metrics(metrics)

  • metrics: Object Result of Quantify.getMetrics([filters]).
  • Return Array Array of events.

Helper to create "metric" events for all target types. If emitter was specified in configuration, calling this helper will also emit these events.

telemetry.timer(name, t)

  • name: String Name of the metric to be used for event.name property.
  • t: Object Quantify calculated timer to process.
  • Return: Object The event.

Helper to create "metric" event with 'target_type' of "timer". If emitter was specified in configuration, calling this helper will also emit this event. The created event object will have the following properties (in addition to those added by TelemeteryEvents):

{
    type: 'metric',
    name: <name>,
    target_type: 'timer',
    value: {
        measureUnit: <t.measureUnit>,
        rateUnit: <t.rateUnit>,
        sampleSize: <t.sampleSize>,
        sampleSizeUnit: <t.sampleSizeUnit>,
        updateCount: <t.sampleSize>,
        meanRate: <t.meanRate>,
        oneMinuteRate: <t.oneMinuteRate>,
        fiveMinuteRate: <t.fiveMinuteRate>,
        fifteenMinuteRate: <t.fifteenMinuteRate>
        max: <t.max>,
        mean: <t.mean>,
        median: <t.median>,
        min: <t.min>,
        percentile75: <t.percentile75>,
        percentile95: <t.percentile95>,
        percentile98: <t.percentile98>,
        percentile99: <t.percentile99>,
        percentile999: <t.percentile999>,
        standardDeviation: <t.standardDeviation>
    }
}

If t has metadata, properties of metadata will be included with or override the above template.