nginx Stay organized with collections Save and categorize content based on your preferences.
The nginx integration collects connection metrics and access logs. Connectionmetrics capture the current state of the connection: active, reading, orwaiting. Access logs are parsed for their connection details, which includefields mapped to request, client, server, and message.
For more information about nginx, see thenginx documentation.
Prerequisites
To collect nginx telemetry, you mustinstall the Ops Agent:
- For metrics, install version 2.1.0 or higher.
- For logs, install version 2.1.0 or higher.
This integration supports nginx versions 1.18 and 1.20.
Configure your nginx instance
You must enable thestub_status module in the nginx configuration file to setup a locally reachable URL, for example,http://www.example.com/nginx_statusfor the status page. To enable thestub_status module, complete the followingsteps:
Edit the
status.conffile, or create the file if it doesn't exist. You canfind this file in the nginx configuration directory, typically found at/etc/nginx/conf.d.Add the following lines to the
serversection:location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all;}Your configuration file might look like the following example:
server { listen 80; server_name 127.0.0.1; location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; } location / { root /dev/null; }}Reload the nginx configuration.
sudoservicenginxreload
You can run the following command to automate the previous steps. It createsastatus.conf file if it doesn't exist or overwrites the existing one if itdoes exist. The command turns onstub_status, reloads nginx, and verifiesthat the expected information is exposed through the endpoint.
sudotee/etc/nginx/conf.d/status.conf >/dev/null <<EOFserver{listen80;server_name127.0.0.1;location/nginx_status{stub_statuson;access_logoff;allow127.0.0.1;denyall;}location/{root/dev/null;}}EOFsudoservicenginxreloadcurlhttp://127.0.0.1:80/nginx_statusThe sample output is:
Active connections: 1server accepts handled requests 23 23 74Reading: 0 Writing: 1 Waiting: 0
127.0.0.1 can be replaced with the real server name, for example,server_name mynginx.domain.com. The curl command to verify would becurl http://mynginx.domain.com:80/nginx_status.Alternately, instead of using a separatestatus.conf file, you can alsodirectly embed the lines to the mainnginx.conf file, whichis typically located in one of the following directories:/etc/nginx,/usr/local/nginx/conf, or/usr/local/etc/nginx.
Configure the Ops Agent for nginx
Following the guide toConfigure the OpsAgent, add the required elementsto collect telemetry from nginx instances, andrestart the agent.
Example configuration
The following commands create the configuration to collect and ingest telemetryfor nginx:
#ConfiguresOpsAgenttocollecttelemetryfromtheapp.Youmustrestarttheagentfortheconfigurationtotakeeffect.set-e#Checkifthefileexistsif[!-f/etc/google-cloud-ops-agent/config.yaml];then#Createthefileifitdoesn'texist.sudomkdir-p/etc/google-cloud-ops-agentsudotouch/etc/google-cloud-ops-agent/config.yamlfi#Createabackupoftheexistingfilesoexistingconfigurationsarenotlost.sudocp/etc/google-cloud-ops-agent/config.yaml/etc/google-cloud-ops-agent/config.yaml.bak#ConfiguretheOpsAgent.sudotee/etc/google-cloud-ops-agent/config.yaml >/dev/null <<EOFmetrics:receivers:nginx:type:nginxstub_status_url:http://127.0.0.1:80/nginx_statusservice:pipelines:nginx:receivers:-nginxlogging:receivers:nginx_access:type:nginx_accessnginx_error:type:nginx_errorservice:pipelines:nginx:receivers:-nginx_access-nginx_errorEOFFor these changes to take effect, you must restart the Ops Agent:
Linux
- To restart the agent, run the following command on your instance:
sudo systemctl restart google-cloud-ops-agent
- To confirm that the agent restarted, run the following command and verify that the components "Metrics Agent" and "Logging Agent" started:
sudo systemctl status "google-cloud-ops-agent*"
Windows
- Connect to your instance using RDP or a similar tool and login to Windows.
- Open a PowerShell terminal with administrator privileges by right-clicking the PowerShell icon and selectingRun as Administrator
- To restart the agent, run the following PowerShell command:
Restart-Service google-cloud-ops-agent -Force
- To confirm that the agent restarted, run the following command and verify that the components "Metrics Agent" and "Logging Agent" started:
Get-Service google-cloud-ops-agent*
Configure logs collection
To ingest logs from nginx, you must create a receiver for the logsthat nginx produces and then create a pipeline for the new receiver.
To configure a receiver for yournginx_access logs, specify the followingfields:
| Field | Default | Description |
|---|---|---|
exclude_paths | A list of filesystem path patterns to exclude from the set matched byinclude_paths. | |
include_paths | [/var/log/nginx/access.log] | A list of filesystem paths to read by tailing each file. A wild card (*) can be used in the paths. |
record_log_file_path | false | If set totrue, then the path to the specific file from which the log record was obtained appears in the output log entry as the value of theagent.googleapis.com/log_file_path label. When using a wildcard, only the path of the file from which the record was obtained is recorded. |
type | This value must benginx_access. | |
wildcard_refresh_interval | 60s | The interval at which wildcard file paths ininclude_paths are refreshed. Given as atime duration, for example30s or2m. This property might be useful under high logging throughputs where log files are rotated faster than the default interval. |
To configure a receiver for yournginx_error logs, specify the followingfields:
| Field | Default | Description |
|---|---|---|
exclude_paths | A list of filesystem path patterns to exclude from the set matched byinclude_paths. | |
include_paths | [/var/log/nginx/error.log] | A list of filesystem paths to read by tailing each file. A wild card (*) can be used in the paths. |
record_log_file_path | false | If set totrue, then the path to the specific file from which the log record was obtained appears in the output log entry as the value of theagent.googleapis.com/log_file_path label. When using a wildcard, only the path of the file from which the record was obtained is recorded. |
type | This value must benginx_error. | |
wildcard_refresh_interval | 60s | The interval at which wildcard file paths ininclude_paths are refreshed. Given as atime duration, for example30s or2m. This property might be useful under high logging throughputs where log files are rotated faster than the default interval. |
What is logged
ThelogName is derived fromthe receiver IDs specified in the configuration. Detailed fields inside theLogEntryare as follows.
Thenginx_access logs contain the following fields in theLogEntry:
| Field | Type | Description |
|---|---|---|
httpRequest | object | SeeHttpRequest |
jsonPayload.host | string | Contents of the Host header (usually not reported by nginx) |
jsonPayload.level | string | Log entry level |
jsonPayload.user | string | Authenticated username for the request |
severity | string (LogSeverity) | Log entry level (translated). |
Thenginx_error logs contain the following fields in theLogEntry:
| Field | Type | Description |
|---|---|---|
jsonPayload.client | string | Client IP address (optional) |
jsonPayload.connection | number | Connection ID |
jsonPayload.host | string | Host header (optional) |
jsonPayload.level | string | Log entry level |
jsonPayload.message | string | Log message |
jsonPayload.pid | number | The process ID issuing the log |
jsonPayload.referer | string | Referer header (optional) |
jsonPayload.request | string | Original HTTP request (optional) |
jsonPayload.server | string | Nginx server name (optional) |
jsonPayload.subrequest | string | Nginx subrequest (optional) |
jsonPayload.tid | number | Thread ID where the log originated |
jsonPayload.upstream | string | Upstream request URI (optional) |
severity | string (LogSeverity) | Log entry level (translated). |
Configure metrics collection
To ingest metrics from nginx, you must create a receiver for the metricsthat nginx produces and then create a pipeline for the new receiver.
This receiver does notsupport the use of multiple instances in the configuration, for example, tomonitor multiple endpoints. All such instances write to the same time series,and Cloud Monitoring has no way to distinguish among them.
To configure a receiver for yournginx metrics, specify the followingfields:
| Field | Default | Description |
|---|---|---|
collection_interval | 60s | Atime duration value, such as30s or5m. |
server_status_url | http://localhost/status | The URL exposed by the nginx stub status module. |
type | This value must benginx. |
What is monitored
The following table provides the list of metrics that the Ops Agent collectsfrom the nginx instance.
| Metric type | |
|---|---|
| Kind, Type Monitored resources | Labels |
workload.googleapis.com/nginx.connections_accepted | |
CUMULATIVE, INT64gce_instance | |
workload.googleapis.com/nginx.connections_current | |
GAUGE, INT64gce_instance | state |
workload.googleapis.com/nginx.connections_handled | |
CUMULATIVE, INT64gce_instance | |
workload.googleapis.com/nginx.requests | |
CUMULATIVE, INT64gce_instance | |
Verify the configuration
This section describes how to verify that you correctly configured thenginx receiver. It might take one or twominutes for the Ops Agent to begin collecting telemetry.
To verify that nginx logs are being sent toCloud Logging, do the following:
In the Google Cloud console, go to theLogs Explorer page:
If you use the search bar to find this page, then select the result whose subheading isLogging.
- Enter the following query in the editor, and then clickRun query:
resource.type="gce_instance"(log_id("nginx_access") OR log_id("nginx_error"))
To verify that nginx metrics are being sent toCloud Monitoring, do the following:
In the Google Cloud console, go to theleaderboard Metrics explorer page:
If you use the search bar to find this page, then select the result whose subheading isMonitoring.
- In the toolbar of thequery-builder pane, select the button whose name is eithercode MQL orcode PromQL.
- Verify thatPromQL is selectedin theLanguage toggle. The language toggle is in the same toolbar thatlets you format your query.
- Enter the following query in the editor, and then clickRun query:
{"workload.googleapis.com/nginx.requests", monitored_resource="gce_instance"}
View dashboard
To view your nginx metrics, you must have a chart or dashboardconfigured.The nginx integration includes one or more dashboards for you.Any dashboards are automatically installed after you configure theintegration and the Ops Agent has begun collecting metric data.
You can also view static previews of dashboards withoutinstalling the integration.
To view an installed dashboard, do the following:
In the Google Cloud console, go to the
Dashboards page:If you use the search bar to find this page, then select the result whose subheading isMonitoring.
- Select theDashboard List tab, and then choose theIntegrations category.
- Click the name of the dashboard you want to view.
If you have configured an integration but the dashboard has not beeninstalled, then check that the Ops Agent is running. When there is nometric data for a chart in the dashboard, installation of the dashboard fails.After the Ops Agent begins collecting metrics, the dashboard is installedfor you.
To view a static preview of the dashboard, do the following:
In the Google Cloud console, go to the
Integrations page:If you use the search bar to find this page, then select the result whose subheading isMonitoring.
- Click theCompute Engine deployment-platform filter.
- Locate the entry for nginx and clickView Details.
- Select theDashboards tab to see a static preview. If the dashboard is installed, then you can navigate to it by clickingView dashboard.
For more information about dashboards in Cloud Monitoring, seeDashboards and charts.
For more information about using theIntegrations page, seeManage integrations.
Install alerting policies
Alerting policies instruct Cloud Monitoring to notify you whenspecified conditions occur.The nginx integration includes one or more alerting policies foryou to use.You can view and installthese alerting policies from theIntegrations page inMonitoring.
To view the descriptions of available alerting policies and install them, do the following:
In the Google Cloud console, go to the
Integrations page:If you use the search bar to find this page, then select the result whose subheading isMonitoring.
- Locate the entry for nginx and clickView Details.
- Select theAlerts tab. This tab provides descriptions of available alerting policies and provides an interface for installing them.
- Install alerting policies. Alerting policies need to know where to send notifications that the alert has been triggered, so they require information from you for installation. To install alerting policies, do the following:
- From the list of available alerting policies, select those that you want to install.
In theConfigure notifications section, select one or more notification channels. You have the option to disable the use of notification channels, but if you do, then your alerting policies fire silently. You can check their status in Monitoring, but you receive no notifications.
For more information about notification channels, seeManage notification channels.
- ClickCreate Policies.
For more information about alerting policies in Cloud Monitoring, seeIntroduction to alerting.
For more information about using theIntegrations page, seeManage integrations.
Troubleshooting
On most distributions, nginx comes withngx_http_stub_status_module enabled.You can check if the module is enabled by running the following command:
sudo nginx -V 2>&1 | grep -o with-http_stub_status_moduleThe expected output iswith-http_stub_status_module, which means the moduleis enabled. In rare cases, if the command returns no output, you must compilenginx from source with the-with-http_stub_status_module following the nginxpublic documentation.
What's next
For a walkthrough on how to use Ansible to install the Ops Agent, configurea third-party application, and install a sample dashboard, see theInstall the Ops Agent to troubleshoot third-party applications video.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.