首页  

springboot2集成业务指标     所属分类 springboot 浏览量 1126
实现 MeterBinder 接口  添加业务指标
bindTo 方法,将采集到的指标注册到 MeterRegistry


import demo.metrics.AppMetrics;

@Configuration
public class MetricsConfig  {
	@Bean
	public AppMetrics appMetrics(){
	    return new AppMetrics();
	}
}


import io.micrometer.core.instrument.FunctionCounter;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.MeterBinder;
import util.MetricsUtil;

public class AppMetrics implements MeterBinder{
	
	@Override
    public void bindTo(MeterRegistry meterRegistry) {
		System.out.println("\n***************\n\n\nmeterRegistry="+meterRegistry+","+meterRegistry.getClass());
		// io.micrometer.prometheus.PrometheusMeterRegistry@36a6307
        Gauge.builder("statusInvokeCount", MetricsUtil.statusInvokeCount, c -> c.get())
                // .tags("host", "localhost")
                // .description("demo of custom meter binder")
                .register(meterRegistry);
        // lambada 无法打断点 换成 AtomicLongToDouble
        FunctionCounter.builder("statusInvokeCount2", MetricsUtil.statusInvokeCount, new AtomicLongToDouble()).register(meterRegistry);
        // # TYPE statusInvokeCount2_total counter
        // statusInvokeCount2_total 3.0
        // # TYPE statusInvokeCount gauge
        // statusInvokeCount 3.0
    }
	
}


public abstract class MetricsUtil {
	public static final AtomicLong statusInvokeCount = new AtomicLong();
	
	
	
完整代码
https://gitee.com/dyyx/springboothello
	
	
 SpringBoot的指标数据 

上一篇     下一篇
RocketMQ Kafka 简单比较

如何手工触发fullgc

mongodb简介

Object的hashCode和equals方法

面向对象 六原则 一法则

为何RedisCluster设计成16384个槽