If you have read the previous article on how to monitor NGINX, you should know how much information you can get from just a few indicators of your network environment. And you also saw how easy it is to collect metrics from an NGINX-specific base. But to achieve comprehensive and continuous monitoring of NGINX, you need a powerful monitoring system to store and visualize indicators and alert you when anomalies occur. In this article we will show you how to use Datadog installs NGINX monitoring so you can view these metrics in a custom dashboard:
NGINX dashboard
Datadog allows you to build graphs and alerts on individual hosts, services, processes, and metrics, or use them Build in almost any combination. For example, you can monitor all your hosts, or all NGINX hosts in a specific availability zone, or you can monitor one key metric for all hosts with a specific tag. This article will tell you how to:
Monitor NGINX metrics on the Datadog dashboard just like you monitor any other system
Set up automatic alerts to notify you when a key metric changes drastically
In order to collect NGINX metrics, you first need to ensure that NGINX has the status module enabled and a URL that reports status metrics. For step-by-step configuration of open source NGINX and NGINX Plus, please refer to previous related articles.
The Datadog Agent is open source software that collects and reports metrics on your hosts so they can be viewed and monitored using Datadog. Installing this agent usually only requires one command
As long as your agent is up and running, you will see your host's metrics reported under your Datadog account.
Datadog infrastructure list
Next, you need to create a simple NGINX configuration file for the agent. The configuration directory for the agent on your system should be found here.
In the directory conf.d/nginx.yaml.example you will find a simple configuration file that you can edit and provide a status URL and optional tags for each NGINX instance:
init_config: instances: - nginx_status_url: http://localhost/nginx_status/ tags: - instance:foo
When you provide the status URL and any tag, save the configuration file as conf.d/nginx.yaml.
You must restart the agent to load the new configuration file. The restart commands are here and vary depending on the platform.
To check that Datadog and NGINX are properly integrated, run Datadog’s info command. See here for the commands used by each platform.
If the configuration is correct, you will see an output like this:
Checks ====== [...] nginx ----- - instance #0 [OK] -Collected8 metrics &0 events
Finally, open “Nginx Integration” in your Datadog account. It's very easy, you just click the "Install Integration" button in the NGINX integration settings.
Install integration
Once the agent starts reporting NGINX metrics, you will see an NGINX dashboard appear in your list of available dashboards in Datadog.
The basic NGINX dashboard displays useful charts and graphs covering several key metrics from our introduction to NGINX monitoring. (Some metrics, notably request processing time, require log analysis, which Datadog does not support.)
You can easily create a comprehensive dashboard to monitor your entire website facility by adding charts for important metrics outside of NGINX. For example, you might want to monitor your NGINX host-level metrics, such as system load. To build a custom dashboard, simply clone a default NGINX dashboard by clicking on the option near the upper right corner of the dashboard and selecting "Clone Dash".
Clone dash
You can also monitor your NGINX instances at a higher level using Datadog’s host maps, for example, color-coding the CPU usage of all your NGINX hosts to identify potential hot spots.
Once Datadog captures and visualizes your metrics, you may want to set up some monitoring to automatically keep an eye on your metrics and alert you when there are issues. A typical example is described below: a metric monitor that alerts you when NGINX throughput suddenly drops.
Datadog indicator alerts can be "throughput-based" (alarms will occur when the indicator exceeds a set value) or "change range-based" (alerts will occur when the indicator changes exceed a certain range). In this example, we'll take the latter approach, which will alert us when incoming requests per second drops dramatically. A decrease often means there is a problem.
Create a new indicator monitor. Select "New Monitor" from the Datadog "Monitors" drop-down list. Select "Metric" as the monitor type.
NGINX metric monitor
Define your metric monitor. We want to know the number of NGINX total requests per second dropped, so we define in our infrastructure the sum of nginx.net.requestpers we are interested in.
NGINX metric
Set metric alert conditions. We want to alert on changes, rather than a fixed value, so we select "Change Alert". We set up monitoring to alert whenever request volume drops by more than 30%. Here, we use a one-minute data window to represent the value of the "now" metric, and compare the average change across that interval to the metric value for the previous 10 minutes.
NGINX metric change alert
custom notification. If NGINX's request volume drops, we want to notify our team. In this example, we will send a notification to the ops team's chat room and send an SMS to the on-call engineer. In “Say what’s happening” we give the monitor a name and add a short message accompanying the notification suggesting what to start investigating first. We'll @ops the team on Slack, and @pagerduty will send alerts to text messages.
NGINX metric notification
Save integrated monitoring. Click the "Save" button at the bottom of the page. You are now monitoring a key NGINX job metric and texting the engineer on duty when it drops rapidly.
In this article, we talked about integrating NGINX with Datadog to visualize your key metrics and notify your team when there is an issue with your network infrastructure.
If you have been using your own Datadog account, you should now have greatly improved visibility into your web environment and the ability to analyze the metrics that are most valuable to your environment, the patterns you use, and your organization. Create automated monitoring.
The above introduces how to use Datadog to monitor Nginx, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.
The above is how to use Datadog to monitor the content of Nginx. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!