npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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:

  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