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

fastify-opencensus

v0.0.2

Published

Opencensus metrics exporter for Fastify

Downloads

5

Readme

fastify-opencensus

Node version Downloads Count Build Status Known Vulnerabilities Coverage Status License

Metrics collector for Fastify based on Opencensus .

This module is inspired and based on the fastify-metrics plugin.

This plugin adds 3 http metrics for your routes:

  • Requests duration distribution
  • Requests duration summary
  • Requests count

ToC

Fastify support

  • v0.x.x - will support >= fastify-2.0.0

Installation

npm i fastify-opencensus --save

Back to top

Features and requirements

  • Collects default server metrics (see opencensus-default-metrics);
  • Collects route response timings
  • By default, metrics info are collected into the global instance of opencensus required by this package. If you want to use another opencensus version, you have to pass in this instance using the stats options field.

  • Requires fastify >=2.0.0.
  • Node.js >=8.9.0.

Back to top

Usage

Add it to your project like regular fastify plugin. Use register method and pass options to it.

const fastify = require('fastify');
const app = fastify();

const metricsPlugin = require('fastify-opencensus');
app.register(metricsPlugin, { interval: 3000 });

It also exports opencensus stats instance to fastify instance fastify.opencensus.client which you may use it in your routes.

See example folder for other examples.

Back to top

Plugin options

| parameter | type | description | default | | ---------------------- | ------------------------ | ------------------------------------------------------------------------------- | ------------ | | enableDefaultMetrics | Boolean | Enables collection of node default metrics. | true | | enableStats | Boolean | Enables collection of fastify metrics. | true | | stats | Object | Custom opencensus metrics instance. | undefined | | metricsExporter | Array | Array of Opencensus metrics exporter | undefined | | groupStatusCodes | Boolean | Groups status codes (e.g. 2XX) if true | false | | pluginName | String | Change name which you'll use to access opencensus registry instance in fastify. | opencensus | | interval | Number | Default metrics collection interval in ms. | 5000 | | blacklist | String, RegExp, String[] | Skip metrics collection for blacklisted routes | undefined | | prefix | String | Custom default metrics prefix. | "" | | metrics | Object | Allows override default metrics config. See section below. | {} |

Metrics details

You may override default metrics settings. You may provide overrides for three metrics tracking http request durations, count and sum (labelNames cannot be overriden). Default values:

{
  distribution: {
    name: 'http_request_duration_seconds',
    desc: 'request duration in seconds',
    labelNames: ['status_code', 'method', 'route'],
    buckets: [0.05, 0.1, 0.5, 1, 3, 5, 10],
  },
  sum: {
    name: 'http_sum_request_duration_seconds',
    desc: 'Sum of durations of http requests',
    labelNames: ['status_code', 'method', 'route']
  },
  count: {
    name: 'http_request_count',
    desc: 'Counter of http requests',
    labelNames: ['status_code', 'method', 'route']
  },
}

Override should look like:

const fastify = require('fastify');
const app = fastify();
const metricsPlugin = require('fastify-metrics');

app.register(metricsPlugin, {metrics: {
  distribution: {
    name: 'my_custom_http_request_duration_seconds',
    buckets: [0.1, 0.5, 1, 3, 5],
  },
  sum: {
    desc: 'custom request duration in seconds summary help'
  },
});

Back to top

HTTP routes metrics

The following table shows what metrics will be available in Prometheus. Note suffixes like _bucket, _sum, _count are added automatically.

| metric | labels | description | | ----------------------------------- | -------------------------------- | ---------------------------- | | http_request_count | method, route, status_code | Requests total count | | http_request_duration_seconds | method, route, status_code | Requests durations by bucket | | http_sum_request_duration_seconds | method, route, status_code | Requests duration sum |

Back to top

Docs

See docs.

Back to top

Changelog

See changelog.

Back to top

See also

Back to top

License

Licensed under MIT.

Back to top