回答我自己的问题
- 我最终为JVM版本信息实现了这个:
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* Migrated From simpleclient_hotspot/src/main/java/io/prometheus/client/hotspot/VersionInfoExports.java
* Because its not included in Micrometer.
*/
@Component
public class JvmVersionInfoExports {
private static final Logger LOGGER = LoggerFactory.getLogger(JvmVersionInfoExports.class);
public JvmVersionInfoExports(MeterRegistry meterRegistry) {
LOGGER.info("Adding JVM Metrics");
Gauge.builder("jvm_info", () -> 1L)
.description("JVM version info")
.tag("version", System.getProperty("java.runtime.version", "unknown"))
.tag("vendor", System.getProperty("java.vm.vendor", "unknown"))
.tag("runtime", System.getProperty("java.runtime.name", "unknown"))
.register(meterRegistry);
}
}
- 我最终为操作系统版本信息实现了这个:
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component
public class OsVersionInfoExports {
private static final Logger LOGGER = LoggerFactory.getLogger(OsVersionInfoExports.class);
public OsVersionInfoExports(MeterRegistry meterRegistry) {
LOGGER.info("Adding OS Metrics");
Gauge.builder("os_info", () -> 1L)
.description("OS version info")
.tag("version", System.getProperty("os.version", "unknown"))
.tag("arch", System.getProperty("os.arch", "unknown"))
.tag("name", System.getProperty("os.name", "unknown"))
.register(meterRegistry);
}
}
尽管这些论文滥用了 Micrometer Gauge,但它们为我提供了兼容性,我需要使用 Micrometer 和 Prometheus HotSpot 库的混合来跨服务跟踪这些细节。