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

artedi

v2.0.3

Published

a metric client library

Downloads

30

Readme

node-artedi: client library for metric collection

About

artedi is a Node.js library for measuring applications -- specifically, the services composing Triton and Manta.

Sample Usage

Here is a simple example usage of counters and histograms to expose metrics in the Prometheus v0.0.4 text format.

var artedi = require('artedi');

// collectors are the 'parent' collector.
var collector = artedi.createCollector();

// counters are a 'child' collector.
// This call is idempotent.
var counter = collector.counter({
    name: 'http_requests_completed',
    help: 'count of muskie http requests completed',
    labels: {
        zone: 'e5d3'
    }
});

// Add 1 to the counter with the labels 'method=getobject,code=200'.
counter.increment({
    method: 'getobject',
    code: '200'
});

collector.collect(artedi.FMT_PROM, function (err, metrics) {
    console.log(metrics);
    // Prints:
    // # HELP http_requests_completed count of muskie http requests completed
    // # TYPE http_requests_completed counter
    // http_requests_completed{zone="e5d3",method="getobject",code="200"} 1
});

var histogram = collector.histogram({
    name: 'http_request_latency_seconds',
    help: 'latency of muskie http requests',
    buckets: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]
});

// Observe a latency of 998ms for a 'putobjectdir' request.
histogram.observe(0.998, {
    method: 'putobjectdir'
});

// For each bucket, we get a count of the number of requests that fall
// below or at the latency upper-bound of the bucket.
// This output is defined by Prometheus.
collector.collect(artedi.FMT_PROM, function (err, metrics) {
    if (err) {
        throw new Error('could not collect metrics');
    }
    console.log(metrics);
    // Prints:
    // # HELP http_requests_completed count of muskie http requests completed
    // # TYPE http_requests_completed counter
    // http_requests_completed{method="getobject",code="200",zone="e5d3"} 1
    // # HELP http_request_latency_seconds latency of muskie http requests
    // # TYPE http_request_latency_seconds histogram
    // http_request_latency_seconds{method="putobjectdir",le="0.005"} 0
    // http_request_latency_seconds{method="putobjectdir",le="0.01"} 0
    // http_request_latency_seconds{method="putobjectdir",le="0.025"} 0
    // http_request_latency_seconds{method="putobjectdir",le="0.05"} 0
    // http_request_latency_seconds{method="putobjectdir",le="0.01"} 0
    // http_request_latency_seconds{method="putobjectdir",le="0.25"} 0
    // http_request_latency_seconds{method="putobjectdir",le="0.5"} 0
    // http_request_latency_seconds{method="putobjectdir",le="1"} 1
    // http_request_latency_seconds{method="putobjectdir",le="2.5"} 1
    // http_request_latency_seconds{method="putobjectdir",le="5"} 1
    // http_request_latency_seconds{method="putobjectdir",le="10"} 1
    // http_request_latency_seconds{le="+Inf",method="putobjectdir"} 1
    // http_request_latency_seconds_count{method="putobjectdir"} 1
    // http_request_latency_seconds_sum{method="putobjectdir"} 0.998
});

For more advanced usage and full API documentation, see docs/API.md.

Installation

npm install artedi

DTrace probes

artedi includes some useful DTrace probes. The full listing of probes and their arguments can be found in the lib/provider.js file.

In this first example artedi is observing the latency of queries to three Postgres instances (using joyent/pgstatsmon). The latency observations include the name of the backend Postgres instance.

We can create a graph of each Postgres backend's latency using built-in DTrace aggregation:

$ dtrace -qn 'artedi*:::histogram-observe {@lat[json(copyinstr(arg2), "name")] = quantize(arg1);} tick-10s {printa(@lat);}'

  3.postgres.walleye.kkantor.com-87eb177c
           value  ------------- Distribution ------------- count
               8 |                                         0
              16 |@@@@@@@@@@                               5
              32 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@            15
              64 |@@                                       1
             128 |                                         0

  2.postgres.walleye.kkantor.com-335c1a83
           value  ------------- Distribution ------------- count
               8 |                                         0
              16 |@@@@@@@@                                 4
              32 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@           16
              64 |@@                                       1
             128 |                                         0

  1.postgres.walleye.kkantor.com-f5c49b33
           value  ------------- Distribution ------------- count
               8 |                                         0
              16 |@@@@@@@@                                 4
              32 |@@@@@@@@@@@@@@@@@@@@@@@@@@@              14
              64 |@@@@@@                                   3
             128 |                                         0
^C

We could also retrieve the number of HTTP operations performed by HTTP handler name and return code (from manta-muskie):

$ dtrace -qn 'artedi*:::counter-add /copyinstr(arg0) == "http_requests_completed" /{ jsonstr = copyinstr(arg2); @counts[json(jsonstr, "operation"), json(jsonstr, "statusCode")] = count(); }'
^C

  getstorage    200     135
  putobject     204     137

These probes could conceivably be used to create more complicated reporting tools as well.

License

MPL-v2