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

service-metrics

v0.1.13

Published

The 'service-metrics' gather metric information about the running process.

Downloads

4

Readme

node-service-metrics

The 'service-metrics' gather metric information about the running process.

BEWARE, because of usage this module does not work well on Windows: your node-gyp needs to properly installed (see here).

Features

  • gather interval can be configured
  • gathered metrics are customisable through an easy API
  • Tasks can be set to be executed at the end of each interval

Take a look to the TODO if you want to help towards the next steps.

Usage

Node Dependencies

Add following line to your project dependencies

"service-metrics": "0.1.x",

then hit

npm install

Require module

var metrics = require('service-metrics');

configure

You can pass an options object as you require the library:

var metrics = require('service-metrics')(options);

Available Options

  • disable_cpu_metrics (boolean): library will not return any information about cpu usage (default: false).
  • disable_memory_metrics (boolean): library will not return any information about memory usage (default: false).
  • interval (number): metrics report interval time in milliseconds (default: 5000)

API

set([persistent-]name [, simple_counter])

Sets a custom metric. Two types of custom metrics are avalaible: the "simple counter" an integer value which gets incremented by one and the "value collection" which gets incremented by custom values and returns an object with the total value, the count of provided values in the cycle, the max, average and min value.

Parameters

  • [persistent-]name (string): the name of the metric. If prefix "persistent-" is used, the metric will not be reset at the end of the cycle
  • simple_counter (boolean): the type of the metric (default is true)

Example

// simple counter
metrics.set('counter');

// simple counter that will not be reset
metrics.set('persistent-counter');

// value collection
metrics.set('collection', false);

// value collection that will not be reset
metrics.set('persistent-collection', false);

incr([persistent-]name [, value])

Increments a custom metric.

Parameters

  • [persistent-]name (string): the name of the metric
  • value (number): the numeric value to be added (only for collection type)

Example

// simple counter gets incremented by +1
metrics.incr('counter');

// value collection gets new element: 23
metrics.incr('collection', 23);

exists(name)

Checks if the specified metric exists and return a boolean.

Parameters

  • name (string): the name of the metric

Example

// returns true
metrics.exists('counter');

// returns false
metrics.exists('doesNotExist');

addTask(name, task)

Defines a task to be executed at the end of each cycle. The task gets the actual metric object as argument.

Parameters

  • name (string): the name of the task
  • task (function): a custom function taking metrics as argument

Example

// show the metrics
metrics.addTask('log', console.log);

// custom task
metrics.addTask('custom', function (metrics) {
  console.log('Show actual metrics:');
  console.log(metrics);

  /* do something */
});

setInterval(milliseconds)

Defines the cycle interval within the range of one second to two minutes.

Parameter

  • milliseconds (number): value in the range 1000 to 120000

Example

// set the cycle interval to 3 seconds
metrics.setInterval(3000);