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

猜你喜欢

转载自blog.csdn.net/guduyishuai/article/details/81532705
今日推荐