telemetry-events-quantify
v2.0.0
Published
Helper for creating telemetry events from Quantify metrics.
Downloads
5
Readme
telemetry-events-quantify
Stability: 1 - Experimental
Helper for creating and emitting telemetry events for Quantify metrics.
Contributors
Contents
Installation
npm install telemetry-events-quantify
Usage
To run the below example run:
npm run readme
"use strict";
const events = require("events");
const pkg = require("../package.json");
const Quantify = require("quantify");
const QuantifyTelemetryEvents = require("../index.js");
const TelemetryEvents = require("telemetry-events");
const emitter = new events.EventEmitter();
const metricsRegistry = new Quantify();
const telemetryEvents = new TelemetryEvents(
{
emitter,
package: pkg
}
);
const quantifyTelemetryEmitter = new QuantifyTelemetryEvents(
{
telemetry: telemetryEvents
}
);
emitter.on("telemetry", event => console.dir(event));
// create some metrics using Quantify
metricsRegistry.counter("errors", "Err",
{
server: "foo"
}
);
metricsRegistry.gauge("cpuLoad", "Load");
metricsRegistry.histogram("searchResultsReturned",
{
measureUnit: "Result",
sampleSizeUnit: "Req"
}
);
metricsRegistry.meter("requests",
{
rateUnit: "Req/s",
updateCountUnit: "Req"
}
);
metricsRegistry.timer("requestLatency",
{
measureUnit: "ms",
rateUnit: "Req/s",
sampleSizeUnit: "Req"
},
{
some: "other_tag",
and: "more_metadata"
}
);
// get the metrics we want to report
const metrics = metricsRegistry.getMetrics();
quantifyTelemetryEmitter.counter("errors", metrics.counters["errors"]);
quantifyTelemetryEmitter.gauge("cpuLoad", metrics.gauges["cpuLoad"]);
quantifyTelemetryEmitter.histogram("searchResultsReturned", metrics.histograms["searchResultsReturned"]);
quantifyTelemetryEmitter.meter("requests", metrics.meters["requests"]);
quantifyTelemetryEmitter.timer("requestLatency", metrics.timers["requestLatency"]);
// ...or just call this
quantifyTelemetryEmitter.metrics(metrics);
Tests
npm test
Documentation
QuantifyTelemetryEvents
Public API
- new QuantifyTelemetryEvents(config)
- telemetry.counter(name, c)
- telemetry.gauge(name, g)
- telemetry.histogram(name, h)
- telemetry.meter(name, m)
- telemetry.metrics(metrics) USE THIS
- telemetry.timer(name, t)
new QuantifyTelemetryEvents(config)
config
: Objecttelemetry
: TelemetryEvents Instance of TelemetryEvents to use for processing.
Creates a new QuantifyTelemetryEvents instance.
telemetry.counter(name, c)
name
: String Name of the metric to be used forevent.name
property.unit
: String Unit to be used for the metricevent.unit
property.c
: Object Quantify calculated counter to process.- Return: Object The event.
Helper to create "metric" event with 'target_type' of "counter". If emitter
was specified in configuration, calling this helper will also emit this event. The created event object will have the following properties (in addition to those added by TelemeteryEvents):
{
type: 'metric',
name: <name>,
target_type: 'counter',
unit: <c.unit>,
value: <c.value>
}
If c
has metadata
, properties of metadata
will be included with or override the above template.
telemetry.gauge(name, g)
name
: String Name of the metric to be used forevent.name
property.unit
: String Unit to be used for the metricevent.unit
property.g
: Object Quantify calculated gauge to process.- Return: Object The event.
Helper to create "metric" event with 'target_type' of "gauge". If emitter
was specified in configuration, calling this helper will also emit this event. The created event object will have the following properties (in addition to those added by TelemeteryEvents):
{
type: 'metric',
name: <name>,
target_type: 'gauge',
unit: <g.unit>,
value: <g.value>
}
If g
has metadata
, properties of metadata
will be included with or override the above template.
telemetry.histogram(name, h)
name
: String Name of the metric to be used forevent.name
property.h
: Object Quantify calculated histogram to process.- Return: Object The event.
Helper to create "metric" event with 'target_type' of "histogram". If emitter
was specified in configuration, calling this helper will also emit this event. The created event object will have the following properties (in addition to those added by TelemeteryEvents):
{
type: 'metric',
name: <name>,
target_type: 'histogram',
value: {
measureUnit: <h.measureUnit>,
sampleSize: <h.sampleSize>,
sampleSizeUnit: <h.sampleSizeUnit>,
max: <h.max>,
mean: <h.mean>,
median: <h.median>,
min: <h.min>,
percentile75: <h.percentile75>,
percentile95: <h.percentile95>,
percentile98: <h.percentile98>,
percentile99: <h.percentile99>,
percentile999: <h.percentile999>,
standardDeviation: <h.standardDeviation>
}
}
If h
has metadata
, properties of metadata
will be included with or override the above template.
telemetry.meter(name, m)
name
: String Name of the metric to be used forevent.name
property.m
: Object Quantify calculated meter to process.- Return: Object The event.
Helper to create "metric" event with 'target_type' of "meter". If emitter
was specified in configuration, calling this helper will also emit this event. The created event object will have the following properties (in addition to those added by TelemeteryEvents):
{
type: 'metric',
name: <name>,
target_type: 'meter',
value: {
rateUnit: <m.rateUnit>,
updateCount: <m.updateCount>,
updateCountUnit: <m.updateCountUnit>,
meanRate: <m.meanRate>,
oneMinuteRate: <m.oneMinuteRate>,
fiveMinuteRate: <m.fiveMinuteRate>,
fifteenMinuteRate: <m.fifteenMinuteRate>
}
}
If m
has metadata
, properties of metadata
will be included with or override the above template.
telemetry.metrics(metrics)
metrics
: Object Result of Quantify.getMetrics([filters]).- Return Array Array of events.
Helper to create "metric" events for all target types. If emitter
was specified in configuration, calling this helper will also emit these events.
telemetry.timer(name, t)
name
: String Name of the metric to be used forevent.name
property.t
: Object Quantify calculated timer to process.- Return: Object The event.
Helper to create "metric" event with 'target_type' of "timer". If emitter
was specified in configuration, calling this helper will also emit this event. The created event object will have the following properties (in addition to those added by TelemeteryEvents):
{
type: 'metric',
name: <name>,
target_type: 'timer',
value: {
measureUnit: <t.measureUnit>,
rateUnit: <t.rateUnit>,
sampleSize: <t.sampleSize>,
sampleSizeUnit: <t.sampleSizeUnit>,
updateCount: <t.sampleSize>,
meanRate: <t.meanRate>,
oneMinuteRate: <t.oneMinuteRate>,
fiveMinuteRate: <t.fiveMinuteRate>,
fifteenMinuteRate: <t.fifteenMinuteRate>
max: <t.max>,
mean: <t.mean>,
median: <t.median>,
min: <t.min>,
percentile75: <t.percentile75>,
percentile95: <t.percentile95>,
percentile98: <t.percentile98>,
percentile99: <t.percentile99>,
percentile999: <t.percentile999>,
standardDeviation: <t.standardDeviation>
}
}
If t
has metadata
, properties of metadata
will be included with or override the above template.