Monitor memory usage of VM in Google Cloud

How to monitor memory usage of VM in Google Cloud ?

This tutorial guides you on how to monitor memory usage of VM in Google Cloud Platform. Let’s learn how to monitor Google Cloud Compute Engine virtual machine (VM) instance by installing Cloud Monitoring Agent.

Monitor memory usage of VM in Google Cloud

Before you start, make sure that you have created Google Cloud Project and enabled billing for your project.

Then, Go to Compute Engine and create a compute engine instance. You need to wait couple of minutes for your instance to launch and visible in VM instances page. Once the instance is launched then follow the below steps. Connect to VM through SSH option in the Google Cloud Console.

Update the package lists on your instance.

$ sudo apt-get update

Set up the Apache2 HTTP Server.

$ sudo apt-get install apache2 php7.0

Finally, install the cloud monitoring agent. To install the agent you need to follow the below instructions.

Add the agent’s package repository by running the following commands.

$ curl -sSO https://dl.google.com/cloudagents/add-monitoring-agent-repo.sh

$ sudo bash add-monitoring-agent-repo.sh

Now, install the cloud monitoring agent.

$ sudo apt-get install stackdriver-agent

Start the cloud monitoring agent.

$ sudo service stackdriver-agent start

Note, you can delete the installation script after agent is installed successfully.

Verify Cloud Monitoring Agent Status

Also, you can verify whether the cloud monitoring agent is working as expected by checking the agent’s status as shown below.

$ sudo service stackdriver-agent status

● stackdriver-agent.service - LSB: start and stop Stackdriver Agent
   Loaded: loaded (/etc/init.d/stackdriver-agent; generated)
   Active: active (running) since Tue 2021-03-30 04:48:07 UTC; 3min 39s ago
     Docs: man:systemd-sysv-generator(8)
    Tasks: 14 (limit: 4665)
   Memory: 9.4M
   CGroup: /system.slice/stackdriver-agent.service
           ├─10201 /opt/stackdriver/collectd/sbin/stackdriver-collectdmon -P /v
           └─10219 /opt/stackdriver/collectd/sbin/stackdriver-collectd -C /etc/

The status of the agent should be Active (Running)/ OK.

You can also check memory usage statistics using metrics explorer option in Monitoring feature of Google Cloud Platform.

Monitor memory usage of VM in Google Cloud

Go to Monitoring -> Metrics Explorer and build your query as shown in the following picture.

memory utlization usgae vm google cloud

 

You can also check memory utilization by navigating from VM instance page -> More actions -> View Monitoring as shown below.

 

Troubleshooting

You can also examine the logs and ensure there are no errors by running the following command.

$ sudo grep collectd /var/log/{syslog,messages} | tail

If you have any trouble in installing the cloud monitoring agent, I suggest you to try some of the things below.

For Linux VM, check whether agent service is up and running.

$ sudo service stackdriver-agent status

Suppose, if agent is not running then try restarting.

$ sudo service stackdriver-agent restart

If the restart fails, and the log output shows “Disabled via metadata”, you may be running an image from Marketplace, where the Cloud monitoring agent is disabled by default. Therefore, try enabling the agent and try reinstalling the agent.

Hope it helped 🙂

References

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments