本文へスキップ

Azure Monitor Exporter 設定

注意

Azure Metrics Exporter 使用時の料金案内

Azure Metrics Exporter は Azure Monitor API を通じてメトリクスを照会する方式であるため、照会するメトリクス数および API 呼び出し量に応じて Azure Monitor の使用料金が発生する場合があります。料金は Azure Monitor のメトリクスクエリ、API リクエストなどの使用量を基準に課金されます。詳細は Azure 公式料金表 をご参照ください。

事前準備

Azure サブスクリプションおよび権限要件

Azure リソースのメトリクスを収集するには、以下の権限が必要です。

権限説明範囲
Monitoring ReaderAzure Monitor メトリクスの読み取り権限Subscription または Resource Group
Readerリソース情報の照会(サービスディスカバリー用)Subscription または Resource Group
ノート

推奨設定

  • 最小権限の原則に従い、Monitoring Reader ロールを使用
  • 特定のリソースグループのみモニタリングする場合は、該当する範囲に限定

必要なAzureリソース情報の収集

Exporter の設定に必要な情報を事前に収集します。

項目説明
Subscription IDAzure サブスクリプション識別子xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Tenant IDAzure AD テナント識別子xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Client ID登録済みアプリの Application IDxxxxxxxx-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 公式ドキュメント で確認できます。

ServiceAzure Docs
Microsoft.Compute virtualMachineshttps://learn.microsoft.com/en-us/azure/azure-monitor/reference/supported-metrics/microsoft-compute-virtualmachines-metrics
Microsoft.ContainerService managedClustershttps://learn.microsoft.com/en-us/azure/aks/monitor-aks-reference
Microsoft.Storage storageAccountshttps://learn.microsoft.com/en-us/azure/azure-monitor/reference/supported-metrics/microsoft-storage-storageaccounts-metrics
Microsoft.Sql servers databaseshttps://learn.microsoft.com/en-us/azure/azure-sql/database/monitoring-sql-database-azure-monitor-reference
Microsoft.DBforPostgreSQL flexibleServershttps://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-monitoring
Microsoft.DBforMySQL flexibleServershttps://learn.microsoft.com/en-us/azure/mysql/flexible-server/concepts-monitoring
Microsoft.DocumentDB databaseAccountshttps://learn.microsoft.com/en-us/azure/cosmos-db/monitor-cosmos-db
Microsoft.Cache redishttps://learn.microsoft.com/en-us/azure/redis/monitor-cache
Microsoft.EventHub namespaceshttps://learn.microsoft.com/en-us/azure/event-hubs/monitor-event-hubs-reference
Microsoft.ServiceBus namespaceshttps://learn.microsoft.com/en-us/azure/service-bus-messaging/monitor-service-bus-reference
Microsoft.KeyVault vaultshttps://learn.microsoft.com/en-us/azure/key-vault/general/monitor-key-vault
Microsoft.Network applicationGatewayshttps://learn.microsoft.com/en-us/azure/application-gateway/monitor-application-gateway

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 UnauthorizedAzure 認証失敗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"]

対応するパラメーター値のタイプ

  • 文字列: 単一の値
  • 文字列配列: 複数の値をカンマで連結
  • その他のタイプ: 自動的に文字列へ変換

メトリクスリラベリング設定(metricRelabelConfigs)

OpenAgent は Prometheus の metric_relabel_configs と同様のメトリクスリラベリング機能をサポートしています。

リラベリング設定要素

  • source_labels: ソースラベルのリスト(配列)
  • separator: ソースラベルの値を連結する際に使用する区切り文字(デフォルト値: ;
  • target_label: ターゲットラベル(結果を保存するラベル)
  • regex: ソースラベルの値に適用する正規表現
  • replacement: 置換値(正規表現のキャプチャグループ参照可能、例: ${1}
  • action: 実行するアクション(keep、drop、replace)

対応アクション(action)

  • keep: 正規表現に一致するメトリクスのみ保持
  • drop: 正規表現に一致するメトリクスを除去
  • replace: ターゲットラベルの値を置換値に変更

特殊ラベル

  • name: メトリクス名を表す特殊ラベル

1. 全メトリクスの収集

metricRelabelConfigs:
- source_labels: [__name__]
regex: ".*"
action: keep

2. 特定メトリクスのみ保持

metricRelabelConfigs:
- source_labels: [__name__]
regex: "http_requests_total"
action: keep

この設定は http_requests_total メトリクスのみを保持し、その他はすべて除去します。

3. 正規表現によるメトリクスフィルタリング

metricRelabelConfigs:
- source_labels: [__name__]
regex: "node_(cpu|memory).*"
action: keep

4. ラベル名の変更

metricRelabelConfigs:
- source_labels: [method]
target_label: http_method
replacement: "${1}"
action: replace

5. 複数ソースラベルの組み合わせ

metricRelabelConfigs:
- source_labels: [__name__, status]
regex: "http_requests_total;(200|500)"
action: keep

6. 静的ラベルの追加

metricRelabelConfigs:
- target_label: metric_src
replacement: "whatap-open-agent"
action: replace

総合的な動作例

元のスクレイプ済みメトリクスが以下の通りであると仮定します:

apiserver_request_total{code="200", resource="pods", verb="GET"} 100
some_other_metric{label="value"} 50
  1. 1つ目のルール(keep apiserver_request_total)の適用: apiserver_request_total を保持、some_other_metric をドロップ
  2. 2つ目のルール(replace verb → http_verb)の適用: verb ラベルの値を http_verb ラベルへコピー
  • 最終収集メトリクス
apiserver_request_total{code="200", resource="pods", verb="GET", http_verb="GET"} 100