Skip to content

Commit

Permalink
Add runtime.jvm.gc.collection.count metric
Browse files Browse the repository at this point in the history
  • Loading branch information
felixbarny committed Mar 22, 2021
1 parent 4168c0b commit bcaab02
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class RuntimeMetricsTest extends AgentInstrumentationSpecification {
then:
conditions.eventually {
assert getMetrics().any { it.name == "runtime.jvm.gc.collection" }
assert getMetrics().any { it.name == "runtime.jvm.gc.collection.count" }
assert getMetrics().any { it.name == "runtime.jvm.memory.area" }
assert getMetrics().any { it.name == "runtime.jvm.memory.pool" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*
* <pre>
* runtime.jvm.gc.collection{gc="PS1"} 6.7
* runtime.jvm.gc.collection.count{gc="PS1"} 1
* </pre>
*/
public final class GarbageCollector {
Expand All @@ -51,6 +52,18 @@ public static void registerObservers() {
}
})
.build();
meter
.longSumObserverBuilder("runtime.jvm.gc.collection.count")
.setDescription("The number of collections that have occurred for a given JVM garbage collector.")
.setUnit("collections")
.setUpdater(
resultLongObserver -> {
for (int i = 0; i < garbageCollectors.size(); i++) {
resultLongObserver.observe(
garbageCollectors.get(i).getCollectionCount(), labelSets.get(i));
}
})
.build();
}

private GarbageCollector() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class SpringBootSmokeTest extends SmokeTest {
then: "JVM metrics are exported"
def metrics = new MetricsInspector(waitForMetrics())
metrics.hasMetricsNamed("runtime.jvm.gc.collection")
metrics.hasMetricsNamed("runtime.jvm.gc.collection.count")
metrics.hasMetricsNamed("runtime.jvm.memory.area")
metrics.hasMetricsNamed("runtime.jvm.memory.pool")

Expand Down

0 comments on commit bcaab02

Please sign in to comment.