To monitor the memory usage of VM instances in Google Cloud, you must enable the Stackdriver Monitoring agent on your VMs. The agent collects memory usage and other system metrics, which can be viewed in the Google Cloud Console. Here’s how to set up and use the Stackdriver Monitoring agent:
Step 1: Install the Monitoring agent on your VM instance
SSH into your VM instance and run the following commands based on your operating system:
Debian/Ubuntu
curl -sSO https://dl.google.com/cloudagents/add-monitoring-agent-repo.sh
sudo bash add-monitoring-agent-repo.sh
sudo apt-get update
sudo apt-get install stackdriver-agent
CentOS/RHEL
curl -sSO https://dl.google.com/cloudagents/add-monitoring-agent-repo.sh
sudo bash add-monitoring-agent-repo.sh
sudo yum clean all
sudo yum install stackdriver-agent
Step 2: Start the Monitoring agent
Run the following command to start the Monitoring agent on your VM instance:
sudo service stackdriver-agent start
Step 3: Verify that the agent is running
You can use the following command to check the status of the agent:
sudo service stackdriver-agent status
Step 4: View memory usage metrics in the Google Cloud Console
- Go to the Google Cloud Console: https://console.cloud.google.com/
- Select your project from the project drop-down menu at the top of the page.
- Navigate to the “Monitoring” page by clicking on the navigation menu (three horizontal lines) at the top left corner, then select “Monitoring”.
- Click “Metrics Explorer” on the left-hand menu in the Monitoring Dashboard.
- In the “Find resource type and metric” field, type “instance” and select “gce_instance” as the resource type.
- In the same field, type “memory” and select the “memory/usage” metric. You can also choose metrics like “memory/bytes_used” or “memory/percent_used”.
- Adjust the filters and groupings as needed to display the memory usage for your VM instances.
You can also create custom dashboards, set up alerts, or use the Monitoring API to analyze the collected metrics further.
That’s it.

Amit Doshi is a Cloud Engineer who has experienced more than 5 years in AWS, Azure, and Google Cloud. He is an IT professional responsible for designing, implementing, managing, and maintaining cloud computing infrastructure, applications, and services.