1.自定义EndPoint
@Component
@Endpoint(id = "xyEndPoint")
public class DubboEndPoint {
@ReadOperation
public Map<String, Object> read() {
return Collections.singletonMap("age", "30");
}
@WriteOperation
public void write() {
}
}
@ReadOperation:自定义读数据
@WriteOperation:自定义写数据
通常定义一个共享变量,用于读写。
2.自定义health
@Component
public class DubboThreadPoolHealthIndicator extends AbstractHealthIndicator {
@Override
protected void doHealthCheck(Builder builder) throws Exception {
builder.status(Status.UP);
}
}
自定义的health组件,一定要以HealthIndicator结尾,且以component的方式添加到容器中
3.自定义info
@Component
public class DubboInfo implements InfoContributor {
@Override
public void contribute(Builder builder) {
Map<String, Object> details = new HashMap<>();
details.put("application", "xy-rbac");
details.put("suthor", "jack.li");
details.put("order total", 100203);
builder.withDetails(details);
}
}
4.自定义Metrics
�
Metrics.counter("dubbo.counter", "poolSize", port).increment();
Timer timer = Metrics.timer("dubbo.request");
timer.record(() -> {
System.out.println("this is Metrics timer");
});
Metrics.gauge("dubbo.poolSize", tp.getPoolSize());
Metrics.gauge("dubbo.taskCount", tp.getTaskCount());
5.springboot健康检查
6.k8s 健康检查
1.添加k8s监控配置项
#k8s 环境健康检查探针
management.endpoint.health.probes.enabled=true
2.访问url检查应用是否健康
http://localhost:8080/actuator/health/liveness http://localhost:8080/actuator/health/readiness