Hi,
I have a use case where I need to use preemptable GCP VMs and capture the total UP time of each VM on-premise. What is the recommended way to achieve this?
One way I can think of is to capture the VM start/stop events and then export this data to pub/sub topic and later pull it on-premise and do something. If this is the recommended approach, could you help me understand if GCP provides any way to capture these events and then export them to pub/sub?
Also, is it possible to add any custom fields to the VM start/stop events so that even when VMs are preempted, I can map the VMs to a common id.
Thank You
The way to go is to use Cloud Logging: https://cloud.google.com/compute/docs/logging/audit-logging
You can filter the logs per project, activity, resource, etc.
Here you have a way to find preempted instances in the Audit logs:
If you also look for the records logged when the instances were created you can calculate the uptime.
You can then send the records via a Sink to BigQuery, and query the data from there.