2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.main
22 import arrow.syntax.function.memoize
23 import io.micrometer.core.instrument.Clock
24 import io.micrometer.core.instrument.Counter
25 import io.micrometer.core.instrument.MeterRegistry
26 import io.micrometer.jmx.JmxConfig
27 import io.micrometer.jmx.JmxMeterRegistry
28 import org.onap.dcae.collectors.veshv.boundary.Metrics
31 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
34 class MicrometerMetrics(
35 private val registry: MeterRegistry = JmxMeterRegistry(JmxConfig.DEFAULT, Clock.SYSTEM)
38 private val receivedBytes = registry.counter("data.received.bytes")
39 private val receivedMsgCount = registry.counter("messages.received.count")
40 private val receivedMsgBytes = registry.counter("messages.received.bytes")
41 private val sentCountTotal = registry.counter("messages.sent.count")
44 registry.gauge("messages.processing.count", this) {
45 (receivedMsgCount.count() - sentCountTotal.count()).coerceAtLeast(0.0)
49 private val sentCount = { topic: String ->
50 registry.counter("messages.sent.count", "topic", topic)
51 }.memoize<String, Counter>()
54 override fun notifyBytesReceived(size: Int) {
55 receivedBytes.increment(size.toDouble())
58 override fun notifyMessageReceived(size: Int) {
59 receivedMsgCount.increment()
60 receivedMsgBytes.increment(size.toDouble())
63 override fun notifyMessageSent(topic: String) {
64 sentCountTotal.increment()
65 sentCount(topic).increment()