how to get uptime of GCP VM instance

4k views Asked by At

I need to know the uptime of GCP VM instances (windows and Linux both) and based on the time I need to stop the VM. Somehow, I am not getting any simpler way to get the uptime of my all GCP VMs which are like 100 in numbers and will be increasing.

I went through below answer but even there it is not answered, I could not add comment so had to ask new question. Get vm uptime data from stackdriver-agent in gcp?

In the python code snippet at below link, there is no module available for instance uptime all we have is creating uptime check for service availability. https://github.com/GoogleCloudPlatform/python-docs-samples

How can I get uptime of all GCP VM instances ?

2

There are 2 answers

7
Subhash On
  1. Go to GCP console
  2. Select monitoring
  3. Click Uptime checks.
  4. Click Create Uptime check.

for more info check the below document

https://cloud.google.com/monitoring/uptime-checks

4
Slava Medvediev On

Assuming that you can adjust process of starting VMs, I think solution below is viable:

  1. When VM is started, add a custom tag with current timestamp (API reference)
  2. Use this tag's value to determine actual instance's uptime

I realize that it sounds overcomplicated, but I don't see any better OS-independent solution.

Update:
The feature you need is already requested in Google's issue tracker. You can check the progress and\or "start" it here: https://issuetracker.google.com/issues/136105125
Note: the issue referenced above is marked as blocked by another one, non-public