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

@metrics/metric

v2.3.3

Published

The metric class definition which metric objects in the @metrics library is instansiated from

Downloads

7,765

Readme

@metrics/metric

The metric class definition which metric objects is instansiated from.

Dependencies GitHub Actions status Known Vulnerabilities

Installation

$ npm install @metrics/metric

Example

const Metric = require('@metrics/metric');

const metric = new Metric({
    name: 'unique_metric_name',
    description: 'Description of metric being collected',
    value: 10,
});

Description

This module is the metric class definition which metric objects is instansiated from.

All modules in the @metric family which exchange data over the stream API exchange this object type. This object definition is intended to be static over time so modules who depend on a module in the @metric family can rely on exchanging data over time.

This class definition is prefered over object literals when exchanging data over the stream API because it will guarantee that all properties are available on the object. All undefined properties will have a null value, making sure they are kept when serialized to JSON.

The metric object aims to be compatible with the Open Metrics initiative.

Constructor

Create a new Metric instance.

const Metric = require('@metrics/metric');
const metric = new Metric(options);

options (required)

An object literal reflecting the properties of this class. The following properties is required:

  • name - String - The name of the metric.
  • description - String - The description of the metric.

Each property value is validated and will throw if a property value is found to be invalid.

Properties

The instansiated object has the following properties:

name

The name of the metric.

  • Valid value: String in the range of [a-zA-Z_][a-zA-Z0-9_].
  • Value is immutable.
  • Is required.

description

A human readable description of the metric.

  • Valid value: String.
  • Value is immutable.
  • Is required.

value

The value of the metric.

  • Valid value: Integer or null.
  • Value is immutable.
  • Defaults to null.

type

A hint of what type of metric this is.

  • Valid value: Integer in the range of 0-7.
  • Value is immutable.
  • Defaults to 0.

Each numeric value reflect one of the following types:

  • 0 represents unknown.
  • 1 represents gauge.
  • 2 represents counter.
  • 3 represents state_set.
  • 4 represents info.
  • 5 represents cumulative histogram.
  • 6 represents gauge histogram.
  • 7 represents summary.

source

The source of the metric in terms of where it originated.

  • Valid value: String or null.
  • Value is mutable.
  • Defaults to null.

timestamp

A timestamp of when the metric was created.

  • Valid value: Double - epoc milliseconds.
  • Value is immutable.
  • Defaults to Date.now() / 1000.

labels

An Array of labeled values. Each item in the Array must be a Label object. Please see the Labels section for further info.

  • Valid value: Array of Label objects.
  • Value is immutable.
  • Defaults to an empty Array.

meta

Available to be used to hold any data. The input is not validated.

  • Valid value: any.
  • Value is immutable.
  • Default to null.

time

Is deprecated.

Label object

A Label object is a object literal which have the following properties:

name

The name of the label.

  • Valid value: String in the range of [a-zA-Z0-9_].
  • Is required.

value

The value of the label.

  • Valid value: Integer, String, Boolean or null.
  • Is required.