1.自定义EndPoint

  1. @Component
  2. @Endpoint(id = "xyEndPoint")
  3. public class DubboEndPoint {
  4. @ReadOperation
  5. public Map<String, Object> read() {
  6. return Collections.singletonMap("age", "30");
  7. }
  8. @WriteOperation
  9. public void write() {
  10. }
  11. }

@ReadOperation:自定义读数据

@WriteOperation:自定义写数据

通常定义一个共享变量,用于读写。

2.自定义health

  1. @Component
  2. public class DubboThreadPoolHealthIndicator extends AbstractHealthIndicator {
  3. @Override
  4. protected void doHealthCheck(Builder builder) throws Exception {
  5. builder.status(Status.UP);
  6. }
  7. }

自定义的health组件,一定要以HealthIndicator结尾,且以component的方式添加到容器中

3.自定义info

  1. @Component
  2. public class DubboInfo implements InfoContributor {
  3. @Override
  4. public void contribute(Builder builder) {
  5. Map<String, Object> details = new HashMap<>();
  6. details.put("application", "xy-rbac");
  7. details.put("suthor", "jack.li");
  8. details.put("order total", 100203);
  9. builder.withDetails(details);
  10. }
  11. }

4.自定义Metrics

  1. Metrics.counter("dubbo.counter", "poolSize", port).increment();
  2. Timer timer = Metrics.timer("dubbo.request");
  3. timer.record(() -> {
  4. System.out.println("this is Metrics timer");
  5. });
  6. Metrics.gauge("dubbo.poolSize", tp.getPoolSize());
  7. Metrics.gauge("dubbo.taskCount", tp.getTaskCount());

5.springboot健康检查

6.k8s 健康检查

1.添加k8s监控配置项

  1. #k8s 环境健康检查探针
  2. management.endpoint.health.probes.enabled=true

2.访问url检查应用是否健康

http://localhost:8080/actuator/health/liveness http://localhost:8080/actuator/health/readiness