我们发现 Log Analytics 成本飙升,并发现 ContainerLog 表急剧增长。这似乎是来自容器的所有 stdout/stderr 日志。
是否可以限制对此表的日志记录(至少对于某些部署或容器而言),而无需在集群上禁用 Log Analytics?我们仍然需要性能日志和见解。
AFAIK ContainerLog 表下的 stdout 和 stderr 日志基本上是我们手动运行命令“kubectl messages”时看到的日志,因此可以通过部署文件来限制对 ContainerLog 表的日志记录,而无需在集群上禁用 Log Analytics如下所示,它将日志写入容器内的日志文件。
apiVersion: apps/v1
kind: Deployment
metadata:
name: xxxxxxx
spec:
selector:
matchLabels:
app: xxxxxxx
template:
metadata:
labels:
app: xxxxxxx
spec:
containers:
- name: xxxxxxx
image: xxxxxxx/xxxxxxx:latest
command: ["sh", "-c", "./xxxxxxx.sh &> /logfile"]
但是,最佳实践是将日志消息发送到容器中运行的应用程序的标准输出,因此上述过程不是更好的方法。
因此,当数据收集高于预期时,您可以创建警报,如中所述this https://learn.microsoft.com/en-us/azure/azure-monitor/platform/manage-cost-storage#create-an-alert-when-data-collection-is-higher-than-expected文章和/或偶尔删除不需要的数据,如中所述this https://learn.microsoft.com/en-us/azure/azure-monitor/platform/personal-data-mgmt#how-to-export-and-delete-private-data文章利用purge https://learn.microsoft.com/en-us/rest/api/loganalytics/workspaces%202015-03-20/purgeREST API(但请确保仅清除不需要的数据,因为 Log Analytics 中的删除是不可逆的!)。
希望这可以帮助!!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)