1.0.6 • Published 1 year ago

@wojbach/nodeamf v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

logo

license node npm Circleci codecov npm

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 WatchData DogPrometheus
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

NameClient packageVersionNPM Link
AWS Cloud Watch@aws-sdk/client-cloudwatch3.245.0Link
Data Doghot-shots9.3.0Link
Prometheusprom-client14.1.1Link

A list of nodeamf's custom parameters for vendors that can be passed together with config specific for a client

VendorParameterTypeDescription
AWS Cloud Watchnamestringused to register vendors under a specific name, default: "cloudWatch"
flushTimeoutnumbernumber of milliseconds between calls to AWS API, has a direct connection with metrics resolution, default:60000
bufferSizenumbermaximum buffer size that holds metrics + dimensions (tags) as a unique key, default: 1000
namespacestringa namespace under which metrics will be stored, default: 'DEFAULT'
Data Dognamestringused to register vendors under a specific name, default: "dogStatsD"
Prometheusnamestringused 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.