Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void testWebClientMetrics() {
Assertions.assertEquals("HELLO", client.post("hello"));

Assertions.assertNotNull(getMeter("http.client.connections").longTaskTimer());
Assertions.assertNotNull(getMeter("http.client.active.connections").gauge());

// Body sizes
double expectedBytesWritten = sizeBefore + 5;
Expand All @@ -105,6 +106,7 @@ void testWebClientMetrics() {
// Because of the different tag, the timer got called a single time
return getMeter("http.client.requests").timer().count() == 1;
});
await().until(() -> getMeter("http.client.active.connections").gauge().value() == 1);

Assertions.assertEquals(1, registry.find("http.client.requests")
.tag("uri", "root")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.quarkus.micrometer.runtime.binder.vertx;

import java.util.concurrent.atomic.LongAdder;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.DistributionSummary;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.LongTaskTimer;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.MeterRegistry;
Expand All @@ -16,14 +19,17 @@ public class NetworkMetrics implements TCPMetrics<LongTaskTimer.Sample> {
final DistributionSummary received;
final DistributionSummary sent;
final Meter.MeterProvider<Counter> exceptionCounter;
final Gauge activeConnections;

final Tags tags;
private final LongTaskTimer connDuration;
private final LongAdder connCount;

public NetworkMetrics(MeterRegistry registry, Tags tags, String prefix, String receivedDesc, String sentDesc,
String connDurationDesc) {
String connDurationDesc, String connCountDesc) {
this.registry = registry;
this.tags = tags == null ? Tags.empty() : tags;
connCount = new LongAdder();
received = DistributionSummary.builder(prefix + ".bytes.read")
.description(receivedDesc)
.tags(this.tags)
Expand All @@ -38,6 +44,10 @@ public NetworkMetrics(MeterRegistry registry, Tags tags, String prefix, String r
.register(registry);
exceptionCounter = Counter.builder(prefix + ".errors")
.withRegistry(registry);
activeConnections = Gauge.builder(prefix + ".active.connections", connCount, LongAdder::longValue)
.description(connCountDesc)
.tags(this.tags)
.register(registry);
}

/**
Expand All @@ -53,6 +63,7 @@ public NetworkMetrics(MeterRegistry registry, Tags tags, String prefix, String r
*/
@Override
public LongTaskTimer.Sample connected(SocketAddress remoteAddress, String remoteName) {
connCount.increment();
return connDuration.start();
}

Expand All @@ -65,6 +76,7 @@ public LongTaskTimer.Sample connected(SocketAddress remoteAddress, String remote
*/
@Override
public void disconnected(LongTaskTimer.Sample sample, SocketAddress remoteAddress) {
connCount.decrement();
if (sample == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class VertxTcpClientMetrics extends NetworkMetrics {
super(registry, tags, prefix,
"Number of bytes received by the client",
"Number of bytes sent by the client",
"The duration of the connections");
"The duration of the connections",
"Number of connections to the remote host currently opened");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class VertxTcpServerMetrics extends NetworkMetrics {
super(registry, tags, prefix,
"Number of bytes received by the server",
"Number of bytes sent by the server",
"The duration of the connections");
"The duration of the connections",
"Number of opened connections to the HTTP Server");
}

}
Loading