共用方式為


部署可檢視性資源並設定記錄

Azure IoT 作業可觀察性可讓您深入瞭解設定的每一層,並讓您深入瞭解問題的實際行為,從而提高網站可靠性工程的有效性。 Azure IoT 作業會透過裝載在 Azure 中的自訂策劃 Grafana 儀錶板提供可觀察性,並由適用於 Prometheus 和 Container Insights 的 Azure 監視器受控服務提供支援。

本文說明如何部署 Azure IoT Operations 可觀測性資源、設定 Azure 受控 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.OperationalInsights
    
  2. 安裝 Azure CLI 擴展以進行 Azure Arc 啟用叢集和 Azure 管理的 Grafana 的指標收集。

    az extension add --upgrade --name k8s-extension
    az extension add --upgrade --name amg
    
  3. 建立 Azure Monitor 工作區,以便為啟用 Azure Arc 的 Kubernetes 叢集進行度量收集:

    az monitor account create --name <WORKSPACE_NAME> --resource-group <RESOURCE_GROUP> --location <LOCATION> --query id -o tsv
    

    從此命令的輸出儲存 Azure 監視器工作區識別碼。 在下一節中啟用計量集合時,您會使用標識符。

  4. 建立一個 Azure Managed Grafana 實例來視覺化你的 Prometheus 指標:

    az grafana create --name <GRAFANA_NAME> --resource-group <RESOURCE_GROUP> --query id -o tsv
    

    從此命令的輸出儲存 Grafana 識別符。 在下一節中啟用計量集合時,您會使用標識符。

  5. 建立一個用於容器洞察的日誌分析工作區:

    az monitor log-analytics workspace create -g <RESOURCE_GROUP> -n <LOGS_WORKSPACE_NAME> --query id -o tsv
    

    從此命令的輸出儲存Log Analytics工作區標識碼。 在下一節中啟用計量集合時,您會使用標識符。

啟用叢集的計量集合

更新 Azure Arc 叢集以收集計量,並將其傳送至您建立的 Azure 監視器工作區。 你也將這個工作區連結到 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 監視器和 Grafana,並連結至叢集,以進行可觀測性和計量收集。

部署 OpenTelemetry 收集器

定義 OpenTelemetry (OTel) 收集器並將其部署至已啟用 Arc 的 Kubernetes 叢集。

  1. 建立名為 otel-collector-values.yaml 的檔案,並將下列程式代碼貼到其中以定義 OpenTelemetry 收集器:

    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: false
    
  2. 在 檔案中 otel-collector-values.yaml ,記下您在叢集上部署 Azure IoT 作業時,在 命令中使用的 az iot ops create 下列值:

    • fullnameOverride
    • grpc.endpoint
    • check_interval
  3. 儲存並關閉檔案。

  4. 執行下列命令來部署收集器:

    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 計量集合。

  1. 建立名為 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
    
  2. 執行下列命令以套用群組態檔:

    kubectl apply -f ama-metrics-prometheus-config.yaml
    

設定可觀察性設定

您可以隨時設定 Azure IoT 作業部署的可觀察性設定。 一旦可觀察性資源設定完成,你可以透過執行 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-collectorgrpc.endpoint=4317
--ops-config observability.metrics.exportInternalSeconds=<CHECK_INTERVAL> 請提供 check_interval 你在 otel-collector-values.yaml 檔案中設定的數值。

本文的說明使用樣本值 check_interval=60

注意

在預覽版本中, az iot ops upgrade 命令不適用於升級至預覽版本,但可用於設定 Azure IoT 作業以取得可檢視性。

將儀錶板部署至 Grafana

Azure IoT 作業提供範例 儀錶板 ,其設計目的是讓您瞭解 Azure IoT 作業部署的健康情況和效能所需的許多視覺效果。

請完成以下步驟以安裝 Azure IoT Operations 精選的 Grafana 儀表板:

  1. 複製或下載 azure-iot-operations 存放庫,以在本機取得範例 Grafana 儀錶板 json 檔案: https://github.com/Azure/azure-iot-operations

  2. 登入 Grafana 控制台。 您可以透過 Azure 入口網站 存取控制台,或使用 az grafana show 命令來擷取 URL。

    az grafana show --name <GRAFANA_NAME> --resource-group <RESOURCE_GROUP> --query url -o tsv
    
  3. 在 Grafana 登陸頁面上,選取 [ 建立您的第一個儀錶板 ] 圖格。

  4. 選取 [匯入儀錶板]。

  5. 瀏覽 Azure IoT Operations 倉庫本地副本中的範例儀表板目錄 azure-iot-operations > samples > grafana-dashboard,然後選擇 aio.sample.json dashboard 檔案。

  6. 當應用程式提示時,請選取受控 Prometheus 資料來源。

  7. 選取匯入

後續步驟