prometheus / client_java

Prometheus instrumentation library for JVM applications

Home Page:http://prometheus.github.io/client_java/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Metric `process_cpu_seconds_total` is in wrong order of magnitude

novoj opened this issue · comments

There is following logic in https://github.com/prometheus/client_java/blob/main/prometheus-metrics-instrumentation-jvm/src/main/java/io/prometheus/metrics/instrumentation/jvm/ProcessMetrics.java file:

try {
	// There exist at least 2 similar but unrelated UnixOperatingSystemMXBean interfaces, in
	// com.sun.management and com.ibm.lang.management. Hence use reflection and recursively go
	// through implemented interfaces until the method can be made accessible and invoked.
	Long processCpuTime = callLongGetter("getProcessCpuTime", osBean);
	if (processCpuTime != null) {
		callback.call(Unit.millisToSeconds(processCpuTime));
	}
} catch (Exception ignored) {
}

Problem is that the method defined on interface: com.sun.management.OperatingSystemMXBean returns value in nanoseconds. According to this documentation:

   /**
     * Returns the CPU time used by the process on which the Java
     * virtual machine is running in nanoseconds.  The returned value
     * is of nanoseconds precision but not necessarily nanoseconds
     * accuracy.  This method returns {@code -1} if the
     * the platform does not support this operation.
     *
     * @return the CPU time used by the process in nanoseconds,
     * or {@code -1} if this operation is not supported.
     */

Sorry, I didn't check the current implementation properly. It's already fixed. Closing the issue.