Skip to content

Pull Request: Add /metrics Endpoint with Request Tracking#78

Open
human-77 wants to merge 3 commits intoOpenZeppelin:mainfrom
human-77:main
Open

Pull Request: Add /metrics Endpoint with Request Tracking#78
human-77 wants to merge 3 commits intoOpenZeppelin:mainfrom
human-77:main

Conversation

@human-77
Copy link

Summary

This PR adds a Prometheus-compatible metrics endpoint to monitor server health and track HTTP requests by route and status code.

Changes

1. route.ts

Implements a /metrics endpoint that exposes server metrics in Prometheus format, including:

  • Server uptime indicator (up)
  • CPU usage (process_cpu_seconds_total)
  • Memory metrics (RSS, heap total/used, external memory, array buffers)
  • HTTP request counters grouped by route and status code (http_requests_by_status)

This endpoint can be scraped by Prometheus or other monitoring tools to track application performance and health.

2. requestCounter.ts

Provides a lightweight in-memory request counter utility with two main functions:

  • incrementCounter(route, statusCode): Records each HTTP request with its route and status code
  • getStatusCounters(): Retrieves the accumulated request statistics

Uses globalThis to persist counters across module hot-reloads in development, ensuring metrics aren't lost during the session.

3. metrics.test.ts

Adds a basic test suite for the metrics endpoint to ensure:

  • The /metrics endpoint responds successfully
  • The response returns valid string content in Prometheus format

Use Case

These changes enable observability for the MCP server, allowing developers and operators to:

  • Monitor resource usage (CPU/memory)
  • Track request patterns and error rates
  • Set up alerts based on status code distributions
  • Debug performance issues in production

@github-actions
Copy link

github-actions bot commented Feb 19, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@human-77
Copy link
Author

human-77 commented Feb 19, 2026

If it's not possible do the merge without signing the CLA I won't mind if you guys just clone my repo and add to the project. It's just three files.

Ignore this, the message didn't showed to me until I reload the page

@human-77
Copy link
Author

I confirm that I have read and hereby agree to the OpenZeppelin Contributor License Agreement

@wwwmilan
Copy link

Any prediction on when will this be merged? My team needs observability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants