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

@pager/metrics-client

v6.0.0

Published

Hapi Prometheus Plugin and optional endpoint

Downloads

4,562

Readme

metrics-client

Hapi-centric Prometheus Plugin and optional endpoint

Use this plugin to:

  • Add an endpoint for metrics (defaults to /metrics)
  • Add custom metrics in routes (server binds .metrics in request contexts)
  • Run a server for worker that reports metrics from an endpoint (defaults to /metrics on port 3000)

Integration

Modules

Once metric-client is a Hapi-centric Prometheus Plugin. Hapi and metrics-client modules need to be installed.

npm install -S @hapi/hapi
npm install -S @pager/metrics-client

Usage

Sample usage for metrics-client server

'use strict';

const Hapi = require('@hapi/hapi');
const Metrics = require('@pager/metrics-client');

const startServer = async () => {

    const server = await new Hapi.Server({
        port: 3000
    });
    await server.register([
        {
            plugin: Metrics
        }
    ]);
    await server.start();
    console.log( `Server started at ${ server.info.uri }`);
    return server;
};

module.exports = startServer();

Annotations

annotations:
  prometheus.io/scrape: "true"
  prometheus.io/port: {{ .Values.service.internalPort | quote }}

Readiness and Liveness

Readiness probes are designed to let Kubernetes know when your app is ready to serve traffic. Similarly, liveness probes let Kubernetes know if your app is alive or dead. Metric-client plugin is also support health check and needs to be added to the deployment file under container details.

livenessProbe:
  httpGet:
    path: /health
    port: {{ .Values.service.internalPort }} 
  initialDelaySeconds: 15
  timeoutSeconds: 1
readinessProbe:
  httpGet:
    path: /health
    port: {{ .Values.service.internalPort }}
  initialDelaySeconds: 15
  timeoutSeconds: 1

Internal Ports

Prometheus server Kubernetes service discovery configuration is going to search running server on kubernetes cluster. It will use default server port 3000. Thus, metrics-client must start at default port 3000. If the server is not already running on port 3000, it should be added on containers details.

env:
  - name: PORT
  value: "3000"

References

Health vs Metrics endpoint

Health endpoint is designed to provide information about a readiness and liveness of the server. On the other hand, metrics endpoint provides information about the performance of the server such as load time, response time, memory usage, CPU usage etc.

| Metrics List| |---| |cpu_user_time| |cpu_user_utilization| |cpu_system_time| |cpu_system_utilization| |event_loop_usage| |event_loop_wait| |memory_physical| |memory_heap_used| |memory_heap_free| |memory_heap_max| |memory_nonheap_used| |http_request_duration_milliseconds| |http_request_buckets_milliseconds| |gc_pause_time_min| |gc_pause_time_max| |gc_pause_time_total| |gc_scavenge_min| |gc_scavenge_max| |gc_scavenge_total| |gc_marksweepcompact_min| |gc_marksweepcompact_max| |gc_marksweepcompact_total| |gc_incrementalmarking_min| |gc_incrementalmarking_max| |gc_incrementalmarking_total|