プロメテウスを使用して春の雲を監視する

一緒に書く習慣を身につけましょう!「ナゲッツデイリーニュープラン・4月アップデートチャレンジ」に参加して6日目です。クリックしてイベントの詳細をご覧ください

プロメテウス

Cloud Native Computing FoundationプロジェクトであるPrometheusは、システムおよびサービスの監視システムです。指定された間隔で構成されたターゲットからメトリックを収集し、ルール式を評価し、結果を表示し、指定された条件が観察されたときにアラートをトリガーします。

Prometheusと他のメトリックおよび監視システムとの違いは次のとおりです。

  • 多次元データモデル(メトリック名とキー/値ディメンションのセットによって定義される時系列)
  • PromQL、この次元を活用する強力で柔軟なクエリ言語
  • 分散ストレージに依存しません。個々のサーバーノードは自律的です
  • 時系列収集用のHTTPプルモデル
  • ****バッチジョブの中間ゲートウェイを介したプッシュ時系列のサポート
  • サービス検出または静的構成によるターゲットの検出
  • グラフとダッシュボードでサポートされる複数のモード
  • 階層的および水平的結合のサポート

アーキテクチャの概要

インストール

プラットフォーム用のPrometheusの最新バージョンをダウンロードし、解凍して実行します。

tar xvfz prometheus-*.tar.gz
cd prometheus-*
复制代码

Prometheusを起動する前に、構成しましょう。

prometheus.yml

# my global config
global:
  scrape_interval:     10s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 10s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
       - 127.0.0.1:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  - "rules/*.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # 配置job,可以同时配置多个服务
  - job_name: 'name1'
    metrics_path: '/actuator/prometheus'
    scrape_interval: 5s
    scheme: "https"
    static_configs:
      - targets: ['xxx.com']

  - job_name: 'name2'
    metrics_path: '/actuator/prometheus'
    scrape_interval: 5s
    scheme: "http"
    static_configs:
      - targets: ['abc.com']
复制代码

アラームルールの監視

rules/xx_rules.yml

groups:
- name: nqi-down
  rules:
  - alert: gx-node-down
    expr: up{instance="xxx.com:443"} == 0
    for: 10s
    labels:
      status: High
      team: xxx
    annotations:
      description: "xxx is Down ! ! !"
      summary:  "xxx服务停了,请留意!!!"
      
  - alert: test-node-down
    expr: up{instance="abc.com:80"} == 0
    for: 5s
    labels:
      status: Warn
      team: test
    annotations:
      description: "abc is Down ! ! !"
      summary:  "abc服务停了,请留意!!!"
复制代码

alertmanagerをインストールして抽出します

tar xvfz alertmanager-*.tar.gz
cd alertmanager-*
复制代码

構成、設定

alertmanager.yml

global: 
  resolve_timeout: 5m #解析的超时时间
  smtp_smarthost: 'smtp.xxx.com:465' #邮箱smtp地址
  smtp_from: '[email protected]' #来自哪个邮箱发出的
  smtp_auth_username: '[email protected]' #邮箱的用户名
  smtp_auth_password: 'W7CKmqD2x0iGXM9R' #这里是邮箱的授权密码,不是登录密码
  smtp_require_tls: false #是否启用tls

templates:
  - ./email.html

route:
  group_by: ['abc']
  group_wait: 3s
  group_interval: 10s
  repeat_interval: 3h
  receiver: 'mail'
receivers:
- name: 'mail'
  email_configs: #email的配置
  - to: '[email protected], [email protected]' #报警接收人的邮件地址
    send_resolved: true  #发送恢复通知
    html: '{{ template "email.html" . }}'
inhibit_rules:
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['alertname', 'dev', 'instance']
复制代码

コード

pomの依存関係を追加する

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

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
复制代码

application.propertiesは構成を増やします

#监控
management.endpoints.web.exposure.include=prometheus
复制代码

Grafanaをインストールする

wget <https://dl.grafana.com/enterprise/release/grafana-enterprise-8.4.6.linux-amd64.tar.gz>\
tar -zxvf grafana-enterprise-8.4.6.linux-amd64.tar.gz
复制代码

Grafanaリファレンス構成

データソースを追加する

pro.png

gra.png

ダッシュボードのインポート

import.png

ダッシュボードテンプレートマーケット

dash.png

dashb.png

参照プロジェクト

おすすめ

転載: juejin.im/post/7087849471849005092