Java SpringBoot

1、在项目中引入SpringBoot Actuator依赖

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-actuator</artifactId>
  4. </dependency>

2、日志打印显示暴露的端点

  1. 2019-12-07 16:59:00.362 INFO 17196 --- [ restartedMain] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'

3、输入项目的主机IP和端口以及日志的路径进行访问

http://localhost:8080/actuator
image.pngimage.png

http://localhost:8080/actuator/health
image.png

4、在运行日志中可以看到本次进程的PID

  1. 2019-12-08 10:53:37.638 INFO 14160 --- [ restartedMain] c.f.s.SpringBootExpandApplication : Starting SpringBootExpandApplication on LAPTOP-CMGC7APE with PID 14160 (D:\Dome\SpringBootHD\SpringBootExpand\target\classes started by Fcant in D:\Dome\SpringBootHD)

5、按下Win+R打开运行,输入命令jconsole

image.png

6、查看Java进程的相关信息

7、在配置文件配置暴露更多的信息

  1. management:
  2. endpoints:
  3. web:
  4. exposure:
  5. include: '*'

8、再次访问/actuator显示了更多的信息

日志中显示暴露了13个端点

  1. 2019-12-08 11:20:37.149 INFO 14160 --- [ restartedMain] o.s.b.a.e.web.EndpointLinksResolver : Exposing 13 endpoint(s) beneath base path '/actuator'

再次访问URL
image.pngimage.png

  1. {
  2. "_links": {
  3. "self": {
  4. "href": "http://localhost:8080/actuator",
  5. "templated": false
  6. },
  7. "beans": {
  8. "href": "http://localhost:8080/actuator/beans",
  9. "templated": false
  10. },
  11. "caches-cache": {
  12. "href": "http://localhost:8080/actuator/caches/{cache}",
  13. "templated": true
  14. },
  15. "caches": {
  16. "href": "http://localhost:8080/actuator/caches",
  17. "templated": false
  18. },
  19. "health": {
  20. "href": "http://localhost:8080/actuator/health",
  21. "templated": false
  22. },
  23. "health-path": {
  24. "href": "http://localhost:8080/actuator/health/{*path}",
  25. "templated": true
  26. },
  27. "info": {
  28. "href": "http://localhost:8080/actuator/info",
  29. "templated": false
  30. },
  31. "conditions": {
  32. "href": "http://localhost:8080/actuator/conditions",
  33. "templated": false
  34. },
  35. "configprops": {
  36. "href": "http://localhost:8080/actuator/configprops",
  37. "templated": false
  38. },
  39. "env": {
  40. "href": "http://localhost:8080/actuator/env",
  41. "templated": false
  42. },
  43. "env-toMatch": {
  44. "href": "http://localhost:8080/actuator/env/{toMatch}",
  45. "templated": true
  46. },
  47. "loggers": {
  48. "href": "http://localhost:8080/actuator/loggers",
  49. "templated": false
  50. },
  51. "loggers-name": {
  52. "href": "http://localhost:8080/actuator/loggers/{name}",
  53. "templated": true
  54. },
  55. "heapdump": {
  56. "href": "http://localhost:8080/actuator/heapdump",
  57. "templated": false
  58. },
  59. "threaddump": {
  60. "href": "http://localhost:8080/actuator/threaddump",
  61. "templated": false
  62. },
  63. "metrics": {
  64. "href": "http://localhost:8080/actuator/metrics",
  65. "templated": false
  66. },
  67. "metrics-requiredMetricName": {
  68. "href": "http://localhost:8080/actuator/metrics/{requiredMetricName}",
  69. "templated": true
  70. },
  71. "scheduledtasks": {
  72. "href": "http://localhost:8080/actuator/scheduledtasks",
  73. "templated": false
  74. },
  75. "mappings": {
  76. "href": "http://localhost:8080/actuator/mappings",
  77. "templated": false
  78. }
  79. }
  80. }

9、其他具体的使用如健康检查和Bean加载可以访问相应的路径

A.查看Bean的加载依赖-http://localhost:8080/actuator/beans

image.png