收集 Spring Cloud Resilience4J 断路器指标(预览版)Collect Spring Cloud Resilience4J Circuit Breaker Metrics (Preview)

本文档介绍了如何通过 Application Insights java 进程内代理收集 Spring Cloud Resilience4j 断路器指标。This document explains how to collect Spring Cloud Resilience4j Circuit Breaker Metrics with Application Insights java in-process agent. 利用此功能,你可以通过 Application Insights 监视 resilience4j 断路器的指标。With this feature you can monitor metrics of resilience4j circuit breaker from Application Insights.

我们使用 spring-cloud-circuit-breaker-demo 来展示其工作原理。We use the spring-cloud-circuit-breaker-demo to show how it works.

先决条件Prerequisites

构建和部署应用Build and deploy apps

以下过程构建并部署应用。The following procedure builds and deploys apps.

  1. 克隆并构建演示存储库。Clone and build the demo repository.
git clone https://github.com/spring-cloud-samples/spring-cloud-circuitbreaker-demo.git
cd spring-cloud-circuitbreaker-demo && mvn clean package -DskipTests
  1. 创建包含终结点的应用程序Create applications with endpoints
az spring-cloud app create --name resilience4j --is-public \
    -s ${asc-service-name} -g ${asc-resource-group}
az spring-cloud app create --name reactive-resilience4j --is-public \
    -s ${asc-service-name} -g ${asc-resource-group}
  1. 部署应用程序。Deploy applications.
az spring-cloud app deploy -n resilience4j \
    --jar-path ./spring-cloud-circuitbreaker-demo-resilience4j/target/spring-cloud-circuitbreaker-demo-resilience4j-0.0.1.BUILD-SNAPSHOT.jar \
    -s ${service_name} -g ${resource_group}
az spring-cloud app deploy -n reactive-resilience4j \
    --jar-path ./spring-cloud-circuitbreaker-demo-reactive-resilience4j/target/spring-cloud-circuitbreaker-demo-reactive-resilience4j-0.0.1.BUILD-SNAPSHOT.jar \
    -s ${service_name} -g ${resource_group}

备注

  • 包括 Resilience4j 所需的依赖项:Include the required dependency for Resilience4j:

    <dependency>
        <groupId>io.github.resilience4j</groupId>
        <artifactId>resilience4j-micrometer</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
    </dependency>
    
  • 客户代码必须使用 CircuitBreakerFactory 的 API,该 API 是在你包括 Spring Cloud 断路器入门版时作为自动创建的 bean 实现的。The customer code must use the API of CircuitBreakerFactory, which is implemented as a bean automatically created when you include a Spring Cloud Circuit Breaker starter. 有关详细信息,请参阅 Spring Cloud 断路器For details see Spring Cloud Circuit Breaker.

  • 以下 2 个依赖项与上述 resilient4j 包冲突。The following 2 dependencies have conflicts with resilient4j packages above. 请确保客户不要包括这些依赖项。Be sure the customer does not include them.

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-zipkin</artifactId>
    </dependency>
    

导航到网关应用程序提供的 URL,然后从 spring-cloud-circuit-breaker-demo 访问终结点,如下所示:Navigate to the URL provided by gateway applications, and access the endpoint from spring-cloud-circuit-breaker-demo as follows:

/get
/get/delay/{seconds}
/get/fluxdelay/{seconds}

从门户查找 Resilence4j 指标Locate Resilence4j Metrics from Portal

  1. 从 Azure Spring Cloud 门户中选择“Application Insights”边栏选项卡,然后单击“Application Insights”。Select the Application Insights Blade from Azure Spring Cloud portal, and click Application Insights.

    resilience4J 0 resilience4J 0

  2. 从“Application Insights”页面中选择“指标”。 Select Metrics from the Application Insights page. 从“指标命名空间”中选择“azure.applicationinsights”。 Select azure.applicationinsights from Metrics Namespace. 另外,请选择采用“平均值”的“resilience4j_circuitbreaker_buffered_calls”指标。 Also select resilience4j_circuitbreaker_buffered_calls metrics with Average.

    resilience4J 1 resilience4J 1

  3. 选择采用“平均值”的“resilience4j_circuitbreaker_calls”指标。 Select resilience4j_circuitbreaker_calls metrics and Average.

    resilience4J 2 resilience4J 2

  4. 选择采用“平均值”的“resilience4j_circuitbreaker_calls”指标。 Select resilience4j_circuitbreaker_calls metrics and Average. 单击“添加筛选器”,然后选择“createNewAccount”作为名称。Click Add filter, and then select name as createNewAccount.

    resilience4J 3 resilience4J 3

  5. 选择采用“平均值”的“resilience4j_circuitbreaker_calls”指标。 Select resilience4j_circuitbreaker_calls metrics and Average. 接着单击“应用拆分”,然后选择“种类”。Then click Apply splitting, and select kind.

    resilience4J 4 resilience4J 4

  6. 选择采用“平均值”的“resilience4j_circuitbreaker_calls”、“resilience4j_circuitbreaker_buffered_calls”和“resilience4j_circuitbreaker_slow_calls” 指标。Select resilience4j_circuitbreaker_calls, `resilience4j_circuitbreaker_buffered_calls, and resilience4j_circuitbreaker_slow_calls metrics with Average.

    resilience4J 5 resilience4J 5

另请参阅See also