---
title: "PE - Examples"
canonical: "https://support.appfire.com/space/PE/14680076/PE%20-%20Examples"
format: markdown
---
We will use the following example to show how you can measure Java garbage collection with Prometheus.

GarbageCollector statistics is one of the of metrics that the Java/JVM client library exposes.

If you invoke `DefaultExports.initialize();` the Java client will expose a number of out of the box JVM metrics: 

- Memory pools
- Memory allocations
- Buffer pools
- Threads
- JVM version
- Loaded classes
- Garbage collection

The GarbageCollector statistics comes from [GarbageCollectorMXBean](https://docs.oracle.com/javase/8/docs/api/java/lang/management/GarbageCollectorMXBean.html), and is exposed as the `jvm_gc_collection_seconds` summary.  
 In particular, `jvm_gc_collection_seconds_count` is responsible for the number of GCs, and `jvm_gc_collection_seconds_sum`  deals with for how long they were taken.

These are the counters, so we can take a rate:

![image](media://9c72b96d-0842-403b-b9f6-9c7574d66638)

We can see that `PS Scavenge` is happening once every 2 seconds or so, and `PS MarkSweek` is rare. You might ask which of those are the young generation and which the old/tenured, but this is not something the JVM exposes so you have to know this in your setup [given the name](https://blogs.oracle.com/jonthecollector/our-collectors).

A GC every 2 seconds sounds excessive, and you can check how long it takes:

![image](media://91b6591a-dd46-4e04-9bf3-bb8656c6ceb8)

They are only taking about 1.5ms on average, which is acceptable. The single `PS MarkSweek` takes 45ms, but they are rare.

Finally, using `rate(jvm_gc_collection_seconds_sum[1m])` you can see what proportion of time each type of GC is taking up, which per the previous numbers is under 0.1% which is not a concern at all.

## See also

[Configuring Prometheus Exporters](https://appfire.atlassian.net/wiki/spaces/PE/pages/14680254)

[JVM metrics](https://appfire.atlassian.net/wiki/spaces/PE/pages/14680629/PE+-+Using+Prometheus+Exporter+for+Jira#PE-UsingPrometheusExporterforJira-JVMMetrics-seeexamplesbelow)