管理 Azure Monitor 工作区

本文介绍如何创建和删除 Azure Monitor 工作区。 配置适用于 Prometheus 的 Azure Monitor 托管服务时,可以选择现有的 Azure Monitor 工作区或创建新的工作区。

注意

创建 Azure Monitor 工作区时,MA_<azure-monitor-workspace-name>_<location>_managed 形式的资源组中默认自动创建 <azure-monitor-workspace-name> 形式的数据收集规则和数据收集终结点。 如果有任何 Azure 策略对资源或资源组名称有限制,创建豁免以免除这些资源进行评估。

创建 Azure Monitor 工作区

通过 Azure CLI 使用以下命令创建 Azure Monitor 工作区。

az monitor account create --name <azure-monitor-workspace-name> --resource-group <resource-group-name> --location <location>

有关更多详细信息,请访问“适用于 Azure Monitor 工作区的 Azure CLI

创建 Azure Monitor 工作区时,会创建新的资源组。 资源组名称采用以下格式:MA_<azure-monitor-workspace-name>_<location>_managed,其中已标记化元素采用小写。 资源组包含一个数据收集终结点,以及一套与工作区同名的数据收集规则。 删除工作区时,会自动删除资源组及其资源。

若要将适用于 Prometheus 的 Azure Monitor 托管服务连接到 Azure Monitor 工作区,请参阅从 AKS 群集收集 Prometheus 指标

删除 Azure Monitor 工作区

删除 Azure Monitor 工作区时,与 Log Analytics 工作区不同的是,不会执行软删除操作。 工作区中的数据会立即删除,并且没有恢复选项。

若要删除 AzureMonitor 工作区,请使用 az resource delete

例如:

  az monitor account delete --name <azure-monitor-workspace-name> --resource-group <resource-group-name>

有关更多详细信息,请访问“适用于 Azure Monitor 工作区的 Azure CLI

将 Azure Monitor 工作区连接到 Azure 托管 Grafana 工作区,以允许 Grafana 在 Grafana 仪表板中使用 Azure Monitor 工作区数据。 Azure Monitor 工作区可以连接到多个 Grafana 工作区,而 Grafana 工作区可以连接到多个 Azure Monitor 工作区。

注意

将 Azure Monitor 工作区作为数据源添加到 Grafana 时,它将以 Managed_Prometheus_<azure-monitor-workspace-name> 的形式列出。

通过更新你所监视的 Azure Kubernetes 服务群集,在 Azure Monitor 工作区和 Grafana 工作区之间创建链接。

如果群集已配置为将数据发送到适用于 Prometheus 的 Azure Monitor 托管服务,则必须先使用以下命令禁用它:

az aks update --disable-azure-monitor-metrics -g <cluster-resource-group> -n <cluster-name> 

然后,使用以下命令启用或重新启用:

az aks update --enable-azure-monitor-metrics -n <cluster-name> -g <cluster-resource-group> --azure-monitor-workspace-resource-id 
<azure-monitor-workspace-name-resource-id> --grafana-resource-id  <grafana-workspace-name-resource-id>

输出

"azureMonitorProfile": {
    "metrics": {
        "enabled": true,
        "kubeStateMetrics": {
            "metricAnnotationsAllowList": "",
            "metricLabelsAllowlist": ""
        }
    }
}

如果 Grafana 实例是自托管的,请参阅使用托管系统标识将 Azure Monitor 适用于 Prometheus 的托管服务用作自托管 Grafana 的数据源

常见问题

本部分提供常见问题的解答。

是否可以在与 Azure Monitor 工作区和适用于 Prometheus 的托管服务不同的区域中使用 Azure 托管 Grafana?

是的。 当使用适用于 Prometheus 的托管服务时,可以在任何受支持的区域中创建 Azure Monitor 工作区。 你的 Azure Kubernetes 服务群集可以位于任何区域,并将数据发送到不同区域中的 Azure Monitor 工作区。 Azure 托管 Grafana 也可以不位于创建 Azure Monitor 工作区的区域。

后续步骤