Azure Monitor Exporter 設定
注意
Azure Metrics Exporter 使用時の料金案内
Azure Metrics Exporter は Azure Monitor API を通じてメトリクスを照会する方式であるため、照会するメトリクス数および API 呼び出し量に応じて Azure Monitor の使用料金が発生する場合があります。料金は Azure Monitor のメトリクスクエリ、API リクエストなどの使用量を基準に課金されます。詳細は Azure 公式料金表 をご参照ください。
事前準備
Azure サブスクリプションおよび権限要件
Azure リソースのメトリクスを収集するには、以下の権限が必要です。
| 権限 | 説明 | 範囲 |
|---|---|---|
| Monitoring Reader | Azure Monitor メトリクスの読み取り権限 | Subscription または Resource Group |
| Reader | リソース情報の照会(サービスディスカバリー用) | Subscription または Resource Group |
ノート
推奨設定
- 最小権限の原則に従い、
Monitoring Readerロールを使用 - 特定のリソースグループのみモニタリングする場合は、該当する範囲に限定
必要なAzureリソース情報の収集
Exporter の設定に必要な情報を事前に収集します。
| 項目 | 説明 | 例 |
|---|---|---|
| Subscription ID | Azure サブスクリプション識別子 | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| Tenant ID | Azure AD テナント識別子 | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| Client ID | 登録済みアプリの Application ID | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| Client Secret | アプリ認証用シークレットキー | xxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| Resource Group | リソースグループ名 | xxxxxxxxxx |
| Resource Name | リソース名(サーバー名/キャッシュ名/ネームスペース名/クラスター名など) | xxxxxxxxxx |
Azure Metrics Exporter インストール
Exporter ダウンロード
# linux/amd64 (x86_64)
wget https://repo.whatap.io/exporter/azure_metrics_exporter/amd64/azure_metrics_exporter
# linux/arm64 (aarch64)
wget https://repo.whatap.io/exporter/azure_metrics_exporter/arm64/azure_metrics_exporter
実行権限の付与とインストール
chmod +x azure_metrics_exporter
sudo mv azure_metrics_exporter /usr/local/bin/azure_metrics_exporter
sudo mkdir -p /etc/azure_metrics_exporter
azure.yml ファイルの設定
Tips
Azure Metrics Exporter を使用するには、収集対象リソースとメトリクスを定義する azure.yml 設定ファイルが必要です。収集するサービスとメトリクス項目を選択した後、設定ファイルをダウンロードして Exporter がインストールされているサーバーに配置します。
対応サービス一覧
主要な対応サービスは以下の通りです。各サービスの詳細なメトリクス定義は Azure 公式ドキュメントで確認できます。以下のリスト以外の追加サービスおよびメトリクス定義は Azure Monitor 公式ドキュメント で確認できます。
azure.yml サンプルファイル
# =============================================================================
# azure.yml example
# - credentials: authentication info (values collected in section 1.2)
# - targets: collect by directly specifying a resource
# - resource_groups: auto-discover by resource group + name regex
# - resource_tags: auto-discover by tag
# =============================================================================
credentials:
subscription_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
tenant_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
client_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
client_secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
targets:
# (1) No aggregations specified: collects all supported (Total/Average/Minimum/Maximum)
- resource: /resourceGroups/example-rg/providers/Microsoft.DBforPostgreSQL/flexibleServers/myserver
metrics:
- name: cpu_percent
- name: memory_percent
# (2) Resource-level aggregation: applied as the default to all metrics in this target
- resource: /resourceGroups/example-rg/providers/Microsoft.DBforPostgreSQL/flexibleServers/myserver
aggregations:
- Average
metrics:
- name: cpu_percent
- name: memory_percent
# (3) Metric-level aggregation: per-metric override (overrides the resource-level value)
- resource: /resourceGroups/example-rg/providers/Microsoft.DBforPostgreSQL/flexibleServers/myserver
aggregations:
- Average # default for this target
metrics:
- name: cpu_percent # -> Average (default applied)
- name: memory_percent # -> Average (default applied)
- name: storage_percent
aggregations:
- Maximum # -> Maximum (overridden at metric level)
- name: iops
aggregations:
- Total
- Maximum # -> Total, Maximum
# Auto-discover by resource group + name regex
resource_groups:
- resource_group: "webapps"
resource_types:
- "Microsoft.Compute/virtualMachines"
resource_name_include_re:
- "testvm.*" # include VMs whose name starts with testvm
resource_name_exclude_re:
- "testvm12" # exclude testvm12
metrics:
- name: "CPU Credits Consumed"
aggregations:
- "Average"
# Auto-discover by tag (resources tagged monitoring=enabled)
resource_tags:
- resource_tag_name: "monitoring"
resource_tag_value: "enabled"
resource_types:
- "Microsoft.Compute/virtualMachines"
metrics:
- name: "CPU Credits Consumed"
aggregations:
- "Average"
- "Maximum"
サービスの登録と起動
方法 A: systemd サービスの登録
sudo tee /etc/systemd/system/azure-metrics-exporter.service > /dev/null <<EOF
[Unit]
Description=Azure Metrics Exporter
After=network.target
[Service]
User=root
ExecStart=/usr/local/bin/azure_metrics_exporter --config.file=/etc/azure_metrics_exporter/azure.yml
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable azure-metrics-exporter
sudo systemctl start azure-metrics-exporter
sudo systemctl status azure-metrics-exporter
方法 B: nohup による実行
nohup /usr/local/bin/azure_metrics_exporter \
--config.file=/etc/azure_metrics_exporter/azure.yml \
> /var/log/azure_metrics_exporter.log 2>&1 &
メトリクス収集の確認とトラブルシューティング
# 全メトリクスの確認
curl http://localhost:9276/metrics
# PostgreSQL メトリクスのフィルタリング
curl http://localhost:9276/metrics | grep -i postgres
- 正常出力例
# HELP azure_microsoft_dbforpostgresql_flexibleservers_cpu_percent_percent_average
# TYPE azure_microsoft_dbforpostgresql_flexibleservers_cpu_percent_percent_average gauge
azure_microsoft_dbforpostgresql_flexibleservers_cpu_percent_percent_average{...} 3.5
- メトリクス名変換ルール:
azure_{namespace}_{メト リクス名}_{単位}_{集計方式}
トラブルシューティング
| 症状 | 原因 | 解決方法 |
|---|---|---|
401 Unauthorized | Azure 認証失敗 | credentials の入力値を確認 |
403 Forbidden | 権限不足 | サービスプリンシパルに Monitoring Reader 権限を付与 |
| メトリクス値なし | Enhanced メトリクス無効 | サーバーパラメーターを有効化 |
| サーバー停止状態 | DB が停止中 | az postgres flexible-server start を実行 |
OpenAgent ダウンロードと設定
すべてのファイルは同一ディレクトリに配置する必要があります。
## Example
/opt/whatap/openagent/
├── openagent # Executable file
├── whatap.conf # Configuration file
└── scrape_config.yaml # Scraping configuration file
ディレクトリの移動と実行ファイルのダウンロード
mkdir -p /opt/whatap/openagent
cd /opt/whatap/openagent
## AMD64 (Intel/AMD 64-bit processor)
wget https://repo.whatap.io/openagent/latest/amd/openagent
## ARM64 (ARM processor in Linux environment)
## CAUTION: macOS Apple Silicon not supported
wget https://repo.whatap.io/openagent/latest/arm/openagent
実行権限の設定
chmod +x openagent
scrape_config.yaml の作成
scrape_config.yaml ファイルが変更されると、OpenAgent は自動的に変更を検知して設定を再ロードします。個別の再起動は不要です。
#scrape_config.yaml
features:
openAgent:
enabled: true
targets:
- targetName: azure-monitor-exporter
type: StaticEndpoints
enabled: true
endpoints:
- address: "192.168.49.2:9276"
path: "/metrics"
scheme: "http"
interval: "30s"
metricRelabelConfigs:
- source_labels: [__name__]
regex: ".*"
action: keep
基本実行
./openagent standalone
バックグラウンド実行
nohup ./openagent standalone > /dev/null 2>&1 &
ログの確認
tail -f logs/whatap-boot-{yyyymmdd}.log
プロセス管理
# Check process
ps aux | grep openagent
# Terminate process
pkill openagent
StaticEndpoints 設定要素
- targetName: ターゲットの名前(識別用)
- type: ターゲットのタイプ("StaticEndpoints")
- endpoints: スクレイピングするエンドポイントの定義
address: スクレイピング対象のアドレス(IP:PORT または HOSTNAME:PORT)path: メトリクスパス(デフォルト値: /metrics)scheme: スクレイピングプロトコル(http または https、デフォルト値: http)interval: スクレイピング間隔(デフォルト値: 60s)metricRelabelConfigs: スクレイピング後のメトリクスリラベリング設定
params 機能の使い方
OpenAgent で params 機能を使用すると、HTTP メトリクススクレイピング時に URL クエリパラメーターを追加できます。
params 設定形式
endpoints:
- address: "192.168.49.2:30400"
path: "/metrics"
scheme: "http"
interval: "30s"
params:
subscription: ["50d91b57-a280-45b5-8d7c-be8005662738"]
resourceGroup: ["WhaTap-Data-KR-MID"]
target: ["/subscriptions/50d91b57-a280-45b5-8d7c-be8005662738/resourceGroups/WhaTap-Data-KR-MID/providers/Microsoft.Sql/managedInstances/openmetrics-instance-01"]
metric: ["avg_cpu_percent,virtual_core_count,memory_usage_percent"]
interval: ["PT1M"]
aggregation: ["average"]