Apache Authors: Pat Romanski, Liz McMillan, Elizabeth White, Christopher Harrold, Janakiram MSV

Related Topics: Apache, Java IoT

Apache: Article

Analyzing Load on Apache Web Server

Monitoring performance over any desired time period

A web server plays an increasingly important role in the computing world as the world has shifted away from traditional stand-alone desktop computing to Internet's Client-Server and its variants based computing paradigm. Almost everything on networks is consumed either by using web services or web-pages, for all of which, a web-server is integral. As such, it becomes imperative for organizations to be able to finely monitor their servers' load usage and average performance over different times of day and according to the kind of resources hosted on the server. This raises the need for a solution through which organizations and individuals can monitor their web servers' performance to an arbitrary level of granularity depending on their needs.

This article addresses the same issue and implements an approach for the same in Java programming language.

Problem Statement - Use Case Scenario
Consider the case where you want to monitor the performance of an Apache Web Server for some past time. You would want to know what are the numbers of pages served by the server in that elapsed time span so as to identify the performance as well as utilization of the Web Server.

The mod_status module in the Apache Web Server already provides us with a status file which determines the performance of the server through several statistics including number of worker, requests, time the server has been running since it was started, and number of requests amongst other things.

But a major disadvantage of mod_status file is that it tells us about the average number of requests since the time server was started and this may not reflect the actual performance of the server in various instances. For example, consider that the server was started at 10:00 AM and it ran till 12:00 Noon. In those 2 hours, it server 120 requests. So the number of request returned by mod_status file would be 1 request per minute. But, during that time span, let us say the server was idle between 10:00 - 11:00 AM and it actually server 120 request in a time span of one hour only. So the actual performance would be 2 requests per minute from 11:00-12:00. There is no way in mod_status file to the status for different time instances. It returns the average only from the time it was started to the present time.

In this article we will implement a way to find out the average performance of the server for different time periods without the need to stop/start the server again and again. We will also store those values for a fairly large period in a database so that we can get a better know-how of the server performance over different time periods.

Tech and Services to be Used
We are going to implement the solution in Java and will make use of the below mentioned services and tech:

  1. Apache Web Server: We will be using an instance of Apache Web Serve in order to monitor it and send requests to it to fetch the machine readable status file generated by mod_status module.
  2. A listener to receive the records. In this example we will showcase it through H2 Database. It will be used to store the values fetched from the status module. Any relational database can be used instead of H2. Users are free to register another listener and implement it the way they want.
  3. Servlets and JSP (Optional): The implementation would communicate with the Apache web server using a servlet hosted on tomcat server. The same can be achieved using command line.


Let us now delve into the actual implementation of the application. This article uses Eclipse as a development environment and assumes familiarity with Eclipse. The article also assumes that you have an Apache web server installed and running on your system. If you do not have Apache Web Server installed, you can download and install it from http://httpd.apache.org/download.cgi

Implementation Roadmap
In this implementation, we will first get the machine readable file which contains server statistics from the Apache web server. We will store these values in a database for a number of time stamps in a convenient fashion. These values would then be used for the calculation of the average number of requests served for different time periods by the Apache Web Server. In the final step, we will allow this app to be used through a Servlet. Alternatively, users can also issue commands through a command line or design a UI for the same which allows them to specify the time frame for which they want the average number of requests for the Apache Web server.

Enable and Test Status Support for mod_status

In order to get the server statistics from mod_status, you first have to enable it so that it can be queried to generate the status file. In order to do so, go to the Apache Web Server installation directory and traverse to the httpd.conf file in the conf directory and add the following to the file:

Also, edit the httpd.conf and mark ExtendedStatus of the server as On.

ExtendedStatus On

You should be able to get the server statistics now. Hit the following URL in the web browser to get the status file:


The file is generated in two formats. One is the human readable one, which is what you get when you hit the above mentioned URL in the browser. The second is the machine readable file, which is like a normal text file and can be directly used by an application to use the statistics reported by the file. For our purpose, we will be calling this machine readable file directly from our application. The machine readable file can be accessed by using the following link:


Create a Listener:
You can extend the IApacheSnapshotProcessor interface which has two methos.  The implementation is upto the user. A sample implementation in provided through H2Persiter which extends the IApacheSnapshotProcessor interface.

Create Schema in H2
As a second step, we will create a schema and a table for storing the values retrieved from the machine readable file. The application would repeatedly ping the Apache Web server URL to get the machine readable file at different time intervals. We will be parsing the values obtained from the file and store them in the database for future use.

Download and install the H2 database from http://www.h2database.com/html/main.html.

Connect to H2 using the following credentials:

Create a schema and table in H2 to store the values. The table should contain the following fields:

1.        ID (serves as the primary key)

2.       TOTAL_ACCESS (for storing the total number of accesses from the time server started running)

3.       TOTAL_KBYTES (total number of KBs since the time server was running)

