代码改变世界

micrometer涉及到的一些监控指标的定义

2020-07-17 14:02  l_v_y_forever  阅读(1524)  评论(0)    收藏  举报

 

micrometer涉及到的一些监控指标的定义如下:

1、jvm.memory.used、jvm.memory.committed、jvm.memory.max的定义及描述如下,收集使用的类为io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics:

for (MemoryPoolMXBean memoryPoolBean : ManagementFactory.getPlatformMXBeans(MemoryPoolMXBean.class)) {
String area = MemoryType.HEAP.equals(memoryPoolBean.getType()) ? "heap" : "nonheap";
Iterable<Tag> tagsWithId = Tags.concat(tags, "id", memoryPoolBean.getName(), "area", area);

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

Gauge.builder("jvm.memory.committed", memoryPoolBean, (mem) -> getUsageValue(mem, MemoryUsage::getCommitted))
.tags(tagsWithId)
.description("The amount of memory in bytes that is committed for the Java virtual machine to use")
.baseUnit(BaseUnits.BYTES)
.register(registry);

Gauge.builder("jvm.memory.max", memoryPoolBean, (mem) -> getUsageValue(mem, MemoryUsage::getMax))
.tags(tagsWithId)
.description("The maximum amount of memory in bytes that can be used for memory management")
.baseUnit(BaseUnits.BYTES)
.register(registry);
}


2、jvm.buffer.count、jvm.buffer.memory.used、jvm.buffer.total.capacity的定义及描述如下,收集使用的类为io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics:

for (BufferPoolMXBean bufferPoolBean : ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) {
Iterable<Tag> tagsWithId = Tags.concat(tags, "id", bufferPoolBean.getName());

Gauge.builder("jvm.buffer.count", bufferPoolBean, BufferPoolMXBean::getCount)
.tags(tagsWithId)
.description("An estimate of the number of buffers in the pool")
.baseUnit(BaseUnits.BUFFERS)
.register(registry);

Gauge.builder("jvm.buffer.memory.used", bufferPoolBean, BufferPoolMXBean::getMemoryUsed)
.tags(tagsWithId)
.description("An estimate of the memory that the Java virtual machine is using for this buffer pool")
.baseUnit(BaseUnits.BYTES)
.register(registry);

Gauge.builder("jvm.buffer.total.capacity", bufferPoolBean, BufferPoolMXBean::getTotalCapacity)
.tags(tagsWithId)
.description("An estimate of the total capacity of the buffers in this pool")
.baseUnit(BaseUnits.BYTES)
.register(registry);
}

 

3、jvm.gc.max.data.size、jvm.gc.live.data.size、jvm.gc.memory.promoted、jvm.gc.memory.allocated、jvm.gc.concurrent.phase.time、jvm.gc.pause的定义及描述如下,收集使用的类为io.micrometer.core.instrument.binder.jvm.JvmGcMetrics:


double maxOldGen = getOldGen().map(mem -> getUsageValue(mem, MemoryUsage::getMax)).orElse(0.0);

AtomicLong maxDataSize = new AtomicLong((long) maxOldGen);
Gauge.builder("jvm.gc.max.data.size", maxDataSize, AtomicLong::get)
.tags(tags)
.description("Max size of old generation memory pool")
.baseUnit(BaseUnits.BYTES)
.register(registry);

AtomicLong liveDataSize = new AtomicLong(0L);

Gauge.builder("jvm.gc.live.data.size", liveDataSize, AtomicLong::get)
.tags(tags)
.description("Size of old generation memory pool after a full GC")
.baseUnit(BaseUnits.BYTES)
.register(registry);

Counter promotedBytes = Counter.builder("jvm.gc.memory.promoted").tags(tags)
.baseUnit(BaseUnits.BYTES)
.description("Count of positive increases in the size of the old generation memory pool before GC to after GC")
.register(registry);

Counter allocatedBytes = Counter.builder("jvm.gc.memory.allocated").tags(tags)
.baseUnit(BaseUnits.BYTES)
.description("Incremented for an increase in the size of the young generation memory pool after one GC to before the next")
.register(registry);
if (isConcurrentPhase(gcCause)) {//是否是使用CMS进行垃圾回收
Timer.builder("jvm.gc.concurrent.phase.time")
.tags(tags)
.tags("action", gcAction, "cause", gcCause)
.description("Time spent in concurrent phase")
.register(registry)
.record(duration, TimeUnit.MILLISECONDS);
} else {
Timer.builder("jvm.gc.pause")
.tags(tags)
.tags("action", gcAction, "cause", gcCause)
.description("Time spent in GC pause")
.register(registry)
.record(duration, TimeUnit.MILLISECONDS);
}

