Class AlertMetricsService

java.lang.Object
com.nt.udc.util.misc.metrics.AlertMetricsService

public class AlertMetricsService extends Object
Class responsible for exposing application metrics in a format that can be scraped by Prometheus. It allows to monitor OCOMC alerts in Prometheus Alert manager. This class provides methods for creating and managing gauges, as well as starting an HTTP server to expose the metrics to Prometheus.
  • Field Details

    • ALERTS_ENABLED

      public static final String ALERTS_ENABLED
      Environment variable names for configuration.
      See Also:
    • ALERTS_NM_SERVICE_PORT

      public static final String ALERTS_NM_SERVICE_PORT
      See Also:
    • ALERTS_ADMIN_SERVICE_PORT

      public static final String ALERTS_ADMIN_SERVICE_PORT
      See Also:
    • ALERTS_NM_SERVICE_PORT_DEFAULT

      public static final int ALERTS_NM_SERVICE_PORT_DEFAULT
      Default port numbers for the alert services.
      See Also:
    • ALERTS_ADMIN_SERVICE_PORT_DEFAULT

      public static final int ALERTS_ADMIN_SERVICE_PORT_DEFAULT
      See Also:
  • Constructor Details

    • AlertMetricsService

      public AlertMetricsService()
  • Method Details

    • getRegistry

      public io.micrometer.prometheusmetrics.PrometheusMeterRegistry getRegistry()
      Gets the Prometheus registry used by this service.
      Returns:
      the Prometheus registry
    • setLogger

      public void setLogger(Logger logger)
      Sets the logger for the alert metrics service.
    • getGauge

      public int getGauge(String metricName, String... tags)
      Gets the current value of a gauge.
      Parameters:
      metricName - the name of the metric
      tags - the tags associated with the gauge
      Returns:
      the current value of the gauge, or 0 if it does not exist
    • setGauge

      public void setGauge(String metricName, int newValue, String... tags)
      Sets the value of a gauge. If the gauge does not exist, it is created with the given value.
      Parameters:
      metricName - the name of the metric
      newValue - the new value for the gauge
      tags - the tags associated with the gauge
    • incrementGauge

      public void incrementGauge(String metricName, String... tags)
      Increments the value of a gauge. If the gauge does not exist, it is created with a value of 1.
      Parameters:
      metricName - the name of the metric
      tags - the tags associated with the gauge
    • resetGauge

      public void resetGauge(String metricName, String... tags)
      Resets the value of a gauge to 0. If the gauge does not exist, this method has no effect.
      Parameters:
      metricName - the name of the metric
      tags - the tags associated with the gauge
    • removeGauge

      public void removeGauge(String metricName, String... tags)
      Removes a gauge. If the gauge does not exist, this method has no effect.
      Parameters:
      metricName - the name of the metric
      tags - the tags associated with the gauge
    • startHttpServer

      public void startHttpServer(int port)
      Starts an HTTP server to expose the metrics to Prometheus.
      Parameters:
      port - the port number to use for the HTTP server