4.       UPTIME

5.       REQ_PS

6.       BYTES_PS

7.       BYTES_PR

8.       BUSY_WORKER

9.       IDLE_WORKER

10.   SNAPSHOT_TIME_DIFF (this field will be used as integer count for the count difference between the number of request at the time first server snapshot was taken and the number of request for which the current snapshot has been taken. So let's say that we take server snapshot every 2 sec and the server started at 10:00 AM. So for the first request at 10:00:00 AM SNAPSHOT_TIME_DIFF value would be 0. At 10:00:02 AM, value would be 1 and so on.)


Our table is now ready and we can use it to store values of all the fields which we get from the mod_status file.

Getting Values from the Machine Readable File
We now have to get the values from the machine readable mod_status file and parse them before storing those values into the database. Create a class (RequestCounter.java) which will access the URL at regular intervals, will read the file, and parse the values into variables, and these variables will then be passed on to a persister class which will then store them in the database.

We will first construct the URL in the proper format as required by Apache Web Server in a method (pool())

This method will again call the pool() method which will then get the Apache Server status from inside of a method (TimerTask). This method will run till the time we have specified. Suppose, we want to store the values for last 2 hours, then we can set the timer for that time period. After that time period is elapsed, it will call the cancel() method and will stop hitting the Apache Web Server URL.

getApacheStatus(url); calls the method which gets the machine readable file.

Once we have the file, we read it line by line and parse it and store the values in private variables.

Storing Values in the Database
Once we have the parsed values from the file, we now need to store them into the database. For this, create a file (H2Persister.java) which will create a connection to the database and will insert values in the database. Later on, we will use the same file to get average performance values from the database as well.

Create a method (connect()) which will create a JDBC connection object for the database.

Class.forName("org.h2.Driver"); specifies the JDBC driver name. We get the connection from DriverManager using getConnection method, and this assign this to conn variable which is an instance of the Connection object.

Create a method (process()), which will take as arguments the values which we parsed, and will then prepare an sql query and store those values in the database by executing that query.

Statement stmt = conn.createStatement();creates a Statement object. We prepare a query which will insert the values into the database.

String sql = "insert into APACHE_MOD_STATUS.COUNT_HANDLER values (DEFAULT," + TOTAL_ACCESS + "," + TOTAL_KBYTES + "," + UPTIME + "," + REQ_PS + "," + BYTES_PS + "," + BYTES_PR + "," + BUSY_WORKER + "," + IDLE_WORKER     + "," + (System.currentTimeMillis() / 1000 - startupTime) + ", DEFAULT" + ")";

Afterwards, we execute the query to insert the values in the database.

We call this process() method from our previously created RequestCounter file and pass the values which we parsed there to the process() method.

hPersister.process(totalAccesses, totalKBytes, uptime, reqPerSec, ytesPerSec, bytesPerReq, busyWorkers,idleWorkers);

Getting Average Values

We now have to have a mechanism to get the values stored in the database and process them to get the average number of requests during the time frame requested by the user. For this, create a method (getAverage) in H2Persister.java file which will do the same. This method takes the time frame as an argument. First of all, create a SQL query to retrieve the desired values from the database. For our purpose, we need Total_ACCESS and UPTIME fields values from the database. The following query does just that:

String sql = "SELECT ID,TOTAL_ACCESS,UPTIME FROM APACHE_MOD_STATUS.COUNT_HANDLER where SNAPSHOT_TIME_DIFF>"    + (System.currentTimeMillis() / 1000 - startupTime - timeslot - 1);

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery(sql);

Create an ArrayList which will store the values retrieved by the ResultSet object.

ArrayList<RPSTuple> rpsTupleList = new ArrayList<RPSTuple>();

This ArrayList is of the type RPSTuple which has two private fields totalAccess and uptime and getter and setter methods for the same.

Iterate over the ResultSet object rs and store the values into the ArrayList one by one.

Once we have the desired values in the ArrayList, let us now process them to get the average number of requests for the server over the specified period of time.

From the rpsTupleList, we first get its first node and last node.

From this, we get the average by subtracting total access numbers of last node from first node, and divide that by difference of first node and last node uptime.

lastNode.getTotalAccess()-firstNode.getTotalAccess()) / (lastNode.getUptime()-firstNode.getUptime()

This gives us the performance of an Apache Web Server link in terms of average number of requests over a desired time frame and not just the time frame from which the server started running to the current one.

Create a Servlet
We will now create a Servlet (CounterServlet.java) which will display the average number of requests which we get from the above.

In addition to a Servlet, one can also call the same app from a command line as well.

This article describes the process of monitoring an Apache Web Server link performance by giving the users and system administrators the facility to monitor the performance over any desired time period. This enables the users more control over the unraveling and understanding of the usage statistics of their servers over different periods of time so that they can better utilize their systems according to peak loads and various other factors.

More Stories By Peeyush Taori

Peeyush Taori is a Senior Systems Engineer with Infosys Technologies Limited and has worked in Java Technology Domain for more than 5 years

More Stories By Kumar Tiwari

Kumar Manava Tiwari has six years of IT experience. He has worked in Cloud Computing, software factories, enterprise application development and application frameworks development. He is currently working as a Technology Lead with Infosys Technologies Limited, India.

@ThingsExpo Stories
Business professionals no longer wonder if they'll migrate to the cloud; it's now a matter of when. The cloud environment has proved to be a major force in transitioning to an agile business model that enables quick decisions and fast implementation that solidify customer relationships. And when the cloud is combined with the power of cognitive computing, it drives innovation and transformation that achieves astounding competitive advantage.
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...
In his session at Cloud Expo, Alan Winters, U.S. Head of Business Development at MobiDev, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to maximize project result...
Personalization has long been the holy grail of marketing. Simply stated, communicate the most relevant offer to the right person and you will increase sales. To achieve this, you must understand the individual. Consequently, digital marketers developed many ways to gather and leverage customer information to deliver targeted experiences. In his session at @ThingsExpo, Lou Casal, Founder and Principal Consultant at Practicala, discussed how the Internet of Things (IoT) has accelerated our abilit...
In his keynote at 19th Cloud Expo, Sheng Liang, co-founder and CEO of Rancher Labs, discussed the technological advances and new business opportunities created by the rapid adoption of containers. With the success of Amazon Web Services (AWS) and various open source technologies used to build private clouds, cloud computing has become an essential component of IT strategy. However, users continue to face challenges in implementing clouds, as older technologies evolve and newer ones like Docker c...
Data is the fuel that drives the machine learning algorithmic engines and ultimately provides the business value. In his session at Cloud Expo, Ed Featherston, a director and senior enterprise architect at Collaborative Consulting, discussed the key considerations around quality, volume, timeliness, and pedigree that must be dealt with in order to properly fuel that engine.
No hype cycles or predictions of zillions of things here. IoT is big. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, Associate Partner at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He discussed the evaluation of communication standards and IoT messaging protocols, data analytics considerations, edge-to-cloud tec...
In his keynote at 18th Cloud Expo, Andrew Keys, Co-Founder of ConsenSys Enterprise, provided an overview of the evolution of the Internet and the Database and the future of their combination – the Blockchain. 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 settl...
In his session at @ThingsExpo, Dr. Robert Cohen, an economist and senior fellow at the Economic Strategy Institute, presented the findings of a series of six detailed case studies of how large corporations are implementing IoT. The session explored how IoT has improved their economic performance, had major impacts on business models and resulted in impressive ROIs. The companies covered span manufacturing and services firms. He also explored servicification, how manufacturing firms shift from se...
IoT is at the core or many Digital Transformation initiatives with the goal of re-inventing a company's business model. We all agree that collecting relevant IoT data will result in massive amounts of data needing to be stored. However, with the rapid development of IoT devices and ongoing business model transformation, we are not able to predict the volume and growth of IoT data. And with the lack of IoT history, traditional methods of IT and infrastructure planning based on the past do not app...
Organizations planning enterprise data center consolidation and modernization projects are faced with a challenging, costly reality. Requirements to deploy modern, cloud-native applications simultaneously with traditional client/server applications are almost impossible to achieve with hardware-centric enterprise infrastructure. Compute and network infrastructure are fast moving down a software-defined path, but storage has been a laggard. Until now.
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...
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
DXWorldEXPO LLC announced today that All in Mobile, a mobile app development company from Poland, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. All In Mobile is a mobile app development company from Poland. Since 2014, they maintain passion for developing mobile applications for enterprises and startups worldwide.
JETRO showcased Japan Digital Transformation Pavilion at SYS-CON's 21st International Cloud Expo® at the Santa Clara Convention Center in Santa Clara, CA. The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get...
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
DXWorldEXPO LLC announced today that the upcoming DXWorldEXPO | CloudEXPO New York event will feature 10 companies from Poland to participate at the "Poland Digital Transformation Pavilion" on November 12-13, 2018.
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...
"We view the cloud not as a specific technology but as a way of doing business and that way of doing business is transforming the way software, infrastructure and services are being delivered to business," explained Matthew Rosen, CEO and Director at Fusion, in this SYS-CON.tv interview at 18th Cloud Expo (http://www.CloudComputingExpo.com), held June 7-9 at the Javits Center in New York City, NY.
As data explodes in quantity, importance and from new sources, the need for managing and protecting data residing across physical, virtual, and cloud environments grow with it. Managing data includes protecting it, indexing and classifying it for true, long-term management, compliance and E-Discovery. Commvault can ensure this with a single pane of glass solution – whether in a private cloud, a Service Provider delivered public cloud or a hybrid cloud environment – across the heterogeneous enter...