Skip to content

Latest commit

 

History

History
732 lines (497 loc) · 27.8 KB

README.ja.md

File metadata and controls

732 lines (497 loc) · 27.8 KB

Create ReleaseGenerate HTMLSlack Notification

ContributorsForksStargazersIssuesMIT LicenseLinkedIn


observability

Learning Observability

Project for learning about Learning Observability.
Explore the docs »

Project Page - Report Bug - Request Feature


Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

プロジェクトについて

このプロジェクトは可観測性について学ぶためのものです。

(back to top)


で構築

  • Github
  • GNULinux
  • Windows
  • Bash
  • Powershell
  • Kubernetes

(back to top)


はじめる

このプロジェクトは、ラーニング オブザーバビリティ ツールとベスト プラクティスを開始するためのものです。

学習用のいくつかのツール:

  • プロメテウス
  • アラートマネージャー
  • グラファナ
  • グラファナ・ロキ
  • グラファナ時間

前提条件

  • Linux システムアップ
  • クラスタ Kubernetes アップ
  • ギット

インストール

リポジトリのクローンを作成する

git clone https://github.com/marcossilvestrini/learning-observability.git
cd learning-observability || exit

(back to top)


使用法

このリポジトリで使用するためにいくつかの例を公開します。

(back to top)


ロードマップ

  • リポジトリの作成
  • プロメテウス
  • アラートマネージャー
  • グラファナ
  • グラファナ・ロキ
  • グラファナ時間
  • グラファナ合金
  • Others tools

を参照してください。未解決の問題提案された機能 (および既知の問題) の完全なリストについては、こちらをご覧ください。

(back to top)


プロメテウス

prometheus

Prometheus は、もともと SoundCloud で構築されたオープンソースのシステム監視および警告ツールキットです。

2012 年の開始以来、多くの企業や組織が Prometheus を採用しており、このプロジェクトには非常に活発な開発者とユーザーのコミュニティがあります。

Prometheus エコシステムは複数のコンポーネントで構成されており、その多くはオプションです。

  • 時系列データを収集して保存するメインの Prometheus サーバー
  • アプリケーション コードをインストルメントするためのクライアント ライブラリ
  • 短期間のジョブをサポートするためのプッシュ ゲートウェイ
  • HAProxy、StatsD、Graphite などのサービスの専用エクスポーター。
  • アラートを処理するためのアラートマネージャー
  • 各種サポートツール

Prometheus の詳細については、公式ドキュメントにアクセスしてください。
hっtps://pろめてぇうs。いお/どcs/いんtろづcちおん/おゔぇrゔぃえw/

メトリック名とラベル

メトリクス名の例:

<metric name>{<label name>=<label value>, ...}

ラベル付きのメトリック名の例:

api_http_requests_total{method="POST", handler="/messages"}

メトリクスのタイプ

Metrics Type

カウンター– 時間の経過とともに増加する値のみを受け入れて保存します。
ゲージ– 異なる値を取ることができ、増加と減少の両方が可能な値を保存します。
ヒストグラム– 観測値 (通常はリクエスト期間や応答サイズなど) をサンプリングし、構成可能なバケットにカウントします。また、すべての観測値の合計も提供されるため、平均を計算することもできます。
まとめ– 追加の統計 (分位数) を使用した、より詳細なデータ表現のヒストグラム。

ジョブとインスタンス

Jobs

Prometheus の用語では、スクレイピングできるエンドポイントはインスタンスと呼ばれ、通常は単一のプロセスに対応します。
同じ目的を持つインスタンスの集合、たとえばスケーラビリティや信頼性のために複製されたプロセスは、ジョブと呼ばれます。

Prometheus のリモート書き込み仕様

