TheHund
TheHund

Reputation: 3

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. Currently I use a script that lists all of the instances gets id's then makes log sink with that. 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?

Upvotes: 0

Views: 781

Answers (1)

Kolban
Kolban

Reputation: 15276

One thought would be to use the GCP Logging APIs to get, create, update the Cloud Logging sinks ... see Cloud Logging API. These APIs are available through language specific client libraries or directly via REST. What this means is that you have programatic control over Cloud Logging sink definitions.

Now what remains is for those APIs to be driven when your environment changes. For that we have Cloud Asset Inventory. This is GCP technology that tracks and informs you when your GCP environment changes. See Monitoring asset changes for setting up feeds for changes.

The feed update is manifested as Cloud PubSub messages. 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.

Upvotes: 1

Related Questions