collectors-framework
v1.0.144
Published
Common code for all collectors
Downloads
29
Readme
Collectors Framework
Create by reading: https://itnext.io/step-by-step-building-and-publishing-an-npm-typescript-package-44fe7164964c
npm Commands:
- npm publish - publish package
- npm version patch - increase the package version number and commit
- npm run lint - run lint checks before publish
- npm install - install packages accordig to package.config file
- npm run build - run package build localy
- 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