リモート書き込みプロトコルは、サンプルを損失なく、送信側から受信側にリアルタイムで確実に伝播できるように設計されています。

  • 「送信者」とは、Prometheus Remote Write データを送信するものです。
  • 「レシーバー」とは、Prometheus Remote Write データを受信するものです。
  • 「サンプル」は (タイムスタンプ、値) のペアです。
  • 「ラベル」は(キー、値)のペアです。
  • 「シリーズ」とは、一意のラベルのセットによって識別されるサンプルのリストです。

互換性のある送信機と受信機

この仕様は、次のコンポーネントがどのように相互作用するかを説明することを目的としています。

  • プロメテウス (「送信者」と「受信者」の両方として)
  • Avalanche (「送信者」として) - 負荷テスト ツール Prometheus メトリクス。
  • Cortex (「受信機」として)
  • 弾性エージェント(「レシーバー」として)
  • Grafana エージェント (「送信者」と「受信者」の両方として)
  • GreptimeDB (「受信者」として)
  • InfluxData の Telegraf エージェント。 (送り手としても受け手としても)
  • M3 (「受信機」として)
  • ミーミル(「受信者」として)
  • OpenTelemetry Collector (「送信者」として、最終的には「受信者」として)
  • サノス(「受信者」として)
  • ベクトル (「送信者」および「受信者」として)
  • VictoriaMetrics (「受信者」として)

promql

Prometheus は、ユーザーがリアルタイムで時系列データを選択して集計できるようにする PromQL (Prometheus Query Language) と呼ばれる関数型クエリ言語を提供します。
式の結果は、グラフとして表示したり、Prometheus の式ブラウザで表形式のデータとして表示したり、HTTP API を介して外部システムで使用したりすることができます。

クエリの例

federation

フェデレーションにより、Prometheus サーバーは、選択した時系列を別の Prometheus サーバーから収集できます。

階層連合

階層的なフェデレーションにより、Prometheus は数十のデータセンターと数百万のノードを持つ環境に拡張できます。

この使用例では、フェデレーション トポロジはツリーに似ており、上位の Prometheus サーバーが多数の下位サーバーから集約された時系列データを収集します。

これは、小規模なサーバーから時系列データを収集する、より大きな Prometheus サーバーがあることを意味します。当社では、さまざまなレベルからデータを収集するトップダウンのアプローチをとっています。

federation-hierarchical

クロスサービスフェデレーション

この方法では、1 つの Prometheus サーバーが特定のサービスまたはサービスのグループを監視し、別のサービスのセットを監視している別のサーバーから特定の時系列データを収集します。

たとえば、複数のサービスを実行しているクラスター スケジューラは、クラスター上で実行されているサービス インスタンスに関するリソース使用量情報 (メモリや CPU 使用量など) を公開する可能性があります。

一方、そのクラスター上で実行されているサービスは、アプリケーション固有のサービス メトリックのみを公開します。

多くの場合、これら 2 つのメトリクス セットは、別個の Prometheus サーバーによって取得されます。フェデレーションを使用すると、サービスレベルのメトリクスを含む Prometheus サーバーは、クラスタ Prometheus からその特定のサービスに関するクラスタ リソース使用量メトリクスを取得できるため、そのサーバー内で両方のメトリクス セットを使用できます。

こうすることで、両方のサーバーからの結合されたデータに対してクエリとアラートを実行できます。

cross-service-federation

HTTP サービスの検出

http_sd

Prometheus は、HTTP エンドポイント経由でターゲットを検出できるようにする汎用 HTTP サービス検出を提供します。

HTTP サービス ディスカバリは、サポートされているサービス ディスカバリ メカニズムを補完するものであり、ファイルベースのサービス ディスカバリに代わるものです。

  • static_configs は、インスタンスが頻繁に追加/削除されるような、より動的な環境には拡張できません。
  • Prometheus はサービス検出メカニズムと統合して、実行中のインスタンスのビューを自動的に更新できます
    • 新しいインスタンスが追加されると、Prometheus はスクレイピングを開始します。検出から失われた場合、時系列も削除されます
    • Consul、Azure、AWS との組み込み統合、またはカスタム メカニズムが必要な場合はファイル ベース
  • JSON/YAML ファイルは、スクレイピング元のすべてのターゲットを指定してプラットフォームによって公開できます。 Prometheus はこれを使用してターゲットを自動的に更新します

