8000 feat: add prometheus metrics by jgryffindor · Pull Request #386 · liftedinit/talib · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add prometheus metrics #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

jgryffindor
Copy link
Contributor
@jgryffindor jgryffindor commented May 12, 2025

This pull request introduces a new monitoring and metrics system using the prom-client library, adding metrics collection and exposing a /monitoring/metrics endpoint.

Monitoring and Metrics System Integration:

  • Dependency Addition: Added prom-client as a new dependency in server/package.json to enable Prometheus metrics collection.

  • Monitoring 8000 Module: Introduced a new MonitoringModule in server/src/metrics/monitoring/monitoring.module.ts, which includes:

    • A MonitoringService to define and update custom metrics. [1] [2]
    • A MonitoringController to expose a /monitoring/metrics endpoint for Prometheus scraping.
    • A MonitoringMiddleware to ensure metrics are updated before serving the metrics endpoint.

Application Module Updates:

  • Module Imports: Updated server/src/app.module.ts to import and register the MonitoringModule and the Prometheus integration module (@willsoto/nestjs-prometheus). [1] [2]

  • Metrics Module Updates: Modified server/src/metrics/metrics.module.ts to include the MonitoringModule as a dependency, allowing it to integrate with existing metrics functionality.

New Dependencies for Monitoring

  • Added prom-client dependencies in server/package.json to enable Prometheus metrics collection and integration. [1] [2]

Monitoring Module Implementation

  • Created a new MonitoringModule in server/src/metrics/monitoring/monitoring.module.ts, which includes middleware, a service, and a controller for handling metrics. The module integrates with existing entities like Metric and PrometheusQuery.

Metrics Collection and Exposure

  • Implemented MonitoringService in server/src/metrics/monitoring/monitoring.service.ts to define and register custom metrics using Prometheus. Metrics are updated dynamically and include labels for additional context.
  • Added a MonitoringController in server/src/metrics/monitoring/monitoring.controller.ts to expose a /monitoring/metrics endpoint, which serves the collected metrics in Prometheus format.

Middleware for Metrics Updates

  • Introduced MonitoringMiddleware in server/src/metrics/monitoring/monitoring.middleware.ts to ensure metrics are updated before responding to requests for the /monitoring/metrics endpoint.

Module Integration

  • Integrated the MonitoringModule into the main AppModule and MetricsModule to make it part of the application's dependency graph. [1] [2] [3]

Screenshots (if applicable)

Checklist:

  • I have read and followed the CONTRIBUTING guidelines for this project.
  • I have added or updated tests and they pass.
  • I have added or updated documentation and it is accurate.
  • I have noted any breaking changes in this module or downstream modules.

- Add monitoring service, module and controller
- Add custom registry and type definitions for adding counters, gauges with labels and custom functions to retrieve values
- Add middleware for monitoring updates when /monitoring/metrics route is called
- Add mfx power conversion metric to monitoring service
@jgryffindor jgryffindor marked this pull request as ready for review May 14, 2025 19:00
@jgryffindor jgryffindor requested a review from fmorency May 14, 2025 19:01
Copy link
Contributor
@fmorency fmorency left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

private readonly logger = new Logger(MonitoringController.name);

constructor() {
// Initialie the Prometheus registry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Initialie the Prometheus registry
//Initialize the Prometheus registry

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
0