Skip to content

Commit f0edda4

Browse files
authored
Merge pull request quarkusio#47554 from contrib-src-openly/main
Add HTTP server and client active network connection gauge metrics
2 parents edfebf0 + 55e9fc9 commit f0edda4

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

extensions/micrometer/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/VertxHttpClientMetricsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void testWebClientMetrics() {
8989
Assertions.assertEquals("HELLO", client.post("hello"));
9090

9191
Assertions.assertNotNull(getMeter("http.client.connections").longTaskTimer());
92+
Assertions.assertNotNull(getMeter("http.client.active.connections").gauge());
9293

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

109111
Assertions.assertEquals(1, registry.find("http.client.requests")
110112
.tag("uri", "root")

extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/binder/vertx/NetworkMetrics.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package io.quarkus.micrometer.runtime.binder.vertx;
22

3+
import java.util.concurrent.atomic.LongAdder;
4+
35
import io.micrometer.core.instrument.Counter;
46
import io.micrometer.core.instrument.DistributionSummary;
7+
import io.micrometer.core.instrument.Gauge;
58
import io.micrometer.core.instrument.LongTaskTimer;
69
import io.micrometer.core.instrument.Meter;
710
import io.micrometer.core.instrument.MeterRegistry;
@@ -16,14 +19,17 @@ public class NetworkMetrics implements TCPMetrics<LongTaskTimer.Sample> {
1619
final DistributionSummary received;
1720
final DistributionSummary sent;
1821
final Meter.MeterProvider<Counter> exceptionCounter;
22+
final Gauge activeConnections;
1923

2024
final Tags tags;
2125
private final LongTaskTimer connDuration;
26+
private final LongAdder connCount;
2227

2328
public NetworkMetrics(MeterRegistry registry, Tags tags, String prefix, String receivedDesc, String sentDesc,
24-
String connDurationDesc) {
29+
String connDurationDesc, String connCountDesc) {
2530
this.registry = registry;
2631
this.tags = tags == null ? Tags.empty() : tags;
32+
connCount = new LongAdder();
2733
received = DistributionSummary.builder(prefix + ".bytes.read")
2834
.description(receivedDesc)
2935
.tags(this.tags)
@@ -38,6 +44,10 @@ public NetworkMetrics(MeterRegistry registry, Tags tags, String prefix, String r
3844
.register(registry);
3945
exceptionCounter = Counter.builder(prefix + ".errors")
4046
.withRegistry(registry);
47+
activeConnections = Gauge.builder(prefix + ".active.connections", connCount, LongAdder::longValue)
48+
.description(connCountDesc)
49+
.tags(this.tags)
50+
.register(registry);
4151
}
4252

4353
/**
@@ -53,6 +63,7 @@ public NetworkMetrics(MeterRegistry registry, Tags tags, String prefix, String r
5363
*/
5464
@Override
5565
public LongTaskTimer.Sample connected(SocketAddress remoteAddress, String remoteName) {
66+
connCount.increment();
5667
return connDuration.start();
5768
}
5869

@@ -65,6 +76,7 @@ public LongTaskTimer.Sample connected(SocketAddress remoteAddress, String remote
6576
*/
6677
@Override
6778
public void disconnected(LongTaskTimer.Sample sample, SocketAddress remoteAddress) {
79+
connCount.decrement();
6880
if (sample == null) {
6981
return;
7082
}

extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/binder/vertx/VertxTcpClientMetrics.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public class VertxTcpClientMetrics extends NetworkMetrics {
99
super(registry, tags, prefix,
1010
"Number of bytes received by the client",
1111
"Number of bytes sent by the client",
12-
"The duration of the connections");
12+
"The duration of the connections",
13+
"Number of connections to the remote host currently opened");
1314
}
1415

1516
}

extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/binder/vertx/VertxTcpServerMetrics.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public class VertxTcpServerMetrics extends NetworkMetrics {
99
super(registry, tags, prefix,
1010
"Number of bytes received by the server",
1111
"Number of bytes sent by the server",
12-
"The duration of the connections");
12+
"The duration of the connections",
13+
"Number of opened connections to the HTTP Server");
1314
}
1415

1516
}

0 commit comments

Comments
 (0)