spring-boot actuat(モニタ)の配置と使用について詳しく説明します。


生産環境では、リアルタイムまたは定期的なモニタリングサービスの利用可能性が必要です。spring-bootのactuat機能は多くの監視に必要なインターフェースを提供しています。簡単な配置と使用は以下の通りです。
1、導入依存:

<dependency> 
  <groupId>org.springframework.boot</groupId> 
  <artifactId>spring-boot-starter-actuator</artifactId> 
</dependency> 
http呼び出しの方式を使うなら、この依存性も必要です。

<dependency> 
  <groupId>org.springframework.boot</groupId> 
  <artifactId>spring-boot-starter-web</artifactId> 
</dependency> 
2、設定:
application.ymlでモニタのHTTPポートを指定します。指定しない場合はserverと同じポートを使用します。ある項目を削除する検査を指定します。(例えば、モニタしないhealth.mail):

server: 
 port: 8082 
management: 
 port: 54001 
 health: 
  mail: 
   enabled: false 
3、使用:
health指標を参照:http://localhost:54001/health

{"status":"UP","diskSpace":{"status":"UP","total":120031539200,"free":33554337792,"threshold":10485760},"db":{"status":"UP","dataSource1":{"status":"UP","database":"MySQL","hello":1},"dataSource2":{"status":"UP","database":"MySQL","hello":1}}} 
4、ユーザー定義の指標:
4.1/health:あるクラスの中でimplements HealthIndicatorインターフェースを実行して、その中のhealth()方法を実現すればいいです。
コード:

@SpringBootApplication 
@EnableScheduling 
public class MySpringBootApplication implements HealthIndicator{ 
  private static Logger logger = LoggerFactory.getLogger(MySpringBootApplication.class); 
   
  public static void main(String[] args) { 
    SpringApplication.run(MySpringBootApplication.class, args); 
    logger.info("My Spring Boot Application Started"); 
  } 
 
  /** 
   *  /health       ,       :"mySpringBootApplication":{"status":"UP","hello":"world"} 
   */ 
  @Override 
  public Health health() { 
    return Health.up().withDetail("hello", "world").build(); 
  } 
} 
/health運転結果(第二の指標に注意):
「status」:「UP」、「mySpringBootAppplication」:{status”:「UP」、「hello」、「world」、「dissSpace」:{status”:「UP」、「total」:1200315159200、「free」:335537792、「threstastastastastastastad」:1040:「Ustastastastastastastastastastastastastastastad」:「Uces」:「UPS」:1040、「UPS」:1040、「UPS」、「UPS」:1040、「UPS」、「UPS」:1040、「UPS」:1040、「UPS」、「UPS」:1040、「U:「MySQL」,「ハロー」:1},「dataSource 2」:{status”:「UP」,「database」:「MySQL」,「ハロー」:1}
4.2/info:次のように構成されています。文字列を直接与えてもいいし、pom.xml構成から取得できます。

info: 
 app: 
  name: "@project.name@" # pom.xml    
  description: "@project.description@" 
  version: "@project.version@" 
  spring-boot-version: "@project.parent.version@" 
/infoの結果は以下の通りです。
{「app」:{name}:「my-spring-boot」、「description」:「Test Project for Spring Boot」、「version」:「1.0」、「spring-boot-version」:「1.3.6.RELEASE」}
公式サイト:http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready
ソースコード参照:https://github.com/xujijun/my-spring-boot
以上が本文の全部です。皆さんの勉強に役に立つように、私たちを応援してください。