Skip to content

Commit

Permalink
Remove changes to GC Metrics and make threads started as Function Cou…
Browse files Browse the repository at this point in the history
…nter.
  • Loading branch information
lenin-jaganathan committed Feb 17, 2023
1 parent 641022b commit 5839559
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,17 @@ public void handleNotification(Notification notification, Object ref) {
CompositeData cd = (CompositeData) notification.getUserData();
GarbageCollectionNotificationInfo notificationInfo = GarbageCollectionNotificationInfo.from(cd);

String gcName = notificationInfo.getGcName();
String gcCause = notificationInfo.getGcCause();
String gcAction = notificationInfo.getGcAction();
GcInfo gcInfo = notificationInfo.getGcInfo();
long duration = gcInfo.getDuration();
if (isConcurrentPhase(gcCause, gcName)) {
Timer.builder("jvm.gc.concurrent.phase.time").tags(tags)
.tags("action", gcAction, "cause", gcCause, "gc_name", gcName)
if (isConcurrentPhase(gcCause, notificationInfo.getGcName())) {
Timer.builder("jvm.gc.concurrent.phase.time").tags(tags).tags("action", gcAction, "cause", gcCause)
.description("Time spent in concurrent phase").register(registry)
.record(duration, TimeUnit.MILLISECONDS);
}
else {
Timer.builder("jvm.gc.pause").tags(tags).tags("action", gcAction, "cause", gcCause, "gc", gcName)
Timer.builder("jvm.gc.pause").tags(tags).tags("action", gcAction, "cause", gcCause)
.description("Time spent in GC pause").register(registry)
.record(duration, TimeUnit.MILLISECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

import io.micrometer.common.lang.NonNullApi;
import io.micrometer.common.lang.NonNullFields;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.*;
import io.micrometer.core.instrument.binder.BaseUnits;
import io.micrometer.core.instrument.binder.MeterBinder;

Expand Down Expand Up @@ -66,9 +63,9 @@ public void bindTo(MeterRegistry registry) {
.description("The current number of live threads including both daemon and non-daemon threads")
.baseUnit(BaseUnits.THREADS).register(registry);

Gauge.builder("jvm.threads.started", threadBean, ThreadMXBean::getTotalStartedThreadCount).tags(tags)
FunctionCounter.builder("jvm.threads.started", threadBean, ThreadMXBean::getTotalStartedThreadCount).tags(tags)
.description(
"The total number of threads created and also started since the Java virtual machine started")
"The total number of application threads started in the JVM")
.baseUnit(BaseUnits.THREADS).register(registry);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ class JvmThreadMetricsTest {
void threadMetrics() {
MeterRegistry registry = new SimpleMeterRegistry();
new JvmThreadMetrics().bindTo(registry);
double initialThreadCount = registry.get("jvm.threads.started").gauge().value();
double initialThreadCount = registry.get("jvm.threads.started").functionCounter().count();

assertThat(registry.get("jvm.threads.live").gauge().value()).isGreaterThan(0);
assertThat(registry.get("jvm.threads.daemon").gauge().value()).isGreaterThan(0);
assertThat(registry.get("jvm.threads.peak").gauge().value()).isGreaterThan(0);
assertThat(registry.get("jvm.threads.states").tag("state", "runnable").gauge().value()).isGreaterThan(0);
assertThat(registry.get("jvm.threads.live").gauge().value()).isPositive();
assertThat(registry.get("jvm.threads.daemon").gauge().value()).isPositive();
assertThat(registry.get("jvm.threads.peak").gauge().value()).isPositive();
assertThat(registry.get("jvm.threads.states").tag("state", "runnable").gauge().value()).isPositive();

createBlockedThread();
assertThat(registry.get("jvm.threads.states").tag("state", "blocked").gauge().value()).isGreaterThan(0);
assertThat(registry.get("jvm.threads.states").tag("state", "waiting").gauge().value()).isGreaterThan(0);
assertThat(registry.get("jvm.threads.states").tag("state", "blocked").gauge().value()).isPositive();
assertThat(registry.get("jvm.threads.states").tag("state", "waiting").gauge().value()).isPositive();

createTimedWaitingThread();
assertThat(registry.get("jvm.threads.states").tag("state", "timed-waiting").gauge().value()).isGreaterThan(0);
assertThat(registry.get("jvm.threads.started").gauge().value()).isGreaterThan(initialThreadCount);
assertThat(registry.get("jvm.threads.states").tag("state", "timed-waiting").gauge().value()).isPositive();
assertThat(registry.get("jvm.threads.started").functionCounter().count()).isGreaterThan(initialThreadCount);
}

@Test
Expand Down

0 comments on commit 5839559

Please sign in to comment.