<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 服務監控 – Hystrix,Eureka 管理員和 Spring Boot 管理員 > 原文: [https://howtodoinjava.com/spring-cloud/microservices-monitoring/](https://howtodoinjava.com/spring-cloud/microservices-monitoring/) Spring Boot 和 Spring Cloud 在交付基于微服務的應用程序時被廣泛使用。 最終,基于在不同主機上運行的 Spring 運行應用程序**監視微服務**成為必要。 有許多工具可用來監視這些微服務的各種運行狀況。 在此 SpringCloud 教程中,我們將學習使用三種監視工具,即 **Hystrix 儀表板**, **Eureka 管理儀表板**和 **Spring boot 管理儀表板**。 ## 1\. 概述 在此演示中,我們將創建三個應用程序。 1. **員工服務** – 此微服務應用程序負責獲取員工的數據。 2. **Api 網關** – 此應用程序將在訪問不同的微服務時提供公共網關。 在以下示例中,它將充當上述員工服務的網關。 3. **Eureka 服務器** – 此微服務應用程序將提供上述微服務的服務發現和注冊。 該演示是圍繞 **Netflix Eureka** 創建的,以集中管理和監視注冊的應用程序。 您可能已經知道 Netflix Eureka 服務器是用于構建**服務注冊表服務器**和關聯的 Eureka 客戶端的,它們將注冊自己以查找其他服務并通過 REST API 進行通信。 ## 2\. 技術棧 * Java 1.8 * Spring 工具套件 * SpringCloud * SpringBoot * SpringRest * Maven ## 3\. 員工服務 * 從[ Spring boot 初始化器](https://start.spring.io/) / [Spring 工具套件](https://spring.io/tools/sts)創建一個 Spring Boot 項目。具有依賴 **Eureka Discovery**,**執行器**,**Web**,**REST 存儲庫**。 ![](https://img.kancloud.cn/c1/c7/c1c7d9be65713789da7c97defa78b93b_1199x558.jpg) * 主應用程序類`EmployeeServiceApplication`,用于啟動 Spring Boot 應用程序。 `EmployeeServiceApplication.java` ```java package com.howtodoinjava.example.employee; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableEurekaClient public class EmployeeServiceApplication { public static void main(String[] args) { SpringApplication.run(EmployeeServiceApplication.class, args); } } ``` `@EnableEurekaClient` – 此注解在下面創建的[ Eureka Server 應用程序](#eureka-dashboard)中將該服務注冊為 Eureka 客戶端。 * 創建一個 Rest 控制器類`EmployeeServiceController`以公開`Employee`數據。 `EmployeeServiceController.java` ```java package com.howtodoinjava.example.employee.controller; import java.util.HashMap; import java.util.Map; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.howtodoinjava.example.employee.beans.Employee; @RestController public class EmployeeServiceController { private static final Map<Integer, Employee> employeeData = new HashMap<Integer,Employee() { private static final long serialVersionUID = -3970206781360313502L; { put(111,new Employee(111,"Employee1")); put(222,new Employee(222,"Employee2")); } }; @RequestMapping(value = "/findEmployeeDetails/{employeeId}", method = RequestMethod.GET) public Employee getEmployeeDetails(@PathVariable int employeeId) { System.out.println("Getting Employee details for " + employeeId); Employee employee = employeeData.get(employeeId); if (employee == null) { employee = new Employee(0, "N/A"); } return employee; } } ``` 關聯的`Employee` Bean 類如下。 `Employee.java` ```java package com.howtodoinjava.example.employee.beans; public class Employee { private String name; private int id; @Override public String toString() { return "Employee [name=" + name + ", id=" + id + "]"; } } ``` * 在`src/main/resources`目錄中創建`application.yml`。 `application.yml` ```java server: port: 8011 eureka: instance: leaseRenewalIntervalInSeconds: 5 leaseExpirationDurationInSeconds: 2 client: serviceUrl: defaultZone: http://localhost:8761/eureka/ healthcheck: enabled: true lease: duration: 5 spring: application: name: employee-service management: security: enabled: false logging: level: com.self.sprintboot.learning.employee: DEBUG ``` * 啟動此應用,可訪問`http://localhost:8011/findEmployeeDetails/111` ![](https://img.kancloud.cn/b4/89/b489e3ba4753afac3cb46ed7395389c5_411x62.jpg) ## 4\. 帶有 Hystrix 的 API 網關 * 從[ Spring boot 初始化器](https://start.spring.io/) / [Spring 工具套件](https://spring.io/tools/sts)創建一個 Spring Boot 項目。具有依賴`Eureka Discovery`, `Actuator`, `Web`, `Hystrix`, `Hystrix Dashboard`, `Rest repositories`。 ![](https://img.kancloud.cn/17/dc/17dc6fa2f340701e9a418252b17abe80_1202x586.jpg) * 主應用程序類`ApiGatewayApplication`,用于啟動 Spring Boot 應用程序。 `ApiGatewayApplication.java` ```java package com.howtodoinjava.example.apigateway; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; @SpringBootApplication @EnableEurekaClient @EnableHystrixDashboard @EnableCircuitBreaker public class ApiGatewayApplication { public static void main(String[] args) { SpringApplication.run(ApiGatewayApplication.class, args); } } ``` `@EnableHystrixDashBoard` – 提供 Hystrix 流的儀表板視圖。 `@EnableCircuitBreaker` – 啟用斷路器實現。 * 創建一個 REST 控制器類`EmployeeController`以公開`Employee`數據。 `EmployeeController.java` ```java package com.howtodoinjava.example.apigateway.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpMethod; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; @RestController public class EmployeeController { @Autowired RestTemplate restTemplate; @RequestMapping(value = "/employeeDetails/{employeeid}", method = RequestMethod.GET) @HystrixCommand(fallbackMethod = "fallbackMethod") public String getStudents(@PathVariable int employeeid) { System.out.println("Getting Employee details for " + employeeid); String response = restTemplate.exchange("http://employee-service/findEmployeeDetails/{employeeid}", HttpMethod.GET, null, new ParameterizedTypeReference<String>() {}, employeeid).getBody(); System.out.println("Response Body " + response); return "Employee Id - " + employeeid + " [ Employee Details " + response+" ]"; } public String fallbackMethod(int employeeid){ return "Fallback response:: No employee details available temporarily"; } @Bean @LoadBalanced public RestTemplate restTemplate() { return new RestTemplate(); } } ``` * 在`src/main/resources`目錄中創建`application.yml`。 `application.yml` ```java server: port: 8010 #port number eureka: instance: leaseRenewalIntervalInSeconds: 5 leaseExpirationDurationInSeconds: 2 client: serviceUrl: defaultZone: http://localhost:8761/eureka/ healthcheck: enabled: true lease: duration: 5 spring: application: name: api-gateway management: security: enabled: false logging: level: com.self.sprintboot.learning.apigateway: DEBUG ``` * 啟動應用程序,可訪問`http://localhost:8010/employeeDetails/111`。 ![](https://img.kancloud.cn/65/d0/65d07964609d3eda22a502e78236b12f_509x149.jpg) ## 5\. Hystrix 儀表板視圖 * 要**通過 Hystrix 儀表板進行監控**,請在`http://localhost:8010/hystrix`打開 Hystrix 儀表板。 ![](https://img.kancloud.cn/03/c0/03c07cf342312ed14ee047787c587c76_1259x596.jpg) 這是主頁,需要放置事件流 URL 進行監視。 * 現在在信息中心中查看 **Hystrix 流** – `http://localhost:8010/hystrix.stream` ![](https://img.kancloud.cn/d6/d0/d6d0e0936af595974c1bcfd1e253df72_1263x545.jpg) 這提供了所有 Hystrix 命令和線程池的實時信息。 ## 6\. Eureka 管理儀表板視圖 現在讓我們學習如何使用 Eureka 管理控制臺視圖。 * 從[ Spring boot 初始化器](https://start.spring.io/) / [Spring 工具套件](https://spring.io/tools/sts)創建一個 Spring Boot 項目,具有以下依賴 **Eureka Server**,**執行器**,**Web**,**Spring Boot 管理員服務器**。 ![](https://img.kancloud.cn/58/ea/58ead6515355d406762a7dea7ab106c8_1198x558.jpg) * 主應用程序類`EurekaServerApplication`,用于啟動 Spring Boot 應用程序。 `EurekaServerApplication.java` ```java package com.howtodoinjava.example.eureka; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; import de.codecentric.boot.admin.config.EnableAdminServer; @SpringBootApplication @EnableEurekaServer @EnableAdminServer public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } } ``` `@EnableEurekaServer` – 此注解將使此應用程序充當微服務注冊表和發現服務器。 `@EnableAdminServer` – 此注解提供 Spring Boot Admin 配置。 * 在`src/main/resources`目錄中創建`application.yml`和`bootstrap.yml`。 * 使用給定的配置添加`application.yml`。 請注意,對于 Spring boot admin 服務器,提供了一個不同的上下文路徑`/admin`,以免與`/eureka`沖突。 `application.yml` ```java server: port: ${PORT:8761} eureka: client: registryFetchIntervalSeconds: 5 registerWithEureka: false serviceUrl: defaultZone: ${DISCOVERY_URL:http://localhost:8761}/eureka/ instance: leaseRenewalIntervalInSeconds: 10 management: security: enabled: false spring: boot: admin: context-path: /admin #A different context path for Spring boot admin server has been provided avoiding conflict with eureka ``` * 創建`bootstrap.yml`并進行配置。 `bootstrap.yml` ```java spring: application: name: Eureka-Server cloud: config: uri: ${CONFIG_SERVER_URL:http://localhost:8888} ``` * 啟動應用程序。 但在此之前,請確保之前啟動了上面提到的其余客戶端應用程序,以便查看所有已注冊的應用程序。 該應用程序可通過`http://localhost:8761`訪問。 ![](https://img.kancloud.cn/19/d4/19d42d85cce7f72defd72f9ff0f4dfdd_1276x619.jpg) ## 7\. Spring Boot 管理儀表板視圖 * 要通過 Spring Boot Admin 服務器進行監視,請調用此 URL,該 URL 運行在不同的上下文路徑 - `http://localhost:8761/admin`中。 ![](https://img.kancloud.cn/0c/30/0c30b35f1a27e0b09ac6fca5a7fda034_1280x488.jpg) * 該管理界面提供應用程序概述,桌面通知,應用程序運行狀況檢查,日志文件瀏覽,JMX Bean,線程堆轉儲等。要查看單個應用程序的運行狀況并監視其指標,請單擊詳細信息按鈕。 它將帶您到各個應用程序的管理儀表板。 ![](https://img.kancloud.cn/0c/2d/0c2d376864c6dcbd096414f6eed8a202_1280x651.jpg) * 使用儀表板管理日志級別。 ![](https://img.kancloud.cn/82/e1/82e1ab470b02608d21edf19751210ed4_1107x676.jpg) * 使用儀表板管理運行時環境屬性。 ![](https://img.kancloud.cn/88/7f/887fac1ba84deea447817cd695db8b8d_1023x616.jpg) * 您也可以使用它來查看 HTTP 跟蹤。 ![](https://img.kancloud.cn/9c/af/9caf624d60c23995da7572a7a16f520d_1091x577.jpg) 從 Spring 運行管理員的角度來看,目前是這樣。 請隨時添加任何評論/查詢。 我們很樂意解決同樣的問題。 [下載員工服務](https://howtodoinjava.com/wp-content/uploads/2018/03/Employee-Service.zip) [下載 API 網關](https://howtodoinjava.com/wp-content/uploads/2018/03/Api-Gateway.zip) [下載 Eureka 服務器](https://howtodoinjava.com/wp-content/uploads/2018/03/Eureka-server.zip) 學習愉快!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看