4、jvm.threads.peak、jvm.threads.daemon、jvm.threads.live、jvm.threads.states的定义及描述如下,收集使用的类为io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics:

ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();

Gauge.builder("jvm.threads.peak", threadBean, ThreadMXBean::getPeakThreadCount)
.tags(tags)
.description("The peak live thread count since the Java virtual machine started or peak was reset")
.baseUnit(BaseUnits.THREADS)
.register(registry);

Gauge.builder("jvm.threads.daemon", threadBean, ThreadMXBean::getDaemonThreadCount)
.tags(tags)
.description("The current number of live daemon threads")
.baseUnit(BaseUnits.THREADS)
.register(registry);

Gauge.builder("jvm.threads.live", threadBean, ThreadMXBean::getThreadCount)
.tags(tags)
.description("The current number of live threads including both daemon and non-daemon threads")
.baseUnit(BaseUnits.THREADS)
.register(registry);

for (Thread.State state : Thread.State.values()) {
Gauge.builder("jvm.threads.states", threadBean, (bean) -> getThreadStateCount(bean, state))
.tags(Tags.concat(tags, "state", getStateTagValue(state)))
.description("The current number of threads having " + state + " state")
.baseUnit(BaseUnits.THREADS)
.register(registry);
}

5、system.cpu.count、system.load.average.1m、system.cpu.usage、process.cpu.usage的定义及描述如下,收集使用的类为io.micrometer.core.instrument.binder.system.ProcessorMetrics:

public ProcessorMetrics(Iterable<Tag> tags) {
this.tags = tags;
this.operatingSystemBean = ManagementFactory.getOperatingSystemMXBean();
this.operatingSystemBeanClass = getFirstClassFound(OPERATING_SYSTEM_BEAN_CLASS_NAMES);
this.systemCpuUsage = detectMethod("getSystemCpuLoad");
this.processCpuUsage = detectMethod("getProcessCpuLoad");
}

@Override
public void bindTo(MeterRegistry registry) {
Runtime runtime = Runtime.getRuntime();
Gauge.builder("system.cpu.count", runtime, Runtime::availableProcessors)
.tags(tags)
.description("The number of processors available to the Java virtual machine")
.register(registry);

if (operatingSystemBean.getSystemLoadAverage() >= 0) {
Gauge.builder("system.load.average.1m", operatingSystemBean, OperatingSystemMXBean::getSystemLoadAverage)
.tags(tags)
.description("The sum of the number of runnable entities queued to available processors and the number " +
"of runnable entities running on the available processors averaged over a period of time")
.register(registry);
}

if (systemCpuUsage != null) {
Gauge.builder("system.cpu.usage", operatingSystemBean, x -> invoke(systemCpuUsage))
.tags(tags)
.description("The \"recent cpu usage\" for the whole system")
.register(registry);
}

if (processCpuUsage != null) {
Gauge.builder("process.cpu.usage", operatingSystemBean, x -> invoke(processCpuUsage))
.tags(tags)
.description("The \"recent cpu usage\" for the Java Virtual Machine process")
.register(registry);
}
}

6、process.files.open、process.files.max的定义及描述如下,收集使用的类为io.micrometer.core.instrument.binder.system.FileDescriptorMetrics:

if (openFilesMethod != null) {
Gauge.builder("process.files.open", osBean, x -> invoke(openFilesMethod))
.tags(tags)
.description("The open file descriptor count")
.baseUnit(BaseUnits.FILES)
.register(registry);
}

if (maxFilesMethod != null) {
Gauge.builder("process.files.max", osBean, x -> invoke(maxFilesMethod))
.tags(tags)
.description("The maximum file descriptor count")
.baseUnit(BaseUnits.FILES)
.register(registry);
}

7、process.uptime、process.start.time的定义及描述如下,收集使用的类为io.micrometer.core.instrument.binder.system.UptimeMetrics:

public UptimeMetrics(Iterable<Tag> tags) {
this(ManagementFactory.getRuntimeMXBean(), tags);
}

// VisibleForTesting
UptimeMetrics(RuntimeMXBean runtimeMXBean, Iterable<Tag> tags) {
this.runtimeMXBean = runtimeMXBean;
this.tags = tags;
}

@Override
public void bindTo(MeterRegistry registry) {
TimeGauge.builder("process.uptime", runtimeMXBean, TimeUnit.MILLISECONDS, RuntimeMXBean::getUptime)
.tags(tags)
.description("The uptime of the Java virtual machine")
.register(registry);

TimeGauge.builder("process.start.time", runtimeMXBean, TimeUnit.MILLISECONDS, RuntimeMXBean::getStartTime)
.tags(tags)
.description("Start time of the process since unix epoch.")
.register(registry);
}

以上使用的micrometer的版本为:

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.3.6</version>
</dependency>