Spring Boot—21Actuator--监控

https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/reference/htmlsingle/


pom.xml

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.11</version>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.9</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>        
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>


application.properties

#
server.address=0.0.0.0
server.port=8080
server.servlet.context-path=/test
server.session.timeout=300
server.error.path=/error
#
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.buffered=true
server.tomcat.accesslog.directory=D:/Project/JavaWeb/SpringBoot/04JPASpringBoot/logs
#
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=Asia/Shanghai
#
spring.thymeleaf.cache=true
spring.thymeleaf.enabled=true

file.upload.path=D:/Project/JavaWeb/SpringBoot/04JPASpringBoot/fileUpLoad

spring.servlet.multipart.enabled=true
spring.servlet.multipart.file-size-threshold=0
spring.servlet.multipart.location=D:/Project/JavaWeb/SpringBoot/04JPASpringBoot/temp
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
spring.servlet.multipart.resolve-lazily=false


spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.druid.one.url=jdbc:mysql://127.0.0.1:3306/test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false
spring.datasource.druid.one.username=root
spring.datasource.druid.one.password=gis
spring.datasource.druid.one.driver-class-name=com.mysql.cj.jdbc.Driver

##Druid
spring.datasource.druid.one.initial-size=2
spring.datasource.druid.one.max-active=5
spring.datasource.druid.one.min-idle=1
spring.datasource.druid.one.max-wait=60000
spring.datasource.druid.one.pool-prepared-statements=true
spring.datasource.druid.one.max-pool-prepared-statement-per-connection-size=20
spring.datasource.druid.one.validation-query=SELECT 1 FROM DUAL
spring.datasource.druid.one.validation-query-timeout=60000
spring.datasource.druid.one.test-on-borrow=false
spring.datasource.druid.one.test-on-return=false
spring.datasource.druid.one.test-while-idle=true
spring.datasource.druid.one.time-between-eviction-runs-millis=60000
spring.datasource.druid.one.min-evictable-idle-time-millis=100000
#spring.datasource.druid.one.max-evictable-idle-time-millis=
spring.datasource.druid.one.filters=stat,wall,log
spring.datasource.druid.one.logSlowSql=true

#
# debug=true # Enable debug logs.
# trace=true # Enable trace logs.

# LOGGING
logging.config=classpath:logback.xml

# Actuator

management.server.address=0.0.0.0
management.server.port=8081
management.server.servlet.context-path=/manage
management.endpoints.enabled-by-default=true
management.endpoint.health.enabled=true
management.endpoint.sessions.enabled=true
management.health.db.enabled=true
management.endpoint.health.show-details=always
#management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.include=auditevents,beans,conditions,configprops,env,flyway,health,heapdump,httptrace,info,jolokia,logfile,loggers,liquibase,metrics,mappings,prometheus,scheduledtasks,sessions,shutdown,threaddump
spring.security.user.name=zyx
spring.security.user.password=gis


启动类

package com.smartmap.sample.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@EnableCaching
@EnableTransactionManagement
@SpringBootApplication
public class TestActuatorApplication {

    public static void main(String[] args) {
        SpringApplication.run(TestActuatorApplication.class, args);

    }

}


http://127.0.0.1:8081/manage/login


http://127.0.0.1:8081/manage/actuator/health



/actuator/auditevents                       ,methods=[GET],
/actuator/beans                               ,methods=[GET],
/actuator/health]                              ,methods=[GET],
/actuator/conditions                          ,methods=[GET],
/actuator/shutdown                          ,methods=[POST],
/actuator/configprops                       ,methods=[GET],
/actuator/env                                  ,methods=[GET],
/actuator/env/{toMatch}                     ,methods=[GET],
/actuator/info                                  ,methods=[GET],
/actuator/loggers                             ,methods=[GET],
/actuator/loggers/{name}                    ,methods=[POST]
/actuator/loggers/{name}                    ,methods=[GET],
/actuator/heapdump                          ,methods=[GET],
/actuator/threaddump                        ,methods=[GET],
/actuator/metrics/{requiredMetricName}      ,methods=[GET],
/actuator/metrics                             ,methods=[GET],
/actuator/scheduledtasks                    ,methods=[GET],
/actuator/httptrace                          ,methods=[GET],
/actuator/mappings                          ,methods=[GET],
/actuator                                         ,methods=[GET],


内存占用诊断

1)生成dump文件

http://127.0.0.1:8081/manage/actuator/heapdump

2)启动jhat工具进行分析

jhat -port 7000 d:/heapdump

3)查看内存中的对象占用

http://127.0.0.1:7000/oql/


select s from java.lang.String s where s.value.length >= 5000

image


image


image


很强!!!

posted @ 2018-04-29 20:57  ParamousGIS  阅读(378)  评论(0编辑  收藏  举报