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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@push.rocks/smartmetrics

v3.0.3

Published

A package for easy collection and reporting of system and process metrics.

Readme

Prometheus Metrics Implementation Plan

cat /home/philkunz/.claude/CLAUDE.md

Overview

Add Prometheus metrics exposure functionality to SmartMetrics while maintaining backward compatibility with existing getMetrics() method.

Implementation Tasks

1. Add HTTP Server Dependencies

  • [x] Check if we need to add any HTTP server dependency to package.json
  • [x] Import necessary modules in smartmetrics.plugins.ts

2. Create Prometheus Gauges in SmartMetrics Class

  • [x] Add private properties for custom gauges:
    • [x] private cpuPercentageGauge: plugins.promClient.Gauge<string>
    • [x] private memoryPercentageGauge: plugins.promClient.Gauge<string>
    • [x] private memoryUsageBytesGauge: plugins.promClient.Gauge<string>
  • [x] Initialize gauges in setup() method with appropriate names and help text:
    • [x] smartmetrics_cpu_percentage - "Current CPU usage percentage"
    • [x] smartmetrics_memory_percentage - "Current memory usage percentage"
    • [x] smartmetrics_memory_usage_bytes - "Current memory usage in bytes"

3. Update getMetrics() Method

  • [x] After calculating metrics, update the Prometheus gauges:
    • [x] this.cpuPercentageGauge.set(cpuPercentage)
    • [x] this.memoryPercentageGauge.set(memoryPercentage)
    • [x] this.memoryUsageBytesGauge.set(memoryUsageBytes)
  • [x] Ensure gauges are only updated if they exist (defensive programming)

4. Add getPrometheusFormattedMetrics() Method

  • [x] Create new public async method getPrometheusFormattedMetrics(): Promise<string>
  • [x] Call this.getMetrics() to ensure gauges are updated with latest values
  • [x] Return await this.registry.metrics() to get Prometheus text format

5. Add HTTP Server Properties

  • [x] Add private property for HTTP server: private prometheusServer?: any
  • [x] Add private property for server port: private prometheusPort?: number

6. Implement enablePrometheusEndpoint() Method

  • [x] Create new public method enablePrometheusEndpoint(port: number = 9090): void
  • [x] Check if server is already running, if so, log warning and return
  • [x] Create minimal HTTP server using Node.js built-in http module:
    • [x] Listen on specified port
    • [x] Handle GET requests to /metrics endpoint
    • [x] Return Prometheus-formatted metrics with correct Content-Type header
    • [x] Handle other routes with 404
  • [x] Store server reference and port for later cleanup
  • [x] Log info message about endpoint availability

7. Add disablePrometheusEndpoint() Method

  • [x] Create new public method disablePrometheusEndpoint(): void
  • [x] Check if server exists, if not, return
  • [x] Close the HTTP server
  • [x] Clear server reference and port
  • [x] Log info message about endpoint shutdown

8. Update stop() Method

  • [x] Call disablePrometheusEndpoint() to ensure clean shutdown

9. Add Tests

  • [x] Add test for getPrometheusFormattedMetrics():
    • [x] Verify it returns a string
    • [x] Verify it contains expected metric names
    • [x] Verify format matches Prometheus text exposition format
  • [x] Add test for enablePrometheusEndpoint():
    • [x] Start endpoint on test port (e.g., 19090)
    • [x] Make HTTP request to /metrics
    • [x] Verify response has correct Content-Type
    • [x] Verify response contains metrics
    • [x] Clean up by calling disablePrometheusEndpoint()

10. Update Documentation

  • [x] Add usage example in readme.md for Prometheus integration
  • [x] Document the new methods in code comments

Notes

  • Using Node.js built-in http module to avoid adding unnecessary dependencies
  • Default port 9090 is commonly used for metrics endpoints
  • Maintaining backward compatibility - existing functionality unchanged
  • Prometheus text format example: metric_name{label="value"} 123.45