Package org.tailormap.api.prometheus
Class PrometheusResultProcessor
java.lang.Object
org.tailormap.api.prometheus.PrometheusResultProcessor
- All Implemented Interfaces:
TagNames
-
Field Summary
Fields inherited from interface org.tailormap.api.prometheus.TagNames
METRICS_APP_ID_TAG, METRICS_APP_LAYER_ID_TAG, METRICS_APP_NAME_TAG, METRICS_APP_REQUEST_COUNTER_NAME, METRICS_APP_TYPE_TAG
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprocessPrometheusResults
(com.fasterxml.jackson.databind.JsonNode root) Processes the JSON response from a Prometheus query and groups the results by appId.processPrometheusResults
(String jsonResponse) Processes the JSON response from a Prometheus query and groups the results by appId.com.fasterxml.jackson.databind.node.ArrayNode
processPrometheusResultsToJsonArray
(com.fasterxml.jackson.databind.JsonNode jsonResponse1, com.fasterxml.jackson.databind.JsonNode jsonResponse2) Merges two Prometheus JSON responses and processes the results into an ArrayNode.
-
Constructor Details
-
PrometheusResultProcessor
public PrometheusResultProcessor()
-
-
Method Details
-
processPrometheusResults
public Map<String,Map<String, processPrometheusResultsString>> (com.fasterxml.jackson.databind.JsonNode root) Processes the JSON response from a Prometheus query and groups the results by appId. Each appId will have a map of metrics, where the key is the metric type (e.g., "total", "lastUpdated") and the value is the metric value. Additionally, the appName is included in the map for each appId.- Parameters:
root
- the root JSON node containing the Prometheus query results (expected structure: root.data.result) where each result has a "metric" object with "appId", "type", and "value" fields, and a "value" array where the second element is the metric value. The "metric" object may also contain "appName".- Returns:
- a map where the key is the appId and the value is another map containing metric types as keys and their corresponding values. The inner map also includes the appName under the key "appName". If an appId has no metrics, it will not be included in the results.
-
processPrometheusResults
public Map<String,Map<String, processPrometheusResultsString>> (String jsonResponse) throws com.fasterxml.jackson.core.JsonProcessingException Processes the JSON response from a Prometheus query and groups the results by appId. This method is a convenience wrapper aroundprocessPrometheusResults(JsonNode)
.- Parameters:
jsonResponse
- the JSON response string from a Prometheus query- Returns:
- a map where the key is the appId and the value is another map containing metric types as keys and their corresponding values.
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- if there is an error parsing the JSON response
-
processPrometheusResultsToJsonArray
public com.fasterxml.jackson.databind.node.ArrayNode processPrometheusResultsToJsonArray(com.fasterxml.jackson.databind.JsonNode jsonResponse1, com.fasterxml.jackson.databind.JsonNode jsonResponse2) throws IOException Merges two Prometheus JSON responses and processes the results into an ArrayNode. Each appId will have a map of metrics, where the key is the metric type (e.g., "total", "lastUpdated") and the value is the metric value.- Parameters:
jsonResponse1
- the first JSON response from a Prometheus queryjsonResponse2
- the second JSON response from a Prometheus query- Returns:
- an ArrayNode containing maps of metrics for each appId
- Throws:
IOException
- if there is an error processing the JSON responses
-