GKE上で動かしているFluent Bitのメトリクスを簡単にGoogle Cloud Monitoring で可視化する方法を紹介します。
前提
- GKE クラスタで Fluent Bit が稼働している
- Google Cloud Managed Service for Prometheus が有効になっている(GKE 1.25以降はデフォルトで有効)
1. Fluent Bit の HTTP サーバーを有効化
Fluent Bit はビルトインの HTTP サーバーを持っており、Prometheus 形式でメトリクスを公開できます。
設定ファイルで HTTP サーバーを有効にします。
[SERVICE]
Http_Server On
Http_Listen 0.0.0.0
Http_Port 2020
これにより、Fluent Bit が /api/v2/metrics/prometheus エンドポイントで Prometheus 形式のメトリクスを公開します。
なお、/api/v1/metrics/prometheus もありますが、v2 の方が Filter メトリクスやレイテンシ histogram など取得できる情報が多いため、v2 を使うのがおすすめです。
2. PodMonitoring リソースを作成
GKE の PodMonitoring リソースを作成して、Fluent Bit のメトリクスを Cloud Monitoring に収集します。
apiVersion: monitoring.googleapis.com/v1
kind: PodMonitoring
metadata:
name: fluentbit-monitoring
namespace: default
spec:
selector:
matchLabels:
app: your-fluentbit-app # Fluent Bit の Pod に付与しているラベルに合わせる
endpoints:
- port: 2020
interval: 30s
path: /api/v2/metrics/prometheus
kubectl apply -f fluentbit-pod-monitoring.yaml
参考: Get started with managed collection
3. Cloud Monitoring で確認
Google Cloud Console の Metrics Explorer を開き、fluentbit で検索するとメトリクスが表示されます。
主なメトリクス:
| メトリクス | 説明 |
|---|---|
fluentbit_input_bytes_total |
Input プラグインが受信した総バイト数 |
fluentbit_input_records_total |
Input プラグインが受信した総レコード数 |
fluentbit_output_proc_bytes_total |
Output プラグインが処理した総バイト数 |
fluentbit_output_proc_records_total |
Output プラグインが処理した総レコード数 |
fluentbit_output_errors_total |
Output プラグインのエラー数 |
fluentbit_output_retries_total |
Output プラグインのリトライ数 |