Welcome!

Eclipse Authors: Pat Romanski, Elizabeth White, Liz McMillan, David H Deans, JP Morgenthal

Blog Feed Post

Nginx Reverse Proxy (NRP) monitoring

nignx monitoringNginx server currently occupies one of the most popular positions in the world. It is a free, open-source, high-performance HTTP server and reverse proxy, which is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption. Unlike traditional servers, Nginx doesn’t rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture.

In order to monitor Nginx servers and make sure everything is running “nice and smoothly”, any sysadmin naturally has the option to turn on Nginx’s stub_stats module. However, notice that the statistics available for this popular module unfortunately often don’t convey enough information, especially if you are using Nginx as an HTTP reverse proxy or balancer.  This paper presents the possibility of using the Monitis custom monitor approach to perform online monitoring of a reverse proxy built on the Nginx server platform.

Usage approach

The possibilities for getting statistics from Nginx are very limited, but fortunately, it has a powerful feature to configure a log file. This makes it possible to create necessary statistics by configuring the log file and then watching and grabbing the monitoring data from it.

The presented monitor is divided into two parts: a watching part and a processing part.

The watching part follows the NRP monitor log and accumulates the necessary statistics. The processing part periodically reads the accumulated statistics, executes necessary calculations and sends them to the Monitismainserver.  Then you can simply see the NRP status online on your Monitis account dashboard.

Usually it is important to know while monitoring NRP what the input load is on the NRP server, how this load is divided between target servers and what the percentage of successful responses is, from the target servers.

The current monitor calculates and shows the following metrics:

  1. The input load to NRP (in_load)
    The number of requests which were received, divided by the observation time
  2. The load redirected to destination host 1 (out1_load)
    The number of requests redirected to destination host 1, divided by the observation time
  3. The load redirected to destination host 2 (out2_load)
    The number of requests redirected to destination host 2, divided by the observation time
  4. The percentage of requests which  were redirected to destination host 1 (out1_reqs)
  5. The percentage of requests which  were redirected to destination host 2 (out2_reqs)
  6. The percentage of successfully processed requests by destination host 1 (out1_2xx)
    The number of responses with a successful status code (2xx) relative to the total number of requests to destination host 1
  7. The percentage of successfully processed requests by destination host 2 (out2_2xx)
    The number of responses with a successful status code (2xx) relative to the total number of requests to destination host 2
  8. The common estimation of NRP state (status)

○     OK – normal working state

○     IDLE – idle state (don’t receive any requests)

○     DEAD – NRP is down (Nginx process isn’t found)

 

Notice that metrics 4 and 5 show the real distribution of requests between destination hosts. Their sum always should equal 100%.

NRP monitor log file configuration

The Nginx log format is very flexible, so you can build it by using a lot of Nginx runtime variables. To prepare your ownlogfile there are two directives:

log_format <name> <format pattern>
access_log <path> <[format name [buffer=size]] |> [off]

The log_format directive describes the format of a log entry. Most of the variables can be used to format a log file pattern. The access_log directive sets the path, format and buffer size for the access log file.

For example, the “Own log” file can be declared as follows:

# Own log format
log_format own ‘ $time_local | $server_name | $request_length ‘;
# Own access log
access_log /var/log/nginx/monitor.log own;

It was decided that this monitor log file should have the following format:

<status code>#<responding host address>  e.g.  404#12.13.11.12:80

To do this, we have to add 2 additional lines in the “/etc/ngnix/sites-available/default” config file near the definition of Nginx standard log files in the ngnix server block to define a new log file “monitor.log” like the following:

# definition of new log file format

log_format monitor '$upstream_status#$upstream_addr';

# specification of location for new log file

access_log /var/log/nginx/monitor.log monitor;

NRP monitor customization

The monitor consists of two main scripts – the watching and accumulating script (called monitor.sh) and the processing script (called nginx_monitor.sh) that periodically requests data, processes it and sends it to Monitis. Besides these, there is the Monitis OpenAPI wrapper script (called monitis_api.sh) and few serviced scripts. Thus, as you can see, it was fully implemented by using Linux Bash scripts.

To use it you should tune it by replacing some parameters (constants) by your own – APIKey, ServiceKey, HRP host IP, Target servers IPs, and so on. For detailed instructions you can look through the sourcecode.

NRP monitor test

The simplest configuration was chosen for testing of the reverse proxy.

Two destination hosts were simulating responses by generating random status codes with normal probability distribution and with mean value – 2xx successful code. The input load was generated by an HTTP generator which provided a load on NRP of about 1 request per second.

NRP was tuned to round-robin distribution so that the input load should have been distributed equally between the designated hosts. As result we got the following monitoring table in our Monitis account:

Notice that during the test the NRP was restarted. The monitor detected this and marked it as NRP DEAD status.

Double-clicking on any line will show more detailed additional information:

Double-clicking on the DEAD status line shows the following:

Naturally, it is possible to look at the graphical presentation of the monitored data:

This graph shows the distribution of requests between the two destination hosts. As you can see, the distribution of requests is done almost equally and the curves fluctuate around 50%, which is normal for our tests.

 

Share Now:del.icio.usDiggFacebookLinkedInBlinkListDZoneGoogle BookmarksRedditStumbleUponTwitterRSS

Read the original blog entry...

More Stories By Hovhannes Avoyan

Hovhannes Avoyan is the CEO of PicsArt, Inc.,

IoT & Smart Cities Stories
Every organization is facing their own Digital Transformation as they attempt to stay ahead of the competition, or worse, just keep up. Each new opportunity, whether embracing machine learning, IoT, or a cloud migration, seems to bring new development, deployment, and management models. The results are more diverse and federated computing models than any time in our history.
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
The standardization of container runtimes and images has sparked the creation of an almost overwhelming number of new open source projects that build on and otherwise work with these specifications. Of course, there's Kubernetes, which orchestrates and manages collections of containers. It was one of the first and best-known examples of projects that make containers truly useful for production use. However, more recently, the container ecosystem has truly exploded. A service mesh like Istio addr...
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...