1.0.6 • Published 1 year ago
@wojbach/nodeamf v1.0.6
Description
Nodeamf offers an abstraction over metrics like counters, gauges, histograms for multiple vendors:
It makes application metrics vendor-neutral. Package is 100% written in TypeScript but can be easily used in a pure JavaScript projects.
Installation
// using npm
$ npm install nodeamf
// using yarn
$ yarn add nodeamf
Base Usage
Setup with one metric and Prometheus
import { Counter, NodeAmf, Prometheus, SupportedVendorsEnum } from '@wojbach/nodeamf';
const nodeAmf = NodeAmf.init({
vendors: [
new Prometheus()
],
metrics: [
new Counter('simple-counter', {}, [SupportedVendorsEnum.Prometheus])
]
});
nodeAmf.getCounter('simple-counter').increment(10);
Vendors and metrics support
A list of supported metrics in each vendor
AWS Cloud Watch | Data Dog | Prometheus | |
---|---|---|---|
Counter | |||
Event | |||
Gauge | |||
Histogram | * | ||
Set | |||
Summary |
* AWS Cloud Watch offers many statistics definitions for metrics and NodeAmf package is compatible with this feature, more can be found here: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Statistics-definitions.html
A list of vendor clients libraries used in this package
Name | Client package | Version | NPM Link |
---|---|---|---|
AWS Cloud Watch | @aws-sdk/client-cloudwatch | 3.245.0 | Link |
Data Dog | hot-shots | 9.3.0 | Link |
Prometheus | prom-client | 14.1.1 | Link |
A list of nodeamf's custom parameters for vendors that can be passed together with config specific for a client
Vendor | Parameter | Type | Description |
---|---|---|---|
AWS Cloud Watch | name | string | used to register vendors under a specific name, default: "cloudWatch" |
flushTimeout | number | number of milliseconds between calls to AWS API, has a direct connection with metrics resolution, default:60000 | |
bufferSize | number | maximum buffer size that holds metrics + dimensions (tags) as a unique key, default: 1000 | |
namespace | string | a namespace under which metrics will be stored, default: 'DEFAULT' | |
Data Dog | name | string | used to register vendors under a specific name, default: "dogStatsD" |
Prometheus | name | string | used to register vendors under a specific name, default: "prometheus" |
Other setup examples
Setup with multiple metrics and vendors
import {
Counter,
Gauge,
DogStatsd,
NodeAmf,
Prometheus,
SupportedVendorsEnum
} from '@wojbach/nodeamf';
const nodeAmf = NodeAmf.init({
vendors: [
new Prometheus(),
new DogStatsd()
],
metrics: [
new Counter('simple-counter', {}, [SupportedVendorsEnum.Prometheus, SupportedVendorsEnum.DogStatsD]),
new Gauge('simple-gauge', {}, [SupportedVendorsEnum.DogStatsD]),
]
});
nodeAmf.getCounter('simple-counter').increment(10);
nodeAmf.getGauge('simple-gauge').set(10)
Setup vendors with custom names
import {
Counter,
Gauge,
DogStatsd,
NodeAmf,
Prometheus,
SupportedVendorsEnum
} from '@wojbach/nodeamf';
const nodeAmf = NodeAmf.init({
vendors: [
new Prometheus({ name: 'vendor1' }),
new DogStatsd({ name: 'vendor2' }),
new Prometheus({ name: 'vendor3' }),
],
metrics: [
new Counter('simple-counter', {}, ['vendor1', 'vendor2']),
new Gauge('simple-gauge', {}, ['vendor2', 'vendor3']),
]
});
nodeAmf.getCounter('simple-counter').increment(10);
nodeAmf.getGauge('simple-gauge').set(10)
Using metrics tags
import {
Counter,
NodeAmf,
Prometheus,
SupportedVendorsEnum
} from '@wojbach/nodeamf';
const nodeAmf = NodeAmf.init({
vendors: [
new Prometheus()
],
metrics: [
new Counter('visits', {tags: ['country', 'browser']}, [SupportedVendorsEnum.Prometheus]),
]
});
nodeAmf.getCounter('visits').increment();
nodeAmf.getCounter('visits').increment(1, {'country': 'US'});
nodeAmf.getCounter('visits').increment(1, {'browser': 'chrome'});
Accessing underlying clients and/or registry of vendor
import {
DogStatsd,
NodeAmf,
Prometheus,
SupportedVendorsEnum
} from '@wojbach/nodeamf';
const nodeAmf = NodeAmf.init({
vendors: [
new Prometheus(),
new DogStatsd()
],
metrics: [...]
});
nodeAmf.getVendor<Prometheus>(SupportedVendorsEnum.Prometheus).getClient() // returns client from https://www.npmjs.com/package/prom-client package
nodeAmf.getVendor<DogStatsd>(SupportedVendorsEnum.DogStatsD).getClient() // returns StatsD object from https://www.npmjs.com/package/hot-shots package
Custom vendor configuration
import {
DogStatsd,
NodeAmf,
Prometheus,
SupportedVendorsEnum
} from '@wojbach/nodeamf';
const nodeAmf = NodeAmf.init({
vendors: [
new DogStatsd({host: 'my-host', port: 1337, globalTags: ['service', 'environment']})
],
metrics: [...]
});
More examples
More examples can be found here including e2e cases.
Stay in touch
Author - Wojciech Bachur
License
Nodeamf is licensed under the MIT.