
サーバー メトリック監視用の Grafana が好きですか? Web サイト監視用の Blackbox Exporter も気に入るはずです!
このチュートリアルでは、CentOS/RHEL に Blackbox Exporter をインストールする方法を学習し、それを Prometheus および Grafana で使用して Web サイトのパフォーマンスとアップタイムを監視する方法を理解します。
Blackbox Exporter とは?
ブラックボックス エクスポーター by Prometheus は、HTTPS、HTTP、TCP、DNS、ICMP などのエンドポイントをプローブするために使用されます。 エンドポイントを定義すると、Blackbox エクスポーターは、Grafana を使用して視覚化できる数百のメトリックを生成します。 応答時間の測定は、Blackbox エクスポーターの最も重要な機能です。
Blackbox Exporter は自己ホスト型ソリューションです。 似たようなものを探しているが、SaaS またはクラウドベースのものを探している場合は、Grafana worldPing を試すことができます。
前提条件
Prometheus と Grafana がプリインストールされている必要があります。 この記事に従って、Prometheus と Grafana をインストールします。
Blackbox エクスポーターのインストール
最初に Blackbox exporter をインストールする方法をお見せしましょう。
ステップ 1: Blackbox Exporter をダウンロードする
に行く 公式ページ 最新の Linux AMD Blackbox エクスポーター パッケージをダウンロードします。 blackbox_exporter-0.16.0.linux-amd64.tar.gz ファイルをダウンロードしています。
- ダウンロードしたファイルをサーバーに転送する
- パッケージからファイルを抽出します。
[[email protected] ~]$ tar -xzf blackbox_exporter-0.16.0.linux-amd64.tar.gz
Blackbox エクスポーター内のすべてのファイルを確認します。
[[email protected] ~]$ cd blackbox_exporter-0.16.0.linux-amd64/ [[email protected] blackbox_exporter-0.16.0.linux-amd64]$ ls -l total 16672 -rwxr-xr-x. 1 centos centos 17050332 Nov 11 2019 blackbox_exporter -rw-r--r--. 1 centos centos 629 Nov 11 2019 blackbox.yml -rw-r--r--. 1 centos centos 11357 Nov 11 2019 LICENSE -rw-r--r--. 1 centos centos 94 Nov 11 2019 NOTICE
ここでは、blackbox_exporter と blackbox.yml の 2 つのファイルが重要です。
- blackbox_exporter: サービスを実行するための実行ファイルです。
- blackbox.yml: プローブするすべてのエンドポイントと実行するモジュールを定義するすべてのバックボックス エクスポーター構成を含む YAML ファイル。
以下のコマンドは、Blackbox エクスポーターで使用できるすべてのフラグを提供します。
[[email protected] blackbox_exporter-0.16.0.linux-amd64]$ ./blackbox_exporter -h usage: blackbox_exporter [<flags>] Flags: -h, --help Show context-sensitive help (also try --help-long and --help-man). --config.file="blackbox.yml" Blackbox exporter configuration file. --web.listen-address=":9115" The address to listen on for HTTP requests. --timeout-offset=0.5 Offset to subtract from timeout in seconds. --config.check If true validate the config file and then exit. --history.limit=100 The maximum amount of items to keep in the history. --web.external-url=<url> The URL under which Blackbox exporter is externally reachable (for example, if Blackbox exporter is served via a reverse proxy). Used for generating relative and absolute links back to Blackbox exporter itself. If the URL has a path portion, it will be used to prefix all HTTP endpoints served by Blackbox exporter. If omitted, relevant URL components will be derived automatically. --web.route-prefix=<path> Prefix for the internal routes of web endpoints. Defaults to path of --web.external-url. --log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error] --log.format=logfmt Output format of log messages. One of: [logfmt, json] --version Show application version.
ステップ 2: Blackbox のユーザーを作成する
これはオプションです。
新しいユーザーを作成して Blackbox を実行するか、既存の Prometheus ユーザーを使用して実行することができます。
アクセス許可を提供し、すべてのファイルの所有権を新しいユーザーに割り当てます。
[[email protected] ~]$ sudo useradd -rs /bin/false blackbox [[email protected] ~]$ sudo chmod -R 777 /home/centos/blackbox_exporter-0.16.0.linux-amd64 [[email protected] ~]$ sudo chown -R blackbox:blackbox /home/centos/blackbox_exporter-0.16.0.linux-amd64
ステップ 3: Blackbox サービスを構成する
Blackbox Exporter を systemd 内のサービスとして設定する時が来ました。 ファイル blackbox.service を作成し、以下の行をファイルに追加して保存します。
[[email protected] ~]$ sudo gedit /etc/systemd/system/blackbox.service [Unit] Description=Blackbox Exporter Service Wants=network-online.target After=network-online.target [Service] Type=simple User=blackbox Group=blackbox ExecStart=/home/centos/blackbox_exporter-0.16.0.linux-amd64/blackbox_exporter --config.file==/home/centos/blackbox_exporter-0.16.0.linux-amd64/blackbox.yml [Install] WantedBy=multi-user.target
抽出した実際の場所へのパスを変更することを忘れないでください。
ステップ 4: Blackbox Exporter を起動する
以下のコマンドを実行して、Blackbox エクスポーターをサービスとして開始します。
[[email protected] ~]$ sudo systemctl daemon-reload [[email protected] ~]$ sudo systemctl start blackbox.service [[email protected] ~]$ sudo systemctl status blackbox.service ● blackbox.service - Blackbox Exporter Service Loaded: loaded (/etc/systemd/system/blackbox.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2020-06-13 17:28:40 EDT; 1s ago Main PID: 30427 (blackbox_export) Tasks: 5 CGroup: /system.slice/blackbox.service └─30427 /usr/local/bin/blackbox_exporter --config.file=/etc/blackbox.yml Jun 13 17:28:40 etechjp.com.linuxvmimages.com systemd[1]: Started Blackbox Exporter Service. Jun 13 17:28:40 etechjp.com.linuxvmimages.com blackbox_exporter[30427]: level=info ts=2020-06-13T21:28:40.283Z caller=main.go:212 msg="Starting b...b9a9)" Jun 13 17:28:40 etechjp.com.linuxvmimages.com blackbox_exporter[30427]: level=info ts=2020-06-13T21:28:40.283Z caller=main.go:213 msg="Build cont...SSING) Jun 13 17:28:40 etechjp.com.linuxvmimages.com blackbox_exporter[30427]: level=info ts=2020-06-13T21:28:40.283Z caller=main.go:225 msg="Loaded config file" Jun 13 17:28:40 etechjp.com.linuxvmimages.com blackbox_exporter[30
すごい!
Blackbox エクスポーターが正常に開始されました。 http://localhost:9115/ で、Blackbox Exporter が実行されていることがわかります。
Blackbox と Prometheus の統合
Blackbox Exporter を Prometheus と統合して、メトリクスのスクレイピングを開始しましょう。
- prometheus.yml ファイル内に以下の構成でブラックボックス ジョブを追加します。 https://www.telegraph.co.uk のパフォーマンスを監視します。
[[email protected] ~]$ sudo gedit /etc/prometheus/prometheus.yml - job_name: 'blackbox' metrics_path: /probe params: module: [http_2xx] # Look for a HTTP 200 response. static_configs: - targets: - https://www.telegraph.co.uk relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 127.0.0.1:9115 # The blackbox exporter's real hostname:port.
[[email protected] ~]$ sudo systemctl restart prometheus.service
- http://localhost:9090/targets でターゲットをもう一度確認すると、定義したエンドポイントで実行されているブラックボックス ジョブが見つかります。
- グラフをクリックし、クエリ – probe_http_duration_seconds を実行します。
- Prometheus によって監視されているデータに視覚化が作成されます。
今度は、Grafana で Blackbox ジョブを視覚化します。
開始するには多くの方法がありますが、最も簡単な方法の 1 つは、既製のダッシュボードから開始することです。 Prometheus Blackbox エクスポーター.
- Grafana ダッシュボードに移動し、+ 記号をクリックして、[インポート]をクリックします。
- [Grafana.com からのインポート]で、ダッシュボード ID 7587 を入力し、[読み込み]をクリックします。
- 次に、Prometheus データ ソースを選択し、[インポート]をクリックします。
- Prometheus Blackbox Exporter ダッシュボードがインポートされます。
- グローバル プローブ期間、ステータス、HTTP 期間、平均プローブ期間、平均 DNS ルックアップ、SSL 有効期限などのメトリックを視覚化できます。
- これらはすべて、ダッシュボード上の個別のパネルです。 HTTP Duration パネルの詳細をお見せしましょう。 このパネルには、接続、処理、解決、TLS、および転送要求にかかった時間が視覚化されて表示されます。
ダッシュボードには、さまざまなオプションが用意されています。 ビジュアライゼーションを表示する時間範囲を変更できます。 データ更新の時間間隔を変更することもできます。 ここでは、新しいデータが 5 秒ごとにダッシュボードに表示されます。
- HTTP Duration の下向き矢印をクリックすると、以下に示すオプションが表示されます。 編集をクリックします。
- 視覚化パネルの下に、クエリ エディターが表示されます。 現在、以下のスナップショットに示されているクエリが視覚化されています – probe_http_duration_seconds.
- 要件に応じて、簡単に視覚化してダッシュボードに追加できるクエリが何百もあります。
- 視覚化タイプを変更するためのオプションもたくさんあります。 平均プローブ時間は、ダッシュボードにテキスト形式で表示されます。 右側の視覚化パネルから、平均プローブ時間のゲージ オプションをクリックします。
- そして、これが視覚化がどのように変化するかです。
結論
上記は、Prometheus Blackbox と Grafana を使用して Web サイトを監視することがいかに簡単かを示すためのものです。 たくさんのオプションがあり、それを試してみることを強くお勧めします。 Grafana の学習に興味がある場合は、彼の記事をチェックしてください。 オンラインコース.
記事を読んでよかったですか? 世界と共有してみませんか?