Is there a way I can get current CPU utilization of a VM on GCE using 'gcloud' commands? - google-compute-engine

I am new to GCE. I am trying to write a cron job to take some action based on current CPU utilization of some VMs on GCE. Is there a way I can get this info using 'gcloud' command?
I have tried gcloud compute instances describe <instance_name>. But that does not provide current CPU utilization info.
I found this other post that talks about getting this info from StackDriver - Understanding instance/cpu/utilization of Google Compute Engine
I am looking for this info using 'gcloud'.
Appreciate any help. Thank you in advance.

gcloud commands are used to create and manage Google Cloud resources. I checked the gcloud command references and it does't cover monitoring metric. To monitor performance of your VM instance, you need to use stackdriver monitoring
If you really want this feature in gcloud command, you can open a feature request here

Related

Having hard time to start GCE VM with GPU in us-east-1

We are having problem to start a simple GCE VM with GPU in us-central-1. I am wondering if anyone experience the same thing. The error we got is below:
Instance 'instance-group-2-vc37' creation failed: The resource 'projects/xxxxx-xxxx-858/zones/us-central1-a/acceleratorTypes/nvidia-tesla-k80' was not found (when acting as 'xxxxxxx#cloudservices.gserviceaccount.com')
Thanks
GCE doesn't offer GPUs in us-central1. The docs list which regions GPUs are available in.
Cloud ML Engine is a separate product and not what you are using here.

Can't start Compute engine after upgrading from Free Trial

I used GCP on a Free Trial for a couple of month and set up and a Compute engine VM, when the Trial budget ended the VM went down and I can't restart it even after upgrading to monthly payments.
Every time I want to restart the VM i get this error:
The default network interface [nic0] is frozen.
I tried to create a new VM, but also got an error:
Google Compute Engine is not ready for use yet in the project. It may take several minutes if Google Compute Engine has just been enabled, or if this is the first time you use Google Compute Engine in the project.
Created a new service account and played with roles, but the result is still the same.
What should I do in this situation?
Thanks in advance!
Best regards, Ivan
This issue looks like a known issue from Google side:
Workaround:
1. Try creating a new VPC network using the following:
https://cloud.google.com/sdk/gcloud/reference/compute/networks/create
Now create a VM instance using the new network
Create a new project under the same billing account and try creating VM using the default network

GCP Cloud Trace for GCE

I have GCE instances and provide our own Web APIs on the VMs. I really want to use GCP Cloud Trace to check the latency. Can I use it on GCE? Some say that it works on GAE. As far as I've read docs, it does not seem that I can use it.

Get Memory and Cpu Usages in Google Cloud Compute

How is one supposed to access the CPU usages and Memory usages of all the instances in a given project in Google Cloud Compute?
I'm unable to find anything regarding this in the documentation.
You can use Google Cloud Monitoring to see some usage metrics for your systems, and the Google Cloud Monitoring agent to get more precise metrics like memory. See the GCP metrics documentation for a list of all available compute metrics.
For memory usage on Debian:
free -m
in console.
You can CPU, Memory, Network, Disk I/O related information of your instance group into Google Stackdriver. Stackdriver comes with a separate subscription. You can add charts to monitoring your GCP infrastructure into one single/multiple dashboard/s.
You can see detail information in How to monitor GCP infrastructure using stack driver visualization
if you are using Linux, you can install gnome-system-monitor and ssh -X into the system and launch it.
For Ubuntu on GCP:
"apt-get install gnome-system-monitor dbus"
From another linux machine (or if you have cygwin/x installed on windows), just "ssh -X {remote ip}" Then type gnome-system-monitor and it will launch on your desktop.
You could also setup a vncserver on the cloud platform.

Managed VMs running Perl on Google App Engine

I have a perl job that runs for 5 mins at the top of every hour. What is the most cost effective way of running this job on the Google Cloud infrastructure? Running a compute engine VM seems too heavy-weight for this since I'd get charged for the other 55 mins of no use. I don't understand the "Managed VMs" well enough, but it seems like this might be an option, but I'm not sure if pricing is rounded to the hour. Does anyone have any ideas what the best option is so that I only get charged for 120 mins of usage (24 times run * 5 minutes). The script also uses some image processing binaries, so converting to Python won't do the trick.
Managed VMs are linked to Google App Engine. If you have an App in GAE, managed VMs are used to configure the hosting environment for you App using VMs that run on Google Compute Engine and these applications are subject to Java and Python run time. This link can give you an idea on pricing on GAE, however Perl is not a supported language in GAE.
On GCE, you can start up an instance, do the task and then delete the instance without deleting the persistence disk, this will allow you to recreate the instance using this disk, however you will still be charged for the provisioned disk space and you will need to create a script that will spin up the instance and delete it. You can also create a snapshot of your disk and recreate your instance based on the snapshot, this will be little bit less expensive that keeping the disk.
Also, you should look at the type of persistence disks (PD) on GCE, at this link, take a look at the examples provided, since based on your operation, regular PD or SSD PD can make a big difference on price.
You can use the pricing calculator to estimate your charges
When you deploy to App Engine using a managed VM, an compute engine instance (managed by google) is created for you. All request to App Engine will be forwarded to the created compute engine instance.
To run your script in App Engine as a Managed VM, you will have to dockerize your project, as the managed VM runs a docker container.
I don't see a reason to use App Engine managed VM (just for running a script), as the cost will be same as using a compute engine instance.
Probably the most cost effective way is to create a script that:
Launches a compute engine instance
Install perl
Copies your script to the instance
Runs you script in the created instance
To schedule the execution, you can put at home/office a cron job that executes the above script.