My GCP project vm installed below agents: google_osconfig_agent /opt/stackdriver/collectd/sbin/stackdriver-collectd. Can i use the stackdriver-agent to get some data? eg. run some commands to get all instances storage, uptime etc.
Asked
Active
Viewed 372 times
1 Answers
0
The Cloud Monitoring agent gathers metrics from VM instances and sends them to Google Cloud Monitoring. Among many there are metrics for uptime and disk utilization.
Gathered metrics are represented in the customizable Dashboards of the Cloud Console.
If you need to filter and process metrics in a more sophisticated way, you can use the Monitoring API available for C#, Go, Java, Node.js, PHP, Python, Ruby.

mebius99
- 2,495
- 1
- 5
- 9
-
Thank you Mebius99. I am new to gcp. How can i get each instance uptime in gcp? here i found a repo in github. https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/monitoring/api/v3/uptime-check-client. i cloned it tried python snippets.py , but not be able to give me correct info(uptime). – markzhu Apr 28 '20 at 02:59
-
gcloud compute ssh example-vm --zone=us-west-b --internal-ip --project=EXAMPLE_PROJECT --command=uptime. We can use this command get uptime, how can we get all instance uptime under same project? i can use python if possible – markzhu Apr 28 '20 at 03:02
-
If you prefer shell scripting and `gcloud`, you can use `gcloud compute instances list` and then create a loop with the command you've mentioned. You'll need a firewall rule to allow SSH connection to the target instances and (if required) provision of the SSH key passphrase. – mebius99 Apr 28 '20 at 14:05
-
Thank you again. Yes we can do that by using "gcloud compute". Actually, we have 300+ instances in GCP, I want know which of them are idle, then shut them down or destroy. Is not possible or not good just to use "gcloud compute" check them one by one from loop. I'd like to try python and check them from Google API. I cloned the python-docs-samples/monitoring/api/v3, cd uptime-check-client, and "python snippets.py -h", tried all listed commands, but i cannot get useful information. Could you please help to share some idea? – markzhu Apr 28 '20 at 14:51
-
The last three sentences of your comment could be a good separate question, interesting and useful for community members besides the two of us. I'd advise to create a separate question in order to focus specifically on using [Monitoring Client Libraries](https://cloud.google.com/monitoring/docs/reference/libraries) for Python. – mebius99 Apr 29 '20 at 11:00