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

@uc-engg/mycroft

v1.0.0

Published

Client for monitoring

Downloads

6

Readme

Monitoring Client for NodeJS

  • Easy to create store where user can measure custom metrics.
  • Default metrics of node can be measured
  • Default labels can be set for all metrics
  • Supported custom metrics : Counter, Gauge and Histogram

Functions

  • createStore :

    • Used to create store which is further used to register custom metrics
    • Params
      • store name
      • defaultLabels : labels that are added to every metrics
      • isCollectNodeMetrics : to add node server metrics to given store
  • registerMetric :

    • Used to register metric with given store
    • Params : store name for given metric and metric properties
  • exportMetrics :

    • Used to get all the metrics in prometheus exposition format with contentType
    • Params : store name for which metrics are required

Usage

  • Create store (with default labels and node metrics)

    Mycroft.createStore({
      storeName: 'store-name',
      defaultLabels: defaultLabels,
      isCollectNodeMetrics: true
    });
  • Register custom counter metric for a give store

    Mycroft.registerMetric.counter('store_1', {  
      name: 'counter-metric', 
      labelNames: ['label_1'], 
      help: 'help message' 
    });
  • Measure custom metric for a given store

    Mycroft.incMetric('store_1', 'counter_metric', {
      label_1: 'label_1'
    });
  • Export metrics for a given store

    Mycroft.exportMetrics('store_1');

    returns

    {
      metrics : 'all metrics in prometheus exposition format'
      contentType: 'content type information'
    }
      

Instrumenting

Three types of metric are offered: Counter, Gauge and Histogram.

Counter

Use it to monitor metrics which gets incremented by only one and further analysis can be performed based on the value. Example => number of errors occurred for http service request

Mycroft.registerMetric.counter('store_1', {  
  name: 'http_request_error_metric', 
  labelNames: ['service', 'route', 'error_type'], 
  help: 'Count of errors' 
});

Mycroft.incMetric('store_1', 'http_request_error_metric', {
  service: 'service_1',
  route: '/functionCall',
  error_type: 'null pointer exception'
});

Gauge

Use it to monitor metrics which can vary at any time. Example => how much time it took to complete a request. If you want the granular details like 95% or 99% percentile use Histogram.

Mycroft.registerMetric.gauge('store_1', {  
  name: 'http_request_lag_metric', 
  labelNames: ['service', 'route'], 
  help: 'Time took to complete service in ms' 
});

Mycroft.setMetric('store_1', 'http_request_lag_duration_millisecond', {
  service: 'service_1',
  route: '/functionCall'
}, 1000);

Histogram

Use it to track the size and number of events in buckets. This allows for aggregative calculation of quantiles. Caution : Using histogram can make the cardinality very high as buckets are stored as one label in metric itself.

Mycroft.registerMetric.histogram('store_1', {  
  name: 'http_request_lag_metric', 
  labelNames: ['service', 'route'], 
  help: 'Time took to complete service in ms',
  buckets: [50, 100, 200, 400, 600, 1000, 5000, 10000, 30000, 60000] 
});

Mycroft.setMetric('store_1', 'http_request_lag_duration_millisecond', {
  service: 'service_1',
  route: '/functionCall'
}, 1000);