Example using http sd_file

http_file_sd

ターゲット http_sd.json 内のサービスをスクラップするための prometheus.yaml

global:
  scrape_interval: 15s
  evaluation_interval: 15s
scrape_configs:  
  # Service Discovery with file_sd  
  - job_name: 'http_sd'
    basic_auth:
      username: "skynet"
      password: "prometheus"
    file_sd_configs:
      - files:
        - /home/vagrant/prometheus-server/http_sd.json

http_sd.json

[
    {
        "targets": ["192.168.0.130:9100", "192.168.0.131:9100"],
        "labels": {            
            "__meta_prometheus_job": "node"
        }
    },
    {
        "targets": ["192.168.0.130:9091"],
        "labels": {            
            "__meta_prometheus_job": "pushgateway"
        }
    }    
]

プロメテウスをインストールする

# Download files - https://prometheus.io/download/
wget https://github.com/prometheus/prometheus/releases/download/v2.51.2/prometheus-2.51.2.linux-amd64.tar.gz

# Extract files
tar xvfz prometheus-*.tar.gz
rm  prometheus-*.tar.gz
cd prometheus-*

# Check version
./prometheus --version

プロメテウスの構成

私の設定ファイルを参照してくださいプロメテウス.yaml

vim prometheus.yaml
# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # 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:
          # - alertmanager:9093

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

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]

プロメテウスを起動する

# Start
./prometheus --config.file=prometheus.yml

# Start with PM2 - npm install pm2@latest -g
pm2 start prometheus --name prometheus-server -- --config.file=prometheus.yml

重要なエンドポイント

http://localhost:9090 # all endpoints
http://localhost:9090/graph # PromQL expressions
http://localhost:9090/metrics # metrics
http://localhost:9090/targets # scrape_configs jobs

式ブラウザの使用

式はテーブル モードまたはグラフ モードで使用できます。

ページ http://localhost:9090 を開きます

# Check all http metrics
promhttp_metric_handler_requests_total

# Check http metrics with http status code 200
promhttp_metric_handler_requests_total{code="200"}

# Count http metrics
count(promhttp_metric_handler_requests_total)

# Rate function
rate(promhttp_metric_handler_requests_total{code="200"}[1m])

プロメテウスエクスポーター

エクスポータは、メトリクスを取得するアプリケーションと一緒に実行されるバイナリです。
エクスポータは、通常、非 Prometheus 形式で公開されているメトリクスを Prometheus がサポートする形式に変換することによって、Prometheus メトリクスを公開します。

ノードエクスポーター

Prometheus Node Exporter は、さまざまなハードウェアおよびカーネル関連のメトリクスを公開します。

ノードエクスポーターのインストール
# Download - https://prometheus.io/download#node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz

# Extract
tar xvfz node_exporter-*.*-amd64.tar.gz
cd node_exporter-*.*-amd64
ノードエクスポーターの開始
# Start
./node_exporter

# Start with PM2 - npm install pm2@latest -g
pm2 start node_exporter --name node_exporter
エンドポイントノードエクスポーター
# Access metrics
http://localhost:9100/metrics
ノードエクスポーターの構成

ノード エクスポーターのスクラップを有効にするために、prometheus を設定できます。

# Edit prometheus file and add job node
vim prometheus.yaml
...
scrape_configs:
- job_name: node
  static_configs:
  - targets: ['localhost:9100']
...

新しいジョブを適用するために prometheus サービスを再起動します。


プッシュゲートウェイ

Prometheus Pushgateway は、一時ジョブやバッチ ジョブがメトリクスを Prometheus に公開できるようにする仲介サービスです。
この種のジョブはスクレイピングできるほど長く存在しない可能性があるため、代わりにメトリクスを Pushgateway にプッシュできます。
Pushgateway は、Prometheus が収集する一時的なメトリクス ストアとして機能します。

