Currently we use AWS EC2 alarms to shut down idle instances. It works well because we can kick off a long running batch job and let AWS kill the instance when it's work is done.

Does GCE have anything similar? or does anyone know of a workaround to achieve this?


The link that ceejayoz shared is good. I want to add that you can also stop an GCE VM instance instead of deleting it in the case you wish to keep the installed and configured applications or your logs and data. This way after stopping the instance, you will be charged only for the disk storage.

Also note that gcutil is a deprecated tool which is replaced by gcloud tool. For more information of creating, deleting, stopping of VM instances using gcloud command take a look at article [1][2] and [3]. In the link [1] you can find a full list of scopes for GCE instances.

To remove your VM instances manually, you can configure Alert in Google Cloud Monitoring (powered by Stackdriver), select CPU or CPU usage as monitoring metric below a threshold for a duration of time to notify your system admin. This way you will have a chance to re-run your jobs or scripts if they failed before deleting or stopping the instance.

[1] https://cloud.google.com/sdk/gcloud/reference/compute/instances/create
[2] https://cloud.google.com/sdk/gcloud/reference/compute/instances/delete
[3] https://cloud.google.com/sdk/gcloud/reference/compute/instances/stop

  • Thanks Kamran (and ceejayoz). I have hacked together a script which allows the instance to terminate itself but it's pretty brittle. I will also look at the monitoring tools but we really need an automated solution as these batch jobs run through the night and I dont think the admins will want to be woken up in the middle of the night every night! :D – Toby Hobson May 26 '15 at 18:10

On top of the Google Cloud Monitoring solution that Kamran suggested, using the Google Compute Engine managed instance groups with autoscaler is the best bet here, as autoscaler adds or remove instances from a managed instance group.

To create an autoscaler, you must specify the autoscaling policy and a target utilization level that the autoscaler uses to determine when to scale the group.

More information about it can be found in this Help Center article

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.