用于容器的 Azure Monitor 常见问题解答

本 Microsoft 常见问题解答列出了用于容器的 Azure Monitor 的常见问题。 如果对该解决方案还有其他任何问题,请访问论坛并发布问题。 当某个问题经常被问到时,我们会将该问题添加到本文中,以便可以轻松快捷地找到该问题。

查询 ContainerLog 表时,没看到填充有 Image 和 Name 属性值。

对于代理版本 ciprod12042019 及更高版本,为了尽量减少收集日志数据时产生的费用,默认情况下不会为每行日志填充这两个属性。 有两种方法可用于查询表,查询包含这些属性及其值:

选项 1

联接其他表,在结果中包含这些属性值。

联接 ContainerID 属性,将查询修改为包含 ContainerInventory 表中的 Image 和 ImageTag 属性。 通过联接 ContainerID 属性,可包含 KubepodInventory 表的 ContaineName 字段中的 Name 属性(如同之前在 ContainerLog 表中显示的一样)。建议使用此选项。

下面是一个详细查询示例,说明了如何使用联接来获取这些字段值。

//lets say we are querying an hour worth of logs
let startTime = ago(1h);
let endTime = now();
//below gets the latest Image & ImageTag for every containerID, during the time window
let ContainerInv = ContainerInventory | where TimeGenerated >= startTime and TimeGenerated < endTime | summarize arg_max(TimeGenerated, *)  by ContainerID, Image, ImageTag | project-away TimeGenerated | project ContainerID1=ContainerID, Image1=Image ,ImageTag1=ImageTag;
//below gets the latest Name for every containerID, during the time window
let KubePodInv  = KubePodInventory | where ContainerID != "" | where TimeGenerated >= startTime | where TimeGenerated < endTime | summarize arg_max(TimeGenerated, *)  by ContainerID2 = ContainerID, Name1=ContainerName | project ContainerID2 , Name1;
//now join the above 2 to get a 'jointed table' that has name, image & imagetag. Outer left is safer in-case there are no kubepod records are if they are latent
let ContainerData = ContainerInv | join kind=leftouter (KubePodInv) on $left.ContainerID1 == $right.ContainerID2;
//now join ContainerLog table with the 'jointed table' above and project-away redundant fields/columns and rename columns that were re-written
//Outer left is safer so you dont lose logs even if we cannot find container metadata for loglines (due to latency, time skew between data types etc...)
ContainerLog
| where TimeGenerated >= startTime and TimeGenerated < endTime 
| join kind= leftouter (
   ContainerData
) on $left.ContainerID == $right.ContainerID2 | project-away ContainerID1, ContainerID2, Name, Image, ImageTag | project-rename Name = Name1, Image=Image1, ImageTag=ImageTag1 

方法 2

为每行容器日志的这些属性重新启用收集功能。

如果第一种方法因涉及到更改查询而不便使用,可通过在代理配置映射中启用设置 log_collection_settings.enrich_container_logs 来重新开始收集这些字段,如数据收集配置设置中所述。

注意

对于包含 50 个以上节点的大型群集,不建议使用第二个选项,因为它将从群集中的每个节点>生成 API 服务器调用以执行此扩充。 该方法还会增加收集到的每行日志的数据大小。

能否在 Grafana 中查看收集的指标?

用于容器的 Azure Monitor 支持在 Grafana 仪表板中查看 Log Analytics 工作区中存储的指标。 我们提供了一个模板,你可从 Grafana 的仪表板存储库中下载它以供入门和参考,它可帮助你了解如何从受监视的群集查询其他数据,以便在自定义 Grafana 仪表板中直观显示。

能否通过用于容器的 Azure Monitor 监视 AKS-Engine 群集?

用于容器的 Azure Monitor 支持监视部署到 Azure 上托管的 AKS-Engine(以前称为 ACS-Engine)群集的容器工作负载。 要进一步了解详细信息并概要了解为此方案启用监视功能所需的步骤,请参阅对 AKS-Engine 使用用于容器的 Azure Monitor

为什么在 Log Analytics 工作区中看不到数据?

如果每天在特定时间都无法查看 Log Analytics 工作区中的任何数据,则你可能已达到默认的 500 MB 限制或为控制每天要收集的数据量而指定的每日上限。 达到当天的限制后,数据收集将停止且只能在第二天恢复。 若要查看数据使用情况并根据预期的使用模式更新到其他定价层,请参阅日志数据使用情况和成本

ContainerInventory 表中指定了哪些容器状态?

ContainerInventory 表包含已停止和正在运行的容器的信息。 此表由代理中的一个工作流进行填充,该工作流查询 Docker 中的所有容器(正在运行的和已停止的),并将该数据转发到 Log Analytics 工作区。

如何解决“缺少订阅注册”错误?

如果收到“缺少 Microsoft.OperationsManagement 的订阅注册”错误,可通过在定义工作区的订阅中注册资源提供程序 Microsoft.OperationsManagement 来解决它 。 可以在此处找到介绍如何执行此操作的文档。

是否支持已启用 RBAC 的 AKS 群集?

容器监视解决方案不支持 RBAC,但用于容器的 Azure Monitor 支持 RBAC。 在显示这些群集的数据的边栏选项卡上,解决方案详细信息页可能不会显示正确的信息。

如何通过 Helm 为 kube-system 命名空间中的容器启用日志收集?

默认情况下,kube-system 命名空间中的容器的日志收集被禁用。 可以通过在 omsagent 上设置一个环境变量来启用日志收集。 有关详细信息,请参阅 GitHub 上的用于容器的 Azure Monitor 页面。

如何将 omsagent 更新为最新发布的版本?

若要了解如何升级代理,请参阅代理管理

如何启用多行日志记录?

当前,用于容器的 Azure Monitor 不支持多行日志记录,但有可用的变通方法。 你可以将所有服务配置为以 JSON 格式进行写入,然后 Docker/Moby 会在单个行上写入它们。

例如,可以将你的日志包装为一个 JSON 对象,如示例 node.js 应用程序的以下示例中所示:

console.log(json.stringify({ 
      "Hello": "This example has multiple lines:",
      "Docker/Moby": "will not break this into multiple lines",
      "and you will receive":"all of them in log analytics",
      "as one": "log entry"
      }));

查询该数据时,该数据与用于日志的 Azure Monitor 中的以下示例类似:

LogEntry : ({“Hello": "This example has multiple lines:","Docker/Moby": "will not break this into multiple lines", "and you will receive":"all of them in log analytics", "as one": "log entry"}

要详细了解此问题,请查看以下 GitHub 链接

如何解决在启用实时日志时遇到的 Azure AD 错误?

你可能会看到以下错误:在请求中指定的回复 URL 与为应用程序“<application ID>”配置的回复 URL 不匹配。

在加入后为何无法升级群集?

如果在为 AKS 群集启用用于容器的 Azure Monitor 之后,删除了群集向其发送数据的 Log Analytics 工作区,则在尝试升级群集时会失败。 要解决此情况,必须禁用再重新启用监视功能,使其引用订阅中的其他有效工作区。 在你重新尝试升级群集时,应该就会处理并成功完成。

需要为代理打开哪些端口和域或将哪些端口和域加入允许名单?

请参阅网络防火墙要求,以了解使用 Azure 云、Azure 美国政府云和由世纪互联运营的 Microsoft Azure 云的容器化代理所需的代理和防火墙配置信息。

后续步骤

若要开始监视 AKS 群集,请查看如何载入用于容器的 Azure Monitor 以了解启用监视的要求和可用方法。