From 3b76270f91ea2eb2c21abc341a10325480e26891 Mon Sep 17 00:00:00 2001 From: Nikita Smirnov <46124551+Nikita-Smirnov-Exactpro@users.noreply.github.com> Date: Tue, 16 Apr 2024 12:27:49 +0400 Subject: [PATCH] Rise `th2_component` metric with box name as `name` label value (#295) --- README.md | 7 ++++- .../schema/factory/AbstractCommonFactory.java | 2 ++ .../th2/common/metrics/ComponentMetric.kt | 30 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/exactpro/th2/common/metrics/ComponentMetric.kt diff --git a/README.md b/README.md index c12482e6..f9b0fac2 100644 --- a/README.md +++ b/README.md @@ -433,6 +433,10 @@ NOTES: * some metric labels are enumerations (`th2_type`: `MESSAGE_GROUP`, `EVENT`, ``;`message_type`: `RAW_MESSAGE`, `MESSAGE`) +COMMON METRICS: + +* th2_component (`name`): information about the current component + RABBITMQ METRICS: * th2_rabbitmq_message_size_publish_bytes (`th2_pin`, `th2_type`, `exchange`, `routing_key`): number of published @@ -509,7 +513,8 @@ dependencies { ### 5.10.1-dev -+ Use box name from `box.json` config as RabbitMQ connection name ++ Use box name from `box.json` config as RabbitMQ connection name ++ Rise `th2_component` metric with box name as `name` label value ### 5.10.0-dev diff --git a/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java b/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java index 8545a0de..17092061 100644 --- a/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java +++ b/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java @@ -28,6 +28,7 @@ import com.exactpro.th2.common.grpc.MessageID; import com.exactpro.th2.common.grpc.RawMessageBatch; import com.exactpro.th2.common.metrics.CommonMetrics; +import com.exactpro.th2.common.metrics.ComponentMetric; import com.exactpro.th2.common.metrics.MetricMonitor; import com.exactpro.th2.common.metrics.PrometheusConfiguration; import com.exactpro.th2.common.schema.box.configuration.BoxConfiguration; @@ -187,6 +188,7 @@ public void start() { // init exporter prometheusExporter.getOrNull(); + ComponentMetric.enable(getBoxConfiguration().getBoxName()); livenessMonitor.enable(); } diff --git a/src/main/kotlin/com/exactpro/th2/common/metrics/ComponentMetric.kt b/src/main/kotlin/com/exactpro/th2/common/metrics/ComponentMetric.kt new file mode 100644 index 00000000..4bb20cb4 --- /dev/null +++ b/src/main/kotlin/com/exactpro/th2/common/metrics/ComponentMetric.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2024 Exactpro (Exactpro Systems Limited) + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:JvmName("ComponentMetric") + +package com.exactpro.th2.common.metrics + +import io.prometheus.client.Gauge + +private val COMPONENT_METRIC: Gauge = Gauge.build( + "th2_component", + "Information about the current component" +).labelNames("name") + .register() + +internal fun enable(componentName: String) { + COMPONENT_METRIC.labels(componentName).set(1.0) +} \ No newline at end of file