Part Two: How to Monitor Nginx using Elastic Stack on a CentOS 7 VPS or Dedicated Server

Part Two: How to Monitor Nginx using Elastic Stack on a CentOS 7 VPS or Dedicated Server

In the previous article (Part One: How to Monitor Nginx using Elastic Stack on a CentOS 7 VPS or Dedicated Server) you learned how to install the various component of the Elastic Stack Next, we will help you use the installed components to monitor Nginx web server.

Ready? Let’s go!

Create and use visualizations

From this point, we’ll only use the Kibana browser-based windows to view and search the system data.

Filebeat is already monitoring the NGINX access as well as the error logs. However, we must generate traffic to create data that can be visualized in Kibana. Run the command below in a separate window to create web server requests:

while true ; do n=$(( RANDOM % 10 )) ; curl "localhost/?$n" ; sleep $n ; done

In your browser, navigate to http://localhost:5601 to access the secure port where you can open Kibana.

On the left sidebar, select your default index pattern to direct Kibana to utilize the docs indexed by either Metricbeat or Filebeat. Select filebeat-* to view the index pattern of Filebeat, then from the screen below, choose the start icon, to set filebeat-*as your default index pattern.

Next, click on “discover” to view the logs indexed by Filebeat. The window below will appear:

In the search box enter nginx.access.url:”/?5″. This will enable you to search all NGINX access logs for requests that correspond to /?5. The logs represent those that are created by the shell loop running in the background. An Elasticsearch will be conducted automatically by the interface to display all the matching documents.

Filebeats’ Dshboards

>Besides gathering NGINX access logs, Filebeats presents numerous dashboards into the Kibana service to deliver vital default visualization for data. Select “Dashboard” from the left sidebar menu:

A list of all the dashboards on Kibana will appear:

Enter “nginx” in the search box to search the NGINX dashboards. Select all the dashboards with the title “[Filebeat Nginx] Access and error logs”. The Windows below will appear:

Keep scrolling down to see all the visualizations present in the default dashboard. Some of the visualizations of interest include response code by URL, geolocation maps, and useragent summaries. The dashboards makes it easy to analyze the traffic to your webserver and debug issues.

First, navigate to the “Response codes over time” display in the default dashboard. There should be numerous 404 responses there, click on any of the 404 bars.

At the top of the Kibana dashboard click on “Apply Now” to filter all the access logs that gave a 404 response to the user. The window below will appear:

Now scroll down to access the visualization for the 404 logs. The “Response codes by top URLs” interfaces show NGINX is only giving 404 response codes that correspond to /server-status url:

It now easy to fix NGINX configuration and resolve the error.

Configuring Nginx

Access the /etc/nginx/nginx.conf file and add a location data between the include line and location line.

/etc/nginx/nginx.conf

include /etc/nginx/default.d/*.conf;

    location /server-status {
            stub_status on
            access_log off;
            allow 127.0.0.1;
            allow ::1;
            deny all;
        }

    location / {
        }

Run the command below to restart NGINX:

sudo systemctl restart nginx

Now, repeat the steps in the previous section to view the response code history. The 404 codes should slowly stop appearing, as you conduct new searches on Kibana.

Metricbeats

Using the visualizations generated by Metricbeat it easy to see not only the web server logs but also the host metrics.

Choose the dashboard from the sidebar, then in the search box type “metricbeat” to filter the Mtericbeat dashboards. Select the dashboard titled “[Metricbeat System] Overview”.  The following window will appear:

The dashboard above features a comprehensive overview of the host metrics including memory, CPU, network use, and disk. Navigate to the “System Navigation” area and select the “Host Overview”.

Scroll down to see the host data collected by Metricbeat. The following windows will appear.

The above window provides a wealth of data of the machine metrics gathered by Metricbeat.

Conclusion

This tutorial covered only a part of the information provided by Metricbeat and Filebeat for search and analysis. You can generate other visualization to provide specific solutions and helpful dashboards for numerous purposes. Search for more comprehensive guides for each component of the stack to get additional information regarding the use of the additional dashboards and visualizations.

Special Note: some leading web hosts provide free 1-click installations of other tools for monitoring server performance. At Hostadvice, you can find extensive information the hosting plans and what they include, as well as user and expert reviews on the best web hosting services.

Check out these top 3 Best web hosting services

Hostinger
AU$4.43 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
IONOS
AU$1.48 /mo
Starting price
Visit IONOS
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.3
Ultahost
AU$3.70 /mo
Starting price
Visit Ultahost
Rating based on expert review
  • User Friendly
    4.3
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.0
  • Pricing
    4.8

Part One: How to Monitor Nginx using Elastic Stack on a CentOS 7 VPS or Dedicated Server

This is Part I of a two-part tutorial explaining how to use the different compon
less than a minute
Idan Cohen
Idan Cohen
Marketing Expert

How to Configure Nginx as Reverse Proxy for Apache on an Ubuntu 16.04 VPS or Dedicated Server

This guide is compiled to help you learn how to install Nginx as a reverse proxy
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

Install & Configure the Caddy web server on a CentOS 7 VPS

Caddy is the only new server's that secure by default. It's growing in popularit
less than a minute
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Configure Nginx and Apache on the same Ubuntu VPS or Dedicated Server

Nginx and Apache are great and powerful web servers. However, they both have dra
less than a minute
Idan Cohen
Idan Cohen
Marketing Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top