この設定は、CI システムのバッチ ジョブや、スケジュールされた時間に実行されるバックアップ スクリプトなど、継続的に実行されないジョブの結果を取得する場合に特に役立ちます。
これにより、ジョブ自体が存続する可能性がある長寿命の Prometheus インスタンスを実行する必要がなく、この種のジョブの監視が簡素化されます。

プッシュゲートウェイのインストール

# Download 
wget -q https://github.com/prometheus/pushgateway/releases/download/v1.8.0/pushgateway-1.8.0.linux-amd64.tar.gz

# Extract
tar xvfz pushgateway-*.*-amd64.tar.gz
cd pushgateway-*.*-amd64

# Start 
# Start with PM2 - npm install pm2@latest -g
pm2 start pushgateway --name pushgateway -- --web.listen-address "192.168.0.130:9091"

プッシュゲートウェイの構成

# Edit prometheus file and add job pushgateway
vim prometheus.yaml
scrape_configs:
  - job_name: 'pushgateway'
    honor_labels: true
    static_configs:
      - targets: ['192.168.0.130:9091'] # prometheus server for scraping
# Restart prometheus

# restart with pm2
pm2 restart prometheus-server

テストプッシュゲートウェイのメトリクスを作成する

echo 'training_completion{course="CKA", status="complete"} 1' > metrics.txt
echo 'training_completion{course="CKS", status="in_progress"} 0.5' >> metrics.txt
echo 'training_completion{course="LPIC2", status="not_started"} 0' >> metrics.txt
curl --data-binary @metrics.txt http://192.168.0.130:9091/metrics/job/training_metrics
エンドポイントプッシュゲートウェイ
# Access metrics
http://localhost:9091

PromQL を使用してメトリクスのプッシュゲートウェイ ターゲットを検索する

promql-pushgateway

プロムレンス

プロムレンズのインストール

基本認証なしでのみ動作します

echo "Downloading Promlens..."
wget -q https://github.com/prometheus/promlens/releases/download/v0.3.0/promlens-0.3.0.linux-amd64.tar.gz

echo "Extracting Promlens..."
tar xvfz promlens-*.*-amd64.tar.gz
rm promlens-*.*-amd64.tar.gz
cd promlens-*.*-amd64 || exit

echo "Starting Promlens..."
pm2 start promlens --name promlens -- --web.listen-address "192.168.0.130:8081"
cd || exit

プロムレンスのエンドポイント

# Access query builder
http://192.168.0.130:8081

promlens


アラートマネージャー

alertmanager

Alertmanager の詳細については、公式ドキュメントにアクセスしてください。
hっtps://ぎてゅb。こm/pろめてぇうs/あぇrtまなげr

(back to top)


グラファナ


グラファナ・ロキ


グラファナ時間


グラファナ合金

(back to top)


貢献する

オープンソース コミュニティを学び、インスピレーションを与え、創造するための素晴らしい場所にするのは、貢献のおかげです。あなたが行う貢献はすべて、とても感謝しています

これを改善するための提案がある場合は、リポジトリをフォークしてプル リクエストを作成してください。 「拡張」タグを付けて問題を開くこともできます。 プロジェクトにスターを付けることを忘れないでください。再度、感謝します!

  1. プロジェクトをフォークする
  2. 機能ブランチを作成します (git checkout -b feature/AmazingFeature
  3. 変更をコミットします (git commit -m 'Add some AmazingFeature'
  4. ブランチにプッシュ (git push origin feature/AmazingFeature
  5. プルリクエストを開く

(back to top)


ライセンス

MIT ライセンスに基づいて配布されます。見るLICENSE詳細については。

(back to top)


接触

プロジェクトリンク:hっtps://ぎてゅb。こm/まrこっしlゔぇstりに/ぇあrにんgーおbせrゔぁびぃty

(back to top)


謝辞

(back to top)