Interface MetricsCollector


public interface MetricsCollector
Contract for a component that collects metrics from a microservice.

Implemented in monitoring-server by ActuatorMetricsCollector, which performs HTTP requests to the target service's /actuator/health and /actuator/metrics endpoints and converts the response into a MetricSnapshot.

Separating the interface from the implementation allows:

  • easy substitution in tests;
  • adding alternative collection mechanisms (e.g. JMX or gRPC) without modifying consumer code.
  • Method Summary

    Modifier and Type
    Method
    Description
    Collects the current metrics from the specified service.
  • Method Details

    • collect

      MetricSnapshot collect(ServiceInfo service)
      Collects the current metrics from the specified service.

      If the service is unavailable, the method does not throw an exception. Instead it returns a MetricSnapshot with status HealthStatus.DOWN and a populated errorMessage.

      Parameters:
      service - description of the service to collect metrics from
      Returns:
      a snapshot of the current service state