From 30488f1922f789c5b8e18934456968aa354c9671 Mon Sep 17 00:00:00 2001 From: Piotr Jaszczyk Date: Mon, 17 Dec 2018 13:22:52 +0100 Subject: Metric: Message latency Defined as a difference between now and vesHeader.lastEpochTime. Change-Id: I4aa97e8efc13cb0039fde38b4fd2aa6411c7b89a Issue-ID: DCAEGEN2-1036 Signed-off-by: Piotr Jaszczyk --- .../collectors/veshv/main/metrics/MicrometerMetrics.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'sources/hv-collector-main/src/main') diff --git a/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/metrics/MicrometerMetrics.kt b/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/metrics/MicrometerMetrics.kt index f060426d..d35e17d6 100644 --- a/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/metrics/MicrometerMetrics.kt +++ b/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/metrics/MicrometerMetrics.kt @@ -30,9 +30,10 @@ import io.micrometer.prometheus.PrometheusConfig import io.micrometer.prometheus.PrometheusMeterRegistry import org.onap.dcae.collectors.veshv.boundary.Metrics import org.onap.dcae.collectors.veshv.domain.WireFrameMessage -import org.onap.dcae.collectors.veshv.model.MessageDropCause import org.onap.dcae.collectors.veshv.model.ClientRejectionCause +import org.onap.dcae.collectors.veshv.model.MessageDropCause import org.onap.dcae.collectors.veshv.model.RoutedMessage +import org.onap.dcae.collectors.veshv.utils.TimeUtils.epochMicroToInstant import java.time.Duration import java.time.Instant @@ -49,6 +50,9 @@ class MicrometerMetrics internal constructor( private val receivedMsgCount = registry.counter(name(MESSAGES, RECEIVED, COUNT)) private val receivedMsgBytes = registry.counter(name(MESSAGES, RECEIVED, BYTES)) + private val processingTime = registry.timer(name(MESSAGES, PROCESSING, TIME)) + private val totalLatency = registry.timer(name(MESSAGES, LATENCY, TIME)) + private val sentCountTotal = registry.counter(name(MESSAGES, SENT, COUNT)) private val sentToTopicCount = { topic: String -> registry.counter(name(MESSAGES, SENT, TOPIC, COUNT), TOPIC, topic) @@ -59,8 +63,6 @@ class MicrometerMetrics internal constructor( registry.counter(name(MESSAGES, DROPPED, CAUSE, COUNT), CAUSE, cause) }.memoize() - private val processingTime = registry.timer(name(MESSAGES, PROCESSING, TIME)) - private val clientsRejectedCount = registry.counter(name(CLIENTS, REJECTED, COUNT)) private val clientsRejectedCauseCount = { cause: String -> registry.counter(name(CLIENTS, REJECTED, CAUSE, COUNT), CAUSE, cause) @@ -90,9 +92,12 @@ class MicrometerMetrics internal constructor( } override fun notifyMessageSent(msg: RoutedMessage) { + val now = Instant.now() sentCountTotal.increment() sentToTopicCount(msg.topic).increment() - processingTime.record(Duration.between(msg.message.wtpFrame.receivedAt, Instant.now())) + + processingTime.record(Duration.between(msg.message.wtpFrame.receivedAt, now)) + totalLatency.record(Duration.between(epochMicroToInstant(msg.message.header.lastEpochMicrosec), now)) } override fun notifyMessageDropped(cause: MessageDropCause) { @@ -121,6 +126,7 @@ class MicrometerMetrics internal constructor( internal const val TOPIC = "topic" internal const val DROPPED = "dropped" internal const val TIME = "time" - fun name(vararg name: String) = "$PREFIX.${name.joinToString(".")}" + internal const val LATENCY = "latency" + internal fun name(vararg name: String) = "$PREFIX.${name.joinToString(".")}" } } -- cgit 1.2.3-korg