Azure IoT Operations の監視機能は、構成のすべてのレイヤーを可視化し、問題の実際の動作に関する分析情報を提供し、サイトの信頼性エンジニアリングの有効性を高めます。 Azure IoT Operations は、Prometheus と Container Insights 用の Azure Monitor マネージド サービスを利用して、Azure でホストされているカスタムキュレーションされた Grafana ダッシュボードを通じて監視を提供します。
この記事では、Azure IoT Operations 監視リソースをデプロイし、Azure Managed Prometheus と Grafana を設定し、Azure Arc クラスターの包括的な監視を有効にする方法について説明します。
前提条件
- Arc 対応 Kubernetes クラスター。
- クラスター コンピューターにインストールされている Azure CLI。 手順については、「Azure CLI をインストールする方法」を参照してください。
- クラスター コンピューターにインストールされている Helm。 手順については、Helm のインストールに関するページを参照してください。
- クラスター コンピューターにインストールされている Kubectl。 手順については、Kubernetes ツールのインストールに関するページを参照してください。
Azure でリソースを作成する
クラスターが配置されているサブスクリプションにプロバイダーを登録します。
注
この手順は、サブスクリプションごとに 1 回だけ実行します。 リソース プロバイダーを登録するには、サブスクリプションの共同作成者および所有者のロール内に含まれる、
/register/action操作を行うためのアクセス許可が必要です。 詳細については、「Azure リソース プロバイダーと種類」を参照してください。az account set -s <SUBSCRIPTION_ID> az provider register --namespace Microsoft.AlertsManagement az provider register --namespace Microsoft.Monitor az provider register --namespace Microsoft.Dashboard az provider register --namespace Microsoft.Insights az provider register --namespace Microsoft.OperationalInsightsAzure Arc 対応クラスターおよび Azure Managed Grafana のメトリック収集用の Azure CLI 拡張機能をインストールします。
az extension add --upgrade --name k8s-extension az extension add --upgrade --name amgAzure Monitor ワークスペースを作成して、Azure Arc 対応 Kubernetes クラスターに対してメトリック収集を有効にします。
az monitor account create --name <WORKSPACE_NAME> --resource-group <RESOURCE_GROUP> --___location <LOCATION> --query id -o tsvこのコマンドの出力にある Azure Monitor ワークスペース ID を保存します。 この ID は、次のセクションでメトリック収集を有効にする際に使用します。
Prometheus メトリックを視覚化する Azure Managed Grafana インスタンスを作成します。
az grafana create --name <GRAFANA_NAME> --resource-group <RESOURCE_GROUP> --query id -o tsvこのコマンドの出力にある Grafana ID を保存します。 この ID は、次のセクションでメトリック収集を有効にする際に使用します。
Container Insights 用の Log Analytics ワークスペースを作成します。
az monitor log-analytics workspace create -g <RESOURCE_GROUP> -n <LOGS_WORKSPACE_NAME> --query id -o tsvこのコマンドの出力にある Log Analytics ワークスペース ID を保存します。 この ID は、次のセクションでメトリック収集を有効にする際に使用します。
クラスターに対してメトリック収集を有効にする
Azure Arc クラスターを更新してメトリックを収集し、作成した Azure Monitor ワークスペースに送信します。 また、このワークスペースを Grafana インスタンスにリンクします。
az k8s-extension create --name azuremonitor-metrics --cluster-name <CLUSTER_NAME> --resource-group <RESOURCE_GROUP> --cluster-type connectedClusters --extension-type Microsoft.AzureMonitor.Containers.Metrics --configuration-settings azure-monitor-workspace-resource-id=<AZURE_MONITOR_WORKSPACE_ID> grafana-resource-id=<GRAFANA_ID>
ログ収集に対して Container Insights ログを有効にします。
az k8s-extension create --name azuremonitor-containers --cluster-name <CLUSTER_NAME> --resource-group <RESOURCE_GROUP> --cluster-type connectedClusters --extension-type Microsoft.AzureMonitor.Containers --configuration-settings logAnalyticsWorkspaceResourceID=<LOG_ANALYTICS_WORKSPACE_ID>
これらの手順を完了すると、Azure Monitor と Grafana の両方が設定され、監視とメトリック収集のためにクラスターにリンクされます。
OpenTelemetry (OTel) コレクターをデプロイする
OpenTelemetry (OTel) コレクターを定義し、Arc 対応 Kubernetes クラスターにデプロイします。
otel-collector-values.yamlという名前のファイルを作成し、それに次のコードを貼り付けて、OpenTelemetry (OTel) コレクターを定義します。mode: deployment fullnameOverride: aio-otel-collector image: repository: otel/opentelemetry-collector tag: 0.107.0 config: processors: memory_limiter: limit_percentage: 80 spike_limit_percentage: 10 check_interval: '60s' receivers: jaeger: null prometheus: null zipkin: null otlp: protocols: grpc: endpoint: ':4317' http: endpoint: ':4318' exporters: prometheus: endpoint: ':8889' resource_to_telemetry_conversion: enabled: true add_metric_suffixes: false service: extensions: - health_check pipelines: metrics: receivers: - otlp exporters: - prometheus logs: null traces: null telemetry: null extensions: memory_ballast: size_mib: 0 resources: limits: cpu: '100m' memory: '512Mi' ports: metrics: enabled: true containerPort: 8889 servicePort: 8889 protocol: 'TCP' jaeger-compact: enabled: false jaeger-grpc: enabled: false jaeger-thrift: enabled: false zipkin: enabled: falseotel-collector-values.yamlファイルの次の値を書き留めておきます。これらの値は、Azure IoT Operations をクラスターにデプロイするときにaz iot ops createコマンドで使用します。- fullnameOverride
- grpc.endpoint
- check_interval
ファイルを保存して閉じます。
次のコマンドを実行してコレクターをデプロイします。
kubectl get namespace azure-iot-operations || kubectl create namespace azure-iot-operations helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts helm repo update helm upgrade --install aio-observability open-telemetry/opentelemetry-collector -f otel-collector-values.yaml --namespace azure-iot-operations
Prometheus メトリック コレクションを構成する
クラスターで Prometheus メトリック コレクションを構成します。
ama-metrics-prometheus-config.yamlというファイルを作成し、次の構成を貼り付けます。apiVersion: v1 data: prometheus-config: |2- scrape_configs: - job_name: otel scrape_interval: 1m static_configs: - targets: - aio-otel-collector.azure-iot-operations.svc.cluster.local:8889 - job_name: aio-annotated-pod-metrics kubernetes_sd_configs: - role: pod relabel_configs: - action: drop regex: true source_labels: - __meta_kubernetes_pod_container_init - action: keep regex: true source_labels: - __meta_kubernetes_pod_annotation_prometheus_io_scrape - action: replace regex: ([^:]+)(?::\\d+)?;(\\d+) replacement: $1:$2 source_labels: - __address__ - __meta_kubernetes_pod_annotation_prometheus_io_port target_label: __address__ - action: replace source_labels: - __meta_kubernetes_namespace target_label: kubernetes_namespace - action: keep regex: 'azure-iot-operations' source_labels: - kubernetes_namespace scrape_interval: 1m kind: ConfigMap metadata: name: ama-metrics-prometheus-config namespace: kube-system次のコマンドを実行して、構成を適用します。
kubectl apply -f ama-metrics-prometheus-config.yaml
可観測性の構成を設定する
Azure IoT Operations デプロイの可観測性構成は、いつでも設定できます。 可観測性リソースを構成したら、az iot ops upgrade パラメーターを指定して --ops-config コマンドを実行して新しい構成値を指定することで、可観測性構成をアップグレードできます。
az iot ops upgrade --resource-group <rg name> -n <instance name> --ops-config observability.metrics.openTelemetryCollectorAddress=<>
| パラメーター | 価値 | 説明 |
|---|---|---|
--ops-config |
observability.metrics.openTelemetryCollectorAddress=<FULLNAMEOVERRIDE>.azure-iot-operations.svc.cluster.local:<GRPC_ENDPOINT> |
otel-collector-values.yaml ファイルで構成した OpenTelemetry (OTel) コレクター アドレスを指定します。 この記事の手順では、サンプル値 fullnameOverride=aio-otel-collector と grpc.endpoint=4317 を使用します。 |
--ops-config |
observability.metrics.exportInternalSeconds=<CHECK_INTERVAL> |
otel-collector-values.yaml ファイルで構成した check_interval 値を指定します。 この記事の手順では、サンプル値 check_interval=60 を使用します。 |
注
プレビュー リリースでは、 az iot ops upgrade コマンドはプレビュー バージョンへのアップグレードには機能しませんが、監視のために Azure IoT Operations を構成する場合に機能します。
ダッシュボードを Grafana にデプロイする
Azure IoT Operations には、サンプル ダッシュボードが用意されており、これらは、Azure IoT Operations デプロイの正常性とパフォーマンスを把握するために必要な多くの視覚化を提供するように設計されています。
Azure IoT Operations でキュレーションされた Grafana ダッシュボードをインストールするには、次の手順を実行します。
ローカルで azure-iot-operations リポジトリ (https://github.com/Azure/azure-iot-operations) を複製またはダウンロードして、サンプルの Grafana ダッシュボードの json ファイルを取得します。
Grafana コンソールにサインインします。 コンソールにアクセスするには、Azure portal を経由するか、
az grafana showコマンドを使用して URL を取得します。az grafana show --name <GRAFANA_NAME> --resource-group <RESOURCE_GROUP> --query url -o tsvGrafana ランディング ページで、[最初のダッシュボードの 作成 ] タイルを選択します。
[ ダッシュボードのインポート] を選択します。
Azure IoT Operations リポジトリのローカル コピー内にあるサンプル ダッシュボード ディレクトリを参照し、azure-iot-operations>samples>grafana-dashboard の順に選択し、
aio.sample.jsonダッシュボード ファイルを選択します。アプリケーションのプロンプトが表示されたら、マネージド Prometheus データ ソースを選択します。
[インポート] を選択します。