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 🙏

© 2025 – Pkg Stats / Ryan Hefner

service-metrics2-node

v1.0.0

Published

Metrics microservice in Node.js / ES2017 V2

Readme

Metrics Microservice for Node.js / ES2017 V2

Node.js CI npm npm

Overview

The Metrics microservice is designed to manage various metrics characterizing the operation of a process. Each metric has the following characteristics:

  • Metric name
  • Up to 3 types of measurements (in string format)
  • Date and time
  • Numerical value

When adding or updating a metric, statistics are automatically calculated for different time horizons with the calculation of:

  • Average values
  • Maximum values
  • Minimum values
  • Accumulated values

Features

  • Multiple Deployment Options

    • Standalone Process
    • HTTP/REST API
    • Multiple Persistence Options
  • Persistence Options

    • In-Memory (for development and testing)
    • Flat Files (for development and testing)
    • MongoDB (for production)
  • No External Dependencies

    • Self-contained service
    • Easy to deploy and maintain

Quick Links

Getting Started

Installation

git clone [email protected]:entinco/eic-services-infrastructure2.git

Note: The Pip.Service team is working on implementing packaging and making stable releases available as downloadable archives.

Running the Service

  1. Add config.json file to the config folder
  2. Start the microservice:
node ./bin/main.js

API Reference

Data Models

// Create or update metric struct
class MetricUpdateV1 {
  public name: string;
  public year: number;
  public month: number;
  public day: number;
  public hour: number;
  public minute?: number;
  public dimension1?: string;
  public dimension2?: string;
  public dimension3?: string;
  public value: number;
}

// Metric definition struct
class MetricDefinitionV1 {
  public name: string;
  public dimension1: string[];
  public dimension2: string[];
  public dimension3: string[];
}

// Metric value struct
class MetricValueSetV1 {
  public name: string;
  public time_horizon: number;
  public dimension1: string;
  public dimension2: string;
  public dimension3: string;
  public values: MetricValueV1[];
}

// Values of metric
class MetricValueV1 {
  public year?: number;
  public month?: number;
  public day?: number;
  public hour?: number;
  public minute?: number;
  public count: number;
  public sum: number;
  public max: number;
  public min: number;
}

// Time horizons
class TimeHorizonV1 {
  public static Total: number = 0;
  public static Year: number = 1;
  public static Month: number = 2;
  public static Day: number = 3;
  public static Hour: number = 4;
  public static Minute: number = 5;
}

Interface

interface IMetricsController {
  getMetricDefinitions(context: IContext): Promise<MetricDefinitionV1[]>;
  getMetricDefinitionByName(
    context: IContext,
    name: string
  ): Promise<MetricDefinitionV1>;
  getMetricsByFilter(
    context: IContext,
    filter: FilterParams,
    paging: PagingParams
  ): Promise<DataPage<MetricValueSetV1>>;
  updateMetric(
    context: IContext,
    update: MetricUpdateV1,
    maxTimeHorizon: number
  ): Promise<void>;
  updateMetrics(
    context: IContext,
    updates: MetricUpdateV1[],
    maxTimeHorizon: number
  ): Promise<void>;
}

Configuration

Persistence Configuration

Memory Persistence

- descriptor: "metrics:persistence:memory:default:1.0"
  options:
    max_page_size: 100

File Persistence

- descriptor: "metrics:persistence:file:default:1.0"
  path: "./data/metrics"

MongoDB Persistence

- descriptor: "metrics:persistence:file:default:1.0"
  collection: "metrics"
  connection:
    uri: "mongodb://localhost/pipservicestest"
    host: "localhost"
    port: 27017
    database: "app"
  credential:
    username: "user_db"
    password: "passwd_db"

Service Configuration

- descriptor: "metrics:service:default:default:1.0"

HTTP Controller Configuration

- descriptor: "metrics:controller:commandable-http:default:1.0"
  connection:
    protocol: "http"
    host: "0.0.0.0"
    port: 8080

Development

Prerequisites

  • Node.js from https://nodejs.org/en/download/
  • TypeScript compiler: npm install typescript -g
  • Mocha test runner: npm install mocha -g
  • Git from https://git-scm.com/downloads
  • MongoDB (optional) from https://www.mongodb.org/downloads

Building and Testing

# Install dependencies
npm install

# Build the project
tsc

# Run tests
npm test

# Run benchmarks
npm run benchmark

Examples

Basic Usage

import { MetricsHttpClientV1 } from "client-metrics2-node";

// Configure client
let httpConfig = ConfigParams.fromTuples(
  "connection.protocol",
  "http",
  "connection.port",
  3000,
  "connection.host",
  "localhost"
);

// Create and open client
let client = new MetricssHttpClientV1();
await client.open(null);

// Example: Update metric
await client.updateMetric(
  null,
  <MetricUpdateV1>{
    name: "metric1",
    dimension1: "A",
    dimension2: "B",
    dimension3: null,
    year: 2018,
    month: 8,
    day: 26,
    hour: 12,
    value: 123,
  },
  TimeHorizonV1.Hour
);

// Example: Get metrics by filter
let page = await client.getMetricsByFilter(
  null,
  FilterParams.fromTuples("name", "metric1"),
  new PagingParams()
);

Acknowledgements

This client library was created and currently maintained by: