Closed as not planned
Closed as not planned
Description
When using buildpacks / bootBuildImage, the Java Buildpack Memory Calculator uses some heuristics to calculate memory parameters.
Those include an assumed number of loaded classes and maximum tread count. We'd like to have alerts, when those values were underestimated, but currently there are no metrics available to write these alerts.
We're currently doing something like the following, but I believe adding this to the actuator-autoconfigure project would be beneficial for other, too.
@AutoConfiguration(after = [MetricsAutoConfiguration::class, CompositeMeterRegistryAutoConfiguration::class])
@ConditionalOnClass(MeterRegistry::class)
@ConditionalOnBean(MeterRegistry::class)
class JvmMemoryCalculatorMetricsAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty("bpl.jvm.thread.count")
fun jvmMemoryCalculatorMetrics(): JvmMemoryCalculatorMetrics = JvmMemoryCalculatorMetrics()
}
class JvmMemoryCalculatorMetrics : MeterBinder {
override fun bindTo(registry: MeterRegistry) {
// These environment variables are always set when running an image build with the Buildpack
val threadCount = System.getenv("BPL_JVM_THREAD_COUNT")?.toLong()
val classCount = System.getenv("BPI_JVM_CLASS_COUNT")?.toLong()
if (threadCount != null) {
Gauge.builder("jvm.buildpack.memorycalculator.threads") { threadCount }
.description("Number of threads used by the JVM Memory Calculator as the " +
"maximum number of threads")
.baseUnit(BaseUnits.THREADS)
.register(registry)
}
if (classCount != null) {
Gauge.builder("jvm.buildpack.memorycalculator.classes") { classCount }
.description("Number of classes used by the JVM Memory Calculator as the " +
"maximum number of loaded classes")
.baseUnit(BaseUnits.CLASSES)
.register(registry)
}
}
}