Occasionally you may run into situations where the performance data is available, but no monitoring tool can be used to collect this data. This article describes the cases where you could write a script or a small program to retrieve and log this data. The methods covered are
The object here is to get a script or small program to connect to the DB and run specific SQL queries to retrieve performance data from the server. This in effect is what a Database monitor does. A DBA can normally help you create the necessary SQL queries for your desired counters if you are not proficient with SQL. Refer to our article on Database Monitoring.
A script can be written to create and log the network measurements. This is widely used when measuring network performance. A shell script or C code can run ping at regular intervals, to capture the response time and log it to a text file.
ping –n 1 google.co.uk will return a line like this:
Reply will be:
Pinging google.co.uk [220.127.116.11] with 32 bytes of data:
Reply from 18.104.22.168: bytes=32 time=19ms TTL=118
From the above response, you want your script to capture the value after “time=” and before “ms”.
So running ‘ping –n 1 google.co.uk | cut –d “=” –f 2 | cut –d “m” –f 1’
would simply return “3” in this case.
For more information you can read the UNIX or Linux man pages for the following commands:
cat, cut, awk or gawk, grep. These can also be found from many locations on the internet.
The same can, of course, be achieved with a C program.
Another option is to create a script that runs traceroute or any other network command-line tool (Refer to our article on Monitoring Networks ) and process the results in the same way. You will then end up with a CSV file that can be imported into any performance results analysis tool. With each of the examples above, the script or program should be scheduled to run at regular intervals. Note that shorter intervals may impact server performance, therefore never go below 10 seconds for custom scripts that monitor servers.
A shell or Vuser script can be programmed to remotely access the UNIX server (via telnet, ssh…) i.e. run the local commands necessary to find out the statistics (refer to the UNIX section in our article Monitoring Operating Systems) you require and then log this data to a file. This is the method used by SiteScope and several other monitoring tools.
Apache exposes its performance stats on a web page, which can be accessed by any browser. Once you have enabled access to the Apache server statistics page (refer to our article Monitoring Web Servers) you can retrieve the data from this page with the wget command. e.g. wget http://your.server.name/server-status
This means that the data is there for a script to retrieve, therefore you can create a small script to read the page at regular intervals and log the values to a file.
For example, you can use the command wget to retrieve the information and use various commands to find and extract the information you require i.e. cat, grep cut etc.
Another option is to simply record a LoadRunner web script that loads the page. You can then use web_reg_save_param() to find the desired values and use lr_user_data_point() to report the values to the Controller as monitor data.
Since Oracle WebLogic exposes its stats via the JMX API, you can write a small Java program that remotely calls this API to retrieve measurements as needed. Refer to Java Net for more information. It is advisable to add code to your program to log the values retrieved to a CSV file.
There are numerous ways to retrieve performance data even if no monitoring tool can be used.
To find out how SQA Consulting can assist you with your performance monitoring and scripting needs contact us.