Package com.nt.udc.util.misc.metrics
Class AlertMetricsService
java.lang.Object
com.nt.udc.util.misc.metrics.AlertMetricsService
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintGets the current value of a gauge.io.micrometer.prometheusmetrics.PrometheusMeterRegistryGets the Prometheus registry used by this service.voidincrementGauge(String metricName, String... tags) Increments the value of a gauge.voidremoveGauge(String metricName, String... tags) Removes a gauge.voidresetGauge(String metricName, String... tags) Resets the value of a gauge to 0.voidSets the value of a gauge.voidSets the logger for the alert metrics service.voidstartHttpServer(int port) Starts an HTTP server to expose the metrics to Prometheus.
-
Field Details
-
ALERTS_ENABLED
Environment variable names for configuration.- See Also:
-
ALERTS_NM_SERVICE_PORT
- See Also:
-
ALERTS_ADMIN_SERVICE_PORT
- See Also:
-
ALERTS_NM_SERVICE_PORT_DEFAULT
public static final int ALERTS_NM_SERVICE_PORT_DEFAULTDefault 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
Sets the logger for the alert metrics service. -
getGauge
Gets the current value of a gauge.- Parameters:
metricName- the name of the metrictags- the tags associated with the gauge- Returns:
- the current value of the gauge, or 0 if it does not exist
-
setGauge
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 metricnewValue- the new value for the gaugetags- the tags associated with the gauge
-
incrementGauge
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 metrictags- the tags associated with the gauge
-
resetGauge
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 metrictags- the tags associated with the gauge
-
removeGauge
Removes a gauge. If the gauge does not exist, this method has no effect.- Parameters:
metricName- the name of the metrictags- 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
-