{"id":4145,"date":"2014-05-04T13:00:12","date_gmt":"2014-05-04T04:00:12","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=4145"},"modified":"2018-11-14T16:33:51","modified_gmt":"2018-11-14T07:33:51","slug":"spring-boot-actuator","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2014\/05\/04\/spring-boot-actuator\/","title":{"rendered":"Spring Boot Actuator \u3067\u30b5\u30fc\u30d0\u306e\u72b6\u614b\u3092\u78ba\u8a8d\u3059\u308b"},"content":{"rendered":"
\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n
Spring Boot \u306e\u7d9a\u304d\u3067\u3059\u3002Spring Boot Actuator \u3092\u4f7f\u3046\u3068\u3001\u30b7\u30b9\u30c6\u30e0\u306e\u72b6\u614b\u3084\u30e1\u30c8\u30ea\u30af\u30b9\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n
<\/p>\n
\u5c0e\u5165\u65b9\u6cd5\u306f pom.xml \u306b\u8ffd\u8a18\u3059\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n
<project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n xsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\">\r\n ...\r\n <dependencies>\r\n <!-- \u8ffd\u52a0: \u3053\u3053\u304b\u3089 -->\r\n <dependency>\r\n <groupId>org.springframework.boot<\/groupId>\r\n <artifactId>spring-boot-actuator<\/artifactId>\r\n <\/dependency>\r\n <!-- \u8ffd\u52a0: \u3053\u3053\u307e\u3067 -->\r\n ...\r\n <\/dependencies>\r\n<\/project><\/pre>\n<\/p>\n
\u8ffd\u52a0\u3055\u308c\u308b\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8<\/h2>\n
Spring Boot Actuator \u3092\u5c0e\u5165\u3059\u308b\u3068\u3001\u30b7\u30b9\u30c6\u30e0\u306e\u72b6\u614b\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u304c\u8ffd\u52a0\u3055\u308c\u307e\u3059\u3002<\/p>\n
\u8ffd\u52a0\u3055\u308c\u308b\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3092\u3044\u304f\u3064\u304b\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n
\u4e0a\u8a18\u3092\u542b\u3081\u3066\u3001\u8ffd\u52a0\u3055\u308c\u308b\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u306e\u4e00\u89a7\u306f\u300c32. Endpoints<\/a>\u300d\u306b\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u8a73\u3057\u304f\u306f\u305d\u3061\u3089\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n <\/p>\n \u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u306f\u500b\u5225\u306b\u6709\u52b9\u5316\/\u7121\u52b9\u5316\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n \u4f8b\u3068\u3057\u3066\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u7121\u52b9\u5316\u3055\u308c\u3066\u3044\u308b\u30b7\u30e3\u30c3\u30c8\u30c0\u30a6\u30f3\u7528\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3092\u6709\u52b9\u5316\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n \u624b\u3063\u53d6\u308a\u65e9\u304f\u3084\u308b\u306b\u306f\u3001\u8d77\u52d5\u6642\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n \u8d77\u52d5\u6642\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u4ee5\u5916\u306b\u3082\u3001application.properties \u3067\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n \u30b7\u30e3\u30c3\u30c8\u30c0\u30a6\u30f3\u7528\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u306f POST \u3067\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3057\u304b\u53d7\u3051\u4ed8\u3051\u307e\u305b\u3093\u3002<\/p>\n Linux \u3092\u3054\u5229\u7528\u306e\u5834\u5408\u306f curl \u30b3\u30de\u30f3\u30c9\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001\u30b7\u30e3\u30c3\u30c8\u30c0\u30a6\u30f3\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n <\/p>\n \u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u306f\u5e38\u306b \"ok\" \u3092\u8fd4\u3059\u3060\u3051\u306a\u306e\u3067\u3001\u72ec\u81ea\u306e\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u3092\u5b9f\u88c5\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n \u72ec\u81ea\u306e\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u3092\u4f5c\u6210\u3059\u308b\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b HealthIndicator<String> \u3092\u5b9f\u88c5\u3057\u305f\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n health() \u30e1\u30bd\u30c3\u30c9\u3067\u72ec\u81ea\u306e\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u3092\u884c\u3044\u3001\u7d50\u679c\u3092\u6587\u5b57\u5217\u3067\u8fd4\u3057\u307e\u3059\u3002<\/p>\n <\/p>\n \/env \u3084 \/dump \u306a\u3069\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3060\u3051\u3067\u69d8\u3005\u306a\u60c5\u5831\u3092\u78ba\u8a8d\u3067\u304d\u3066\u4fbf\u5229\u3067\u3059\u304c\u3001\u3053\u308c\u3089\u306e\u60c5\u5831\u306f\u4e00\u822c\u306e\u30e6\u30fc\u30b6\u306b\u306f\u898b\u305b\u305f\u304f\u306a\u3044\u60c5\u5831\u304c\u307b\u3068\u3093\u3069\u3060\u3068\u601d\u3044\u307e\u3059\u3002\u305d\u3053\u3067\u3001\u30d1\u30b9\u3084\u30dd\u30fc\u30c8\u306a\u3069\u3092\u5909\u66f4\u3057\u3066\u30a2\u30af\u30bb\u30b9\u5236\u9650\u3057\u3084\u3059\u3044\u3088\u3046\u306b\u3059\u308b\u3068\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n \u8a2d\u5b9a\u306e\u3084\u308a\u65b9\u306f\u524d\u56de\u3082\u3054\u7d39\u4ecb\u3057\u307e\u3057\u305f\u304c\u3001src\/main\/resources\/ \u4ee5\u4e0b\u306b application.properties \u307e\u305f\u306f application.yml \u3092\u4f5c\u6210\u3057\u3001\u5fc5\u8981\u306a\u9805\u76ee\u3092\u6307\u5b9a\u3059\u308b\u3060\u3051\u3067\u3059\u3002src\/main\/resources\/application.properties \u3092\u4f5c\u6210\u3057\u305f\u3068\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n <\/p>\n \u6700\u521d\u306f\u300c\u3061\u3087\u3063\u3068\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u3068\u304b\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3060\u3051\u300d\u3068\u601d\u3063\u3066\u3044\u307e\u3057\u305f\u304c\u3001Spring Boot Actuator \u306f\u601d\u3063\u305f\u4ee5\u4e0a\u306e\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3057\u305f\u3002\u4eca\u56de\u306f\u7d39\u4ecb\u3057\u307e\u305b\u3093\u3067\u3057\u305f\u304c\u3001HTTP \u4ee5\u5916\u306b\u3082 JMX \u3084 SSH \u306a\u3069\u306b\u3082\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002Spring \u306e\u30b5\u30a4\u30c8\u306b\u3082\u300cproduction-ready \u306a\u6a5f\u80fd\u300d\u3068\u66f8\u304b\u308c\u3066\u3044\u308b\u3053\u3068\u304b\u3089\u3082\u3001\u672c\u756a\u904b\u7528\u3067\u4f7f\u3046\u3053\u3068\u3092\u5ff5\u982d\u306b\u4f5c\u3089\u308c\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" \u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n Spring Boot \u306e\u7d9a\u304d\u3067\u3059\u3002Spring Boot Actuator \u3092\u4f7f\u3046\u3068\u3001\u30b7\u30b9\u30c6\u30e0\u306e\u72b6\u614b\u3084\u30e1\u30c8\u30ea\u30af\u30b9\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u306e\u6709\u52b9\u5316\/\u7121\u52b9\u5316<\/h2>\n
mvn -Dendpoints.shutdown.enabled=true spring-boot:run<\/pre>\n
# application.properties\r\nendpoints.shutdown.enabled=true<\/pre>\n
curl -X POST localhost:8080\/shutdown<\/pre>\n
\u72ec\u81ea\u306e\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u3092\u5b9f\u88c5\u3059\u308b<\/h2>\n
package com.techscore.spring_boot_sample;\r\n\r\nimport org.springframework.boot.actuate.health.HealthIndicator;\r\nimport org.springframework.stereotype.Component;\r\n\r\n@Component\r\npublic class CustomHealth implements HealthIndicator<String> {\r\n\r\n public String health() {\r\n \/\/ TODO \u5fc5\u8981\u306a\u30c1\u30a7\u30c3\u30af\u3092\u3057\u3066\u8fd4\u3059\u5024\u3092\u5909\u3048\u308b.\r\n return \"good\";\r\n }\r\n\r\n}<\/pre>\n
\u30d1\u30b9\u3084\u30dd\u30fc\u30c8\u306a\u3069\u3092\u5909\u66f4\u3059\u308b<\/h2>\n
# \/manage\/health \u306a\u3069\u3067\u53d7\u3051\u4ed8\u3051\u308b\u3088\u3046\u306b\u306a\u308b.\r\nmanagement.contextPath=\/manage\r\n\r\n# \u53d7\u3051\u4ed8\u3051\u308b\u30dd\u30fc\u30c8\u3068\u30a2\u30c9\u30ec\u30b9.\r\nmanagement.port=8081\r\nmanagement.address=127.0.0.1<\/pre>\n
\u307e\u3068\u3081<\/h2>\n
\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[57,136,122],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/4145"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=4145"}],"version-history":[{"count":14,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/4145\/revisions"}],"predecessor-version":[{"id":4173,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/4145\/revisions\/4173"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=4145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=4145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=4145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}