I. Overview
Use actuator to view monitoring and metrics information by configuration
Second, use 2.1, build Web projects, add Pom
< Dependency > < groupId >org.springframework.boot</groupId> < Artifactid>spring-boot-starter-web</artifactid> </dependency>
Start the project, view the log, and find the access address as follows
2.2, increase the pom dependence of actuator
< Dependency > < groupId >org.springframework.boot</groupId> < Artifactid>spring-boot-actuator</artifactid> </ Dependency >
Start the project, view the log, and find the access address as follows
As you can see, the accessible address has increased
Third, detailed
We recommend installing the Jsonview plugin for easy viewing of JSON
3.1. Add configuration
Close permission limit, application.properties
Management.security.enabled=false
3.2. Visit the following URL
The key feature of Spring Boot actuator is that it provides many WEB interfaces in the application to understand the internal state of the application as it runs. Actuator provides the following interfaces, which can be divided into three main categories: Configuration interfaces, metric interfaces, and other interfaces, as shown in the following table.
http Method |
Path |
|
Description |
authentication |
GET |
/auditevents |
|
Audit events |
True |
GET |
/autoconfig |
Configuration |
View the usage of automatic configuration Provides an automated configuration report that records which automatic configuration conditions have passed and which failed |
True |
GET |
/configprops |
Configuration |
View configuration properties, including default configuration Describes how configuration properties (including default values) are injected into a bean |
True |
GET |
/beans |
Configuration |
View a list of beans and their relationships Describe all the beans in the application context, and their relationships |
True |
GET |
/dump |
|
Print line stacks, get snapshot of thread activity |
True |
GET |
/env |
Configuration |
View all environment variables |
True |
GET |
/env/{name} |
Configuration |
Get specific environment property values by name |
True |
GET |
/health |
Configuration |
View the app health metrics, which are provided by the Healthindicator implementation class Including: Cassandra, Composite, Couchbase, DataSource, DiskSpace, Elasticsearch, Jms, Ldap, Mail, Mongo, Ordered, Rabbit, Redis, SOLR |
False |
GET |
/heapdump |
|
|
True |
GET |
/info |
Configuration |
View application information, which is provided by the attributes that begin with info |
False |
GET |
/loggers |
|
|
True |
GET |
/loggers/{name} |
|
|
True |
POST |
/loggers/{name} |
|
|
True |
GET |
/mappings |
|
View all URL mappings and mappings between them and the controller (including actuator endpoints) |
True |
GET |
/metrics |
Measure |
Report various application metrics, such as memory usage and HTTP request count |
True |
GET |
/metrics/{name} |
Measure |
Report application metrics for the specified name |
True |
POST |
/shutdown |
|
To close the app, ask Endpoints.shutdown.enabled to set to True |
True |
GET |
/trace |
|
View basic tracking information, providing basic HTTP request tracking information (timestamp, HTTP prime) |
True |
3.3. Source view
Under Org.springframework.boot.actuate.endpoint in the Spring-boot-actuator-1.5.9.release.jar package, look at the specific class implementation,
You can set whether an item is displayed
Endpoints.beans.enabled=false
View the code here endpoints, all inherited from Abstractendpoint, where Abstractendpoint contains attributes as follows
Sensitive sensitive information enabled
3.3.1, Org.springframework.boot.actuate.health
Extensions are supported in addition to the previously supported health checks. Healthindicator
Steps:
1 "Implement Healthindicator interface, implement logic, and incorporate into spring container management
@Component Public class Implements healthindicator { @Override Public Health Health () { // Return Health.down (). Withdetail ("Error", "Spring Test Error"). Build (); return Health.up (). Withdetail ("Success", "Spring Test Success"). Build ();} }
3.3.2, Info
configurations that begin with info in all the loaded profiles can be displayed here, as
Info.name=myinfoinfo.version=1.0.0info.datasource.url=jdbc:mysql:// 127.0.0.1:3306/springboot
Git information is also displayed git.properties
Git.branch=master
Shown below
"Jdbc:mysql://127.0.0.1:3306/springboot""root" "Root" "Com.mysql.jdbc.Driver" "MyInfo""1.0.0" "Master" }}
3.3.3, metrics viewing metric information
Counterservice: Count service, can be used directly
See the number of user/home visits above
@Autowired private counterservice counterservice;//introduced @GetMapping ("/user /home" )public string (@RequestParam (" Error ") string error) { Counterservice.increment("User.home.request.count");//Buried point if(error.equals ("Test ")) { thrownew nullpointerexception (); } return "Home"; }
View Now: Http://127.0.0.1:8080/metrics
Gaugeservice: Used to count a value to see the value of a monitoring point
@Autowired private gaugeservice gaugeservice; @GetMapping ("/user/create") public String Create (int age ) { Gaugeservice.submit ("User.create.age", age); return "Create"; }
View Now: Http://127.0.0.1:8080/metrics
3.3.4, monitoring information output other locations
1. Add the configuration class as follows
@Configuration Public class exportconfiguration { @Bean @ExportMetricWriter public metricwriter Createmetricwriter (Mbeanexporter exporter) { returnnew Jmxmetricwriter ( exporter);} }
View Metricwriter supports the following types of support, or you can define your own
JMX is used here.
Iv. Use of JDK tools
View JMX mode JDK with three types under Bin, JConsole, JMC, JVISUALVM
Jconsole Way
JVISUALVM Way
Note JVISUALVM default does not support Mbean,jconsole, etc. need to install their own plug-in, the tool → plug-in installation of plug-ins
JMC Way
Note: These three tools are not only able to view the Mbean, other information can also be viewed, and the page content view consistent.
Not related to Jmx configured above, configuring JMX only adds Metricwriter entries
020-spring Boot Monitoring and metrics