inspector-carbon
TypeScript icon, indicating that this package has built-in type declarations

2.8.0 • Public • Published

inspector-carbon

Typescript Metrics Reporter for graphite carbon.

NPM Version License CI Status

This library is made for inspector-metrics node module and is meant to be used with nodejs.
It uses node-graphite as graphite/carbon client.

Take a look at the Documentation.

install

npm install --save inspector-carbon

basic usage

import { MetricRegistry } from "inspector-metrics";
import { CarbonMetricReporter } from "inspector-carbon";

// instance the carbon reporter
const reporter: CarbonMetricReporter = new CarbonMetricReporter({
    host: "http://graphite-server/",
});
const registry: MetricRegistry = new MetricRegistry();

// add the registry to the reporter
reporter.addMetricRegistry(registry);
// start reporting
await reporter.start();

set common tags for all metrics

import { MetricRegistry } from "inspector-metrics";
import { CarbonMetricReporter } from "inspector-carbon";

// instance the carbon reporter
const reporter: CarbonMetricReporter = new CarbonMetricReporter({
    host: "http://graphite-server/",
});

// set common tags for all metrics
reporter.getTags().set("app-name", "my-service");
reporter.getTags().set("app-version", "v1.2.3");

reporting events

import { Event, MetricRegistry } from "inspector-metrics";
import { CarbonMetricReporter } from "inspector-carbon";

// instance the carbon reporter
const reporter: CarbonMetricReporter = new CarbonMetricReporter({
    host: "http://graphite-server/",
});

// build an ad-hoc event
const event = new Event<number>("application_started")
    .setValue(1.0)
    .setTag("mode", "test")
    .setTag("customTag", "specialValue");

// send the event to graphite
reporter.reportEvent(event);

multi process support (nodejs cluster)

By default forked processes are sending the metrics as inter-process message
to the master process. The CarbonMetricReporter is listening for those messages
and reports the metrics from the other processes.

To disable this behavior set the DisabledClusterOptions when creating an instance.

In each case you should set the pid as reporter tag.

import { tagsToMap, DisabledClusterOptions } from "inspector-metrics";
import { CarbonMetricReporter } from "inspector-carbon";

// instance the carbon reporter
const reporter: CarbonMetricReporter = new CarbonMetricReporter({
    clusterOptions: new DisabledClusterOptions(),
    host: "http://graphite-server/",
});

// set "pid" to process id
reporter.setTags(tagsToMap({
    pid: `${process.pid}`,
}));

License

MIT

Package Sidebar

Install

npm i inspector-carbon

Weekly Downloads

0

Version

2.8.0

License

MIT

Unpacked Size

31.2 kB

Total Files

9

Last publish

Collaborators

  • rstiller