Skip to content

Metrics

Mahdi Sheikh Hosseini edited this page Aug 1, 2025 · 2 revisions

πŸ“Š Metrics Integration in MicroFox

MicroFox provides built-in support for exposing application metrics via a Prometheus-compatible endpoint at:

/metrics

This functionality is powered by Micrometer, the industry-standard metrics collection library used in production environments.

βš™οΈ Enabling Metrics

To enable metrics in your MicroFox application, simply add the following Maven dependency:

<dependency>
    <groupId>ir.moke.microfox</groupId>
    <artifactId>microfox-metrics</artifactId>
    <version>${microfox.version}</version>
</dependency>

That's it β€” no manual configuration or activation is needed. Once the dependency is present, the /metrics endpoint becomes automatically available.

πŸ“‘ Metrics Endpoint

Path:

GET /metrics

Content-Type:

text/plain; version=0.0.4

Output: Prometheus-compliant metric format:

# HELP jvm_memory_used_bytes The amount of used memory
# TYPE jvm_memory_used_bytes gauge
jvm_memory_used_bytes{area="heap",id="G1 Eden Space",} 1.048576E7
...

πŸ”Œ Internals & Dependencies

MicroFox metrics module is internally based on:

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

This ensures compatibility with modern observability stacks including Prometheus, Grafana, and OpenTelemetry (via bridge adapters).

πŸ“ˆ Collected Metrics

Out of the box, MicroFox + Micrometer collects:

Metric Category Description
jvm.memory.* Heap, non-heap, Eden/Survivor/Old space usage
jvm.gc.* GC pause count and duration
system.cpu.* CPU usage, system load
process.* Uptime, threads, file descriptors
http.server.requests Request count, response time (Jetty internal)
logback.events Logging events (if logback is used)

⚠️ Some metrics may depend on your JVM version and OS.

🎯 Example Usage with Prometheus

To scrape metrics into Prometheus, use the following config:

scrape_configs:
  - job_name: 'microfox-app'
    static_configs:
      - targets: ['localhost:8080']
        metrics_path: '/metrics'

Then visualize data in Grafana using the Prometheus data source.

βœ… Benefits

  • One-line setup via Maven
  • No config files or annotations
  • Standards-compliant /metrics endpoint
  • Full Prometheus integration
  • Works with JVM, HTTP, system, and custom metrics

Clone this wiki locally