Jon Thoms
Jon Thoms

Reputation: 10777

What unit of measurement is the Spring Actuator Metric "jvm.memory.used"?

I've recently started using Spring Boot Actuator for a pre-existing service. I'm currently using version 2.0.1.RELEASE. I've managed to get Spring Actuator up and running, and I can see the /actuator/metrics page up and running with metrics. I can access metrics like the jvm.memory.used metric at its respective URL with various tags for drill-down options. When I access the URL http://localhost:8080/actuator/metrics/jvm.memory.used, I get the following output:

{"name":"jvm.memory.used","measurements":[{"statistic":"VALUE","value":7.71444944E8}],"availableTags":[{"tag":"area","values":["heap","nonheap"]},{"tag":"id","values":["Compressed Class Space","PS Survivor Space","PS Old Gen","Metaspace","PS Eden Space","Code Cache"]}]}

So, I can see that my JVM memory used is "7.71444944E8" (or more simply just "771444944"). I'm curious, however, what the unit of measurement is, as the value, itself, is meaningless. Is it just bytes? Might it be MB or GB, though? I'm assuming that the answer is just bytes. That would make sense, but I can't find any underlying reason to support that thus far.

I've tried googling, but to no avail. I consulted with what appears to be the canonical Spring Actuator doc but I couldn't find any answers there, either. I also found a similar SO Q&A on the http.server.requests "TOTAL TIME" metric. That question's accepted answer stated that it depended on the MeterRegistry implementation in my service. Note that I have no such implementation. I'm just playing with the web API for now. Moreover, that answer appeared to be specific to time units which I'm not dealing with. Any help would be greatly appreciated.

Upvotes: 1

Views: 5134

Answers (1)

Mark Bramnik
Mark Bramnik

Reputation: 42541

Well, I assume you're using micrometer under the hood.

Micrometer is a spring boot 2 metrics library.

Even if you don't use any store to manage metrics (like Prometheus, DataDog, etc.) you still have some default registry.

Now, micrometer monitors the JVM and provides some "out-of-the" box metrics. Here you can find an information about it.

It uses a concept called "binders" and you're interested in JvmMemoryMetrics. Lets take a look at the source-code of this binder.

Note the following code:


            Gauge.builder("jvm.memory.used", memoryPoolBean, (mem) -> getUsageValue(mem, MemoryUsage::getUsed))
                .tags(tagsWithId)
                .description("The amount of used memory")
                .baseUnit(BaseUnits.BYTES)
                .register(registry);

It basically takes the information from JMX of JVM memory that is available for each java process and builds a gauge that shows the information in bytes.

So its your case and its shown in actuator.

Upvotes: 4

Related Questions