System Metrics

Micrometer provides several binders for system monitoring:

System Disk Space Metrics

// Usage example
new DiskSpaceMetrics(new File(System.getProperty("user.dir"))).bindTo(registry);

assertThat(registry.get("disk.free").gauge().value()).isNotNaN().isGreaterThan(0);
assertThat(registry.get("disk.total").gauge().value()).isNotNaN().isGreaterThan(0);

System File Descriptor Metrics

// Usage example
new FileDescriptorMetrics(Tags.of("some", "tag")).bindTo(registry);

assertThat(registry.get("process.files.open").tags("some", "tag").gauge().value()).isGreaterThan(0);
assertThat(registry.get("process.files.max").tags("some", "tag").gauge().value()).isGreaterThan(0);

System Processor Metrics

// Instrumentation setup
new ProcessorMetrics().bindTo(registry);

// Usage example
assertThat(registry.get("system.cpu.usage").gauge().value()).isNotNegative();
assertThat(registry.get("process.cpu.usage").gauge().value()).isNotNegative();

System Uptime Metrics

// Usage example
MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
new UptimeMetrics(runtimeMXBean, emptyList()).bindTo(registry);

assertThat(registry.get("process.uptime").timeGauge().value()).isEqualTo(1.337);
assertThat(registry.get("process.start.time").timeGauge().value()).isEqualTo(4.711);