# Java containers

## Enabling JVM metrics collection

{% hint style="info" %}
The **Coroot agent** is disabled by default. Once enabled, PerfectScale automatically detects Java containers and starts collecting JVM metrics.&#x20;

Add the following parameter when deploying the PerfectScale agent to enable this feature:

```yaml
--set settings.corootNodeAgent.enabled=true
```

{% endhint %}

{% hint style="warning" %}
Coroot supports only Linux nodes.
{% endhint %}

Once the Coroot agent is installed, PerfectScale starts identifying Java containers running in your Kubernetes environment and collecting JVM metrics from them. By continuously analyzing them, PerfectScale provides granular visibility into resource usage, identifying potential bottlenecks. Based on this analysis, PerfectScale generates tailored recommendations to help ensure that your services remain efficient and maintain consistent performance.

### Deploy coroot pods to specific nodes

If your cluster includes both Linux and Windows nodes, make sure to set a nodeSelector for Linux when deploying workloads that are not Windows-compatible.

YAML values file example:

```yaml
coroot:
  nodeSelector:
    kubernetes.io/os: linux
```

Helm command example:

```
helm upgrade --install perfectscale ..... \
  --set coroot.nodeSelector."kubernetes\.io/os"=linux \
  perfectscale/exporter
```

To restrict workloads to a specific set of nodes (for example, those labeled `component=java`), you can combine multiple node selectors.

YAML values file example:

```
coroot:
  nodeSelector:
    kubernetes.io/os: linux
    component: java
```

Helm command example:

```
helm upgrade --install perfectscale ..... \
  --set coroot.nodeSelector."kubernetes\.io/os"=linux \
  --set coroot.nodeSelector.component=java \
  perfectscale/exporter
```

## Java usage visibility

When a Java container is detected, PerfectScale automatically starts collecting key JVM metrics. By continuously analyzing this data, PerfectScale delivers deep visibility into Heap, Non-Heap, and Garbage Collector usage patterns over time. By providing tailored, data-driven optimization recommendations, teams can seamlessly optimize resource utilization and cut cloud costs safely, ensuring their services remain efficient and maintain consistent performance.

<figure><img src="https://3591580169-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzCh9aABpk7yLeToPr6vk%2Fuploads%2FCxxvMIbmmPtNcQGov1UU%2Fimage.png?alt=media&#x26;token=04b5573d-5efe-427e-b2bc-c079f65a17c1" alt=""><figcaption><p>Java containers resource utilization</p></figcaption></figure>

When heap parameters are not set, the relevant indicator will appear under container flags, along with the calculated `-Xms` and `-Xmx` values.

<figure><img src="https://3591580169-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzCh9aABpk7yLeToPr6vk%2Fuploads%2FIGgDMGVRmyBa3hnXbkDF%2Fimage.png?alt=media&#x26;token=251ec1f0-6a6d-4f11-a7ff-d2717057be6b" alt=""><figcaption><p>HeapSize is not set</p></figcaption></figure>

{% hint style="info" %}
PerfectScale respects explicitly set heap parameters when providing recommendations or applying automation.
{% endhint %}

When heap parameters are explicitly set, PerfectScale always respects them for resource recommendations and automation. The configured values are also displayed under the Container Flags section.

<figure><img src="https://3591580169-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzCh9aABpk7yLeToPr6vk%2Fuploads%2F2Zfcra3DMJdCUhtfzV1f%2Fimage.png?alt=media&#x26;token=ff7cc04a-3356-4572-9429-09175140dbf4" alt=""><figcaption><p>HeapSize is set</p></figcaption></figure>

{% hint style="warning" %}
When recommendations **exceed the MaxHeapSize** or **fall below the MinHeapSize**, Automation will not apply the recommendation to ensure that explicitly set values are respected. The relevant tooltip will be displayed.
{% endhint %}

PerfectScale also provides detailed visibility into Garbage Collector time, helping teams better understand trends such as rising GC activity, correlate spikes with performance or latency issues, validate the impact of optimization changes, and plan capacity more effectively. By monitoring GC behavior alongside memory usage, teams can ensure Java workloads remain stable and efficient.

<figure><img src="https://3591580169-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzCh9aABpk7yLeToPr6vk%2Fuploads%2FuXfnjVH0AMT1JvO5ySvV%2Fimage.png?alt=media&#x26;token=688130ff-ac7a-470f-8077-23a3da25f433" alt=""><figcaption><p>GC time</p></figcaption></figure>

On the right side, you can also view additional Garbage Collector parameters, including the ActiveProcessorCount and GC type:

* ZGC
* ShenandoahGC
* G1GC
* ParallelGC
* ParallelOldGC
* ConcMarkSweepGC
* SerialGC

{% hint style="info" %}
The JVM maps millicores using the following logic: 1000m = 1 CPU, and 1001m = 2 CPUs
{% endhint %}

## Disabling JVM metrics collection

To limit JVM metrics collection, you need to disable the deployment  `psc-coroot-node-agent` when [installing the PerfectScale Agent](https://docs.perfectscale.io/2.0-self-hosted-or-perfectscale-documentation/getting-started/how-to-onboard-a-cluster#cluster-configuration) by adding the following parameter to the installation helm:

```
--set settings.corootNodeAgent.enabled=false
```
