Skip to content

Commit

Permalink
Fix time unit for process_cpu_seconds_total #881
Browse files Browse the repository at this point in the history
Signed-off-by: Fabian Stäber <fabian@fstab.de>
  • Loading branch information
fstab committed Oct 22, 2023
1 parent 18bdc33 commit ca75666
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void register(PrometheusRegistry registry) {
// 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));
callback.call(Unit.nanosToSeconds(processCpuTime));
}
} catch (Exception ignored) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.File;
import java.io.IOException;
import java.lang.management.RuntimeMXBean;
import java.util.concurrent.TimeUnit;

import static io.prometheus.metrics.instrumentation.jvm.TestUtil.convertToOpenMetricsFormat;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -29,7 +30,7 @@ public class ProcessMetricsTest {

@Before
public void setUp() throws IOException {
when(sunOsBean.getProcessCpuTime()).thenReturn(72L);
when(sunOsBean.getProcessCpuTime()).thenReturn(TimeUnit.MILLISECONDS.toNanos(72));
when(sunOsBean.getOpenFileDescriptorCount()).thenReturn(127L);
when(sunOsBean.getMaxFileDescriptorCount()).thenReturn(244L);
when(runtimeBean.getStartTime()).thenReturn(37100L);
Expand Down

0 comments on commit ca75666

Please sign in to comment.