springCloud微服務系列——actuator

目錄

一、簡介

二、pom依賴

三、配置

  management

         spring boot 1.x

         spring boot 2.x

  權限配置 

         spring boot 1.x

         spring boot 2.x

  statusPage和health check

  info配置

四、使用說明

spring boot 1.x

spring boot 2.x


一、簡介

             spring boot提供了一系列的監控指標,可以通過actuator進行引入。spring boot 2.x在此基礎上引入了prometheus。

二、pom依賴

              spring boot 1.x只有actuator

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

               spring boot 2.x還可以引入prometheus

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

三、配置

  management

               配置management目的在於將節點監控的訪問路徑和端口號和api分開,有利於權限的管理。

  •          spring boot 1.x

management: 
  security: 
    enabled: true
  port: 8188
  context-path: /trace-demo1/admin

                在spring boot 1.x中,可以直接在yarn中配置security,另外默認開放所有的節點 

  •          spring boot 2.x

management: 
  server:
    port: 8188
    servlet:
      context-path: /trace-demo1/admin
  endpoints: 
    web: 
      exposure:
        include: "*"

                 在spring boot 2.x中,只默認開放info和health端口 

  權限配置 

  •          spring boot 1.x

                 在spring boot 1.x中,直接在yarn中配置security即可   

  •          spring boot 2.x

@EnableWebSecurity
public class EurekaClientWebSecurityConfig extends WebSecurityConfigurerAdapter {

	@Override
	protected void configure(HttpSecurity http) throws Exception {
		
		 http
         .authorizeRequests()
         // 普通的接口不需要校驗
         .antMatchers("/*api/**").permitAll()
         // swagger頁面需要添加登錄校驗
         .antMatchers("/swagger-ui.html").authenticated()
         // 監控節點需要添加登錄校驗
         .requestMatchers(EndpointRequest.toAnyEndpoint()).authenticated()
         .and()
         .formLogin();
		
	}
	
}

 

  statusPage和health check

                 可以向註冊中心說明自己的statusPage和healthCheck接口

eureka: 
  instance: 
    instanceId: ${spring.application.name}:${random.value} 
    status-page-url-path: ${management.server.servlet.context-path}/actuator/info
    health-check-url-path: ${management.server.servlet.context-path}/actuator/health 
  client: 
    serviceUrl: 
      defaultZone: http://admin:[email protected]:1111/manage/serverCenter/eureka/

  info配置

                   只需要在yarn中配置即可,info下的內容可以隨便配置

info: 
  describe: 鏈路跟蹤demo1
  version: 1.0.0

四、使用說明

                   配置了manager後,只需要訪問manager配置的地址和端口,外加相應的節點名即可。如果配置了權限,需要輸入用戶名密碼

                   所有的節點名,可以通過/actuator查看

  • spring boot 1.x

                   按照上面的配置,訪問地址爲,http://ip:8188/trace-demo1/admin/相應的節點名 

  • spring boot 2.x

                   按照上面的配置,訪問地址爲,http://ip:8188/trace-demo1/admin/actuator/相應的節點名

                   如果引入了prometheus,還可以訪問這個地址,http://ip:8188/trace-demo1/admin/prometheus

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章