ホームページ  >  記事  >  Java  >  SpringBoot2でActuatorコンポーネントを設定する方法

SpringBoot2でActuatorコンポーネントを設定する方法

王林
王林転載
2023-05-14 08:46:111821ブラウズ

1. Actuator の概要

1. 監視コンポーネントの機能

本番環境では、サービスの可用性をリアルタイムまたは定期的に監視する必要があります。 Spring Boot のアクチュエーター (健全性監視) 機能は、アプリケーション システムの構成と表示、および関連する機能の統計の実行ができる、監視に必要な多くのインターフェイスを提供します。

2. モニタリング カテゴリ

Actuator は、モニタリング情報を表示するための Rest インターフェイスを提供します。
インターフェイスは 3 つの主要なカテゴリに分かれています。
アプリケーション構成クラス: アプリケーション構成、環境変数、アプリケーションにロードされた自動構成レポートなど、SpringBoot アプリケーションに関連する構成クラス情報を取得します。
Metric クラス: メモリ情報、スレッド プール情報、HTTP リクエスト統計など、アプリケーションの実行中の監視に使用されるメトリクスを取得します。
操作制御クラス:アプリケーションの終了などの操作機能を提供します。

2. SpringBoot2.0との統合.0

1. コア依存関係Jarパッケージ

<!-- 监控依赖 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2. Yml設定ファイル

# 端口
server:
  port: 8016
spring:
  application:
    # 应用名称
    name: node16-boot-actuator
management:
  endpoints:
    web:
      exposure:
        # 打开所有的监控点
        include: "*"
      # 自定义监控路径 monitor
      # 默认值:http://localhost:8016/actuator/*
      # 配置后:http://localhost:8016/monitor/*
      base-path: /monitor
  endpoint:
    health:
      show-details: always
    shutdown:
      # 通过指定接口关闭 SpringBoot
      enabled: true
  # 可以自定义端口
  # server:
  #   port: 8089
# 描述项目基础信息
info:
  app:
    name: node16-boot-actuator
    port: 8016
    version: 1.0.0
    author: cicada

3. モニタリングの詳細説明インターフェイス

1. 情報インターフェイス

##Yml ファイルで設定された基本的なプロジェクト情報##
路径:http://localhost:8016/monitor/info
输出:
{
    "app": {
        "name": "node16-boot-actuator",
        "port": 8016,
        "version": "1.0.0",
        "author": "cicada"
    }
}
##2. ヘルスインターフェイス

##ヘルスは主に実行中の状態を確認するために使用されます。アプリケーションのステータス

路径:http://localhost:8016/monitor/health
输出:
{
    "status": "UP",
    "details": {
        "diskSpace": {
            "status": "UP",
            "details": {
                "total": 185496236032,
                "free": 140944084992,
                "threshold": 10485760
            }
        }
    }
}

3. Beans インターフェース

は、Bean タイプ、単一インスタンスと複数インスタンス、エイリアス、クラスのフルパス、依存する Jar などを示します。

路径:http://localhost:8016/monitor/beans
输出:
{
    "contexts": {
        "node16-boot-actuator": {
        "beans": {
            "endpointCachingOperationInvokerAdvisor": {
                "aliases": [],
                "scope": "singleton",
                "type": "org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor",
                "resource": "class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.class]",
                "dependencies": ["environment"]
            }
        }
    }
}

4. 条件インターフェイス

設定が有効である条件、または自動設定が無効である理由を確認します。

路径:http://localhost:8016/monitor/conditions
输出:
{
    "contexts": {
        "node16-boot-actuator": {
            "positiveMatches": {
                "AuditAutoConfiguration#auditListener": [{
                    "condition": "OnBeanCondition",
                    "message": "@ConditionalOnMissingBean"
                }],
    }
}

5. HeapDump インターフェイス

Jvm ヒープ ダンプ ファイル HeapDump を自動的に生成します。監視ツール VisualVM を使用してこのファイルを開いて、メモリ スナップショットを表示できます。

路径:http://localhost:8016/monitor/heapdump

6. マッピング インターフェイス

URI パスとコントローラー間のマッピング関係を説明します

路径:http://localhost:8016/monitor/mappings
输出:
{
    "contexts": {
        "node16-boot-actuator": {
            "mappings": {
                "dispatcherServlets": {
                    "dispatcherServlet": [ {
                        "handler": "Actuator web endpoint 'auditevents'",
                        "predicate": "{GET /monitor/auditevents || application/json]}",
                        "details": {
                            "handlerMethod": {
                                "className": "org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping.Operat
                                "name": "handle",
                                "descriptor": "(Ljavax/servlet/http/HttpServletRequest;Ljava/util/Map;)Ljava/lang/Object;"
                            },
                            "requestMappingConditions": {
                                "consumes": [],
                                "headers": [],
                                "methods": ["GET"],
                                "params": [],
                                "patterns": ["/monitor/auditevents"],
                                "produces": [{
                                    "mediaType": "application/vnd.spring-boot.actuator.v2+json",
                                    "negated": false
                                }, {
                                    "mediaType": "application/json",
                                    "negated": false
                                }]
                            }
                        }
                    }
            }
    }
}

7. ThreadDump インターフェイス

スレッド名、スレッド ID、ロックを待機するかどうか、スレッドのステータス、スレッド ロック、およびその他の関連情報。

rree

以上がSpringBoot2でActuatorコンポーネントを設定する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はyisu.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。