Monitor NGINX Performance With Google Cloud Ops (Formerly Stackdriver)
Get insights into your app's performance by monitoring your NGINX instance using GCP Monitoring

Monitoring nginx performance can help you understand what the underlying application is doing. Monitoring is also an essential part of maintaining an app's operation. Proper monitoring and alerting system can help you diagnose bugs, identify attacks, or get the gists of your apps load.
Installing Cloud Ops Agent
Before we start, make sure you have installed cloud ops agent on your machine. It's not installed by default, even in your google cloud compute engine machine, so we must install the agent first.
Run this command on a dir
you can access
That's it. You can check if the ops agent is running by using
You can also install the ops agent using google cloud console.

This is useful, especially if you try to install the ops agent on multiple machines.
Configuring NGINX stub-status
Module
For ops agent to ingest the statistics of your nginx instances, it will use the stub-status
module from nginx. Every standard installation of nginx will include the module. However, if you build nginx from the source, you need to rebuild it with the module included.
To enable the module, you need to write the module config into a location
block. You can add the block to an existing server
configuration.
For example, I will add the above configuration to an existing site config.
Let me explain the configuration.
- First, we will enable the
stub_status
This will enable the module - Next, we turn off
access_log
collection for the specificstatus
location to prevent the log building up, as the ops agent will regularly access the status module regularly - Finally, we only allow
localhost
access to the module.
Now, reload your nginx
Now, test the module by curl-ing into the URL
If you get this response, then it is a success.
Configuring the Ops Agent
We need to configure the ops agent to start ingesting the nginx statistics and logs. Open /etc/google-cloud-ops-agent/config.yaml
with your favourite editor and paste this comment.
You can also ingest access log (the required config is in the commented code), but I highly do not recommend it because the log size will get huge and incur more log billing.
Now, restart your cloud ops agent.
After that, go to your monitoring page and click Integration.

It may take a few minutes. Otherwise, it will appear on the integration page.

Now you can view your nginx monitoring dashboard. Here is the example of the graph for our NGINX instances

You can even view your access & error logs directly in the monitoring dashboard.

Thank you for reading my article! That was an easy one! If you have any questions regarding monitoring and google cloud things, contact me at madjavacoder@gmail.com.