Skip to content

Commit

Permalink
Rise th2_component metric with box name as name label value (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro authored Apr 16, 2024
1 parent 5d4d954 commit 3b76270
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ NOTES:
* some metric labels are
enumerations (`th2_type`: `MESSAGE_GROUP`, `EVENT`, `<customTag>`;`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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -187,6 +188,7 @@ public void start() {

// init exporter
prometheusExporter.getOrNull();
ComponentMetric.enable(getBoxConfiguration().getBoxName());
livenessMonitor.enable();
}

Expand Down
30 changes: 30 additions & 0 deletions src/main/kotlin/com/exactpro/th2/common/metrics/ComponentMetric.kt
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 3b76270

Please sign in to comment.