Skip to content

Java Garbage Collection Health Check, based on percentage of time spent collecting garbage

License

Notifications You must be signed in to change notification settings

dvbern/gc-health-check

Repository files navigation

Garbage Collection Health Check

This tiny library provides a simply metric for garbage collection usage: the percentage of time that the JVM spends collecting garbage. The health check will report HEALTHY, if the percentage is below a specified threshold and UNHEALTHY otherwise.

The GC percentage is calculated based on the last health check access time. Thus, you most likely get false positives when checking too often. Checking the health every few seconds should suffice.

The calculations use some static properties. Thus you can only instantiate one GCHealthCheck. If you are using CDI, you can simply use a Producer as follows:

@ApplicationScoped
public class HealthCheck {

	private GCHealthCheck gcHealthCheck = null;

	@Produces
	public GCHealthCheck produceGCHealthCheck() {
		return gcHealthCheck;
	}

	@PostConstruct
	public void init() {
		int threshold = 20;
		gcHealthCheck = GCHealthCheck.init(threshold);
	}
}

About

Java Garbage Collection Health Check, based on percentage of time spent collecting garbage

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages