春ブーツアクチュエータ統合プロメテウス

簡単な紹介

春ブーツ独自の監視アクチュエーター、このような状況、豆の荷重条件、環境変数、ログ情報、スレッド情報を監視して、監視プログラムの内部動作を達成するのを助けることができます。プロメテウス、Grafanaと組み合わせこのセクションでは、情報のより直感的に表示すること。

実験

説明

サービス名 アドレス ポート
プロメテウス 172.16.2.101 9090
Grafana 172.16.2.101 3000
春ブーツデモ 172.16.2.204 8080

プロジェクトを作成します。

テスト春ブートプロジェクトを作成し、メインのコードは次のようです。

pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

application.yml

management:
  endpoints:
    web:
      exposure:
        include: '*'

  endpoint:
    health:
      show-details: always

  metrics:
    tags:
      application: actuator-demo
  • management.endpoints.web.exposure.include:ほとんどのアクチュエータポートは、これらすべての公共のエンドポイントに代わって、HTTP経由で開く*されていません。本番環境のために、あなたは慎重に公衆にエンドポイントを選択する必要があります。
  • management.metrics.tags.application:タグを設定するアプリケーション、簡単に別のアプリケーションを区別します。

スタートアップクラス

@SpringBootApplication
@RestController
public class SpringbootActuatorPrometheusDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootActuatorPrometheusDemoApplication.class, args);
    }

    @RequestMapping(value = "/hello")
    public String  sayHello() {
        for (int i = 1 ; i <= 10 ; i++) {
            Thread t = new Thread(() -> {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } , "HelloThread - " + i);
            t.start();
        }
        return "ok";
    }

    /**
    @Bean
    MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
        return registry -> registry.config().commonTags("application", "springboot-actuator-prometheus-demo");
    }
    */

}

プロメテウスとGrafanaの設定

prometheus.yml春ブートアプリケーションの監視ジョブを追加します。

- job_name: 'actuator-demo'
    metrics_path: '/prometheus'
    static_configs:
    - targets: ['172.16.2.204:8080']

プロメテウスの実行とGrafana:

docker start prometheus grafana

UIプロメテウス訪問http://172.16.2.101:9090を、ターゲットを参照してください、あなたは、設定が正常に行われた、UP状態で仕事を見ることができます。

春ブーツアクチュエータ統合プロメテウス

UI Grafana Grafanaてhttp://172.16.2.101:3000、 +導入のアイコン(インポート)JVM(マイクロメートル)ダッシュボード :

  • grafana番号= 4701
  • データ・ソースは、プロメテウスが選択されていることに注意してください

JVM(Micormeter)ダッシュボードを表示します。

春ブーツアクチュエータ統合プロメテウス

あなたはなど、アプリケーションのJVMスタック、スレッド、IOなどを見ることができます。

ソース

https://github.com/gf-huanchupk/SpringBootLearning/tree/master/springboot-actuator-prometheus

参照

https://micrometer.io/docs/registry/prometheus
https://prometheus.io/docs/prometheus

おすすめ

転載: blog.51cto.com/13698036/2444354