collectors-framework
TypeScript icon, indicating that this package has built-in type declarations

1.0.144 • Public • Published

Collectors Framework

Create by reading: https://itnext.io/step-by-step-building-and-publishing-an-npm-typescript-package-44fe7164964c

npm Commands:

  1. npm publish - publish package
  2. npm version patch - increase the package version number and commit
  3. npm run lint - run lint checks before publish
  4. npm install - install packages accordig to package.config file
  5. npm run build - run package build localy
  6. npm test - run test before publish

Metrics

Create multiple different metrics and report to influx DB

import { InfluxDbMetrics } from 'metrics/metrics';

const reportOptions = {}; // see all options below
const metrics = new InfluxDbMetrics(reportOptions);

const metricOptions = {
    metricName: 'my-amazing-metric',
    resetOnReport: false
}

metric.counter(metricOptions).inc();
metric.counter(metricOptions).inc(10);
metric.counter(metricOptions).dec();
metric.counter(metricOptions).dec(10);

metric.gauge(metricOptions).set(10);

metric.histogram(metricOptions).update(50);

metric.meter(metricOptions).mark();
metric.meter(metricOptions).mark(10);

metrics.timer(metricOptions).time(() => // do work);
metrics.timer(metricOptions).time(async () => // do async work);

Reporting options & defaults:

const host = options.host ?? '127.0.0.1';
const port = options.port ?? 8086;
const protocol = options.protocol ?? 'http'; // the protocol used for communication with influx DB
const app = options.appName ?? 'application'; // the name of our application, will be a tag in influx DB
const environment = options.environment ?? 'undefined'; // the name of the environment, will be a tag in influx DB
const database = options.database ?? "app_metrics"; // the name of the database in influx DB
const skipIdleMetrics = options.skipIdleMetrics === undefined ? true : options.skipIdleMetrics;
const flushInterval = options.flushInterval ?? 1000; // interval to send batched data to influx DB
const timeout = options.timeout; // timeout (in ms) when communicating with influx DB
const onErrorCallback = options.onErrorCallback; // a callback that will return errors to client
options.tags - additional default tags to attach to all metrics
options.autoCreateDatabase - if true, database will be generated automatically if it does not exist

Metric options & defaults:

metricName - mandatory - the name of the metric
resetOnReport - default = true - flag to specify if metric data should be cleared after reporting to influx

System metrics

import { SystemMetricsCollector } from 'metrics/systemMetricsCollector';

new SystemMetricsCollector({ collectHeapMemory: true, collectCpu: true });

System metrics options & defaults: Note: SystemMetric options are the same as Reporting options + the fields below

const collectMemory = options.collectHeapMemory ?? true; // should heap memory metrics be collected
const collectCpu = options.collectCpu ?? true; // should cpu metrics be collected
const collectInterval = options.collectInterval ? options.collectInterval : 1000; // interval of system metrics collection

Package Sidebar

Install

npm i collectors-framework

Weekly Downloads

135

Version

1.0.144

License

ISC

Unpacked Size

161 kB

Total Files

248

Last publish

Collaborators

  • ofer_lazmi
  • yonimv