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');
var collector = artedi.createCollector();
var counter = collector.counter({
name: 'http_requests_completed',
help: 'count of muskie http requests completed',
labels: {
zone: 'e5d3'
}
});
counter.increment({
method: 'getobject',
code: '200'
});
collector.collect(artedi.FMT_PROM, function (err, metrics) {
console.log(metrics);
});
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]
});
histogram.observe(0.998, {
method: 'putobjectdir'
});
collector.collect(artedi.FMT_PROM, function (err, metrics) {
if (err) {
throw new Error('could not collect metrics');
}
console.log(metrics);
});
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