简体   繁体   English

是否可以仅从具有特定标签的 VM 中过滤日志? GCP 云日志记录

[英]Is it possible to filter logs only from VM with a specific label? GCP cloud logging

I'm trying to filter logs only from specific VM-s.我正在尝试仅过滤来自特定 VM 的日志。 Currently I use a script that lists all of the instances gets id's then makes log sink with that.目前我使用的脚本列出了所有实例获取 ID,然后使用它生成日志接收器。 However there might be new VM-s with that label added after and I could use a cloud function I guess but is there a better more civilized way of doing this?但是,之后可能会添加带有该标签的新 VM,我想我可以使用云功能,但是有没有更好的更文明的方法来做到这一点?

One thought would be to use the GCP Logging APIs to get, create, update the Cloud Logging sinks ... see Cloud Logging API .一种想法是使用 GCP Logging API 来获取、创建、更新 Cloud Logging 接收器……请参阅Cloud Logging API These APIs are available through language specific client libraries or directly via REST.这些 API 可通过特定语言的客户端库或直接通过 REST 获得。 What this means is that you have programatic control over Cloud Logging sink definitions.这意味着您可以通过编程控制 Cloud Logging 接收器定义。

Now what remains is for those APIs to be driven when your environment changes.现在剩下的就是在您的环境发生变化时驱动这些 API。 For that we have Cloud Asset Inventory .为此,我们有Cloud Asset Inventory This is GCP technology that tracks and informs you when your GCP environment changes.这是 GCP 技术,可在您的 GCP 环境发生变化时跟踪并通知您。 See Monitoring asset changes for setting up feeds for changes.请参阅监控资产更改以设置更改提要。

The feed update is manifested as Cloud PubSub messages.提要更新显示为 Cloud PubSub 消息。 You could then trigger a GCP Cloud Function that is triggered when a PubSub message arrives that then examines the nature of the changed asset and, if a VM that is added and has a label you want, you could then conceivably update your sinks.然后,您可以触发一个 GCP 云函数,该函数在 PubSub 消息到达时被触发,然后检查更改资产的性质,如果添加了一个虚拟机并具有您想要的标签,那么您可以想象更新您的接收器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM