Skip to content

Add JVM Buildpack Memory Calculator values to actuator-autoconfigure Metrics #42458

Closed as not planned
@michael-arndt-gcx

Description

@michael-arndt-gcx

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)
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fixstatus: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions