Performance Statistics Collection for UNIX flavored OS

Introduction:

This post explains how to setup performance counter collection in Unix, Solaris, Linux or HP-UX environment and how to extract the log and present it in a Graphical format with simple ruby program which i have written.

Please download ruby from http://www.ruby-lang.org

The 3 major steps to follow to collect and report performance statistics are as follows:

1.Configure Performance counters
2.Conversion of Performance logs to csv
3.Reporting

1.Configure Performance counters:
90% of the time people are concerned with the memory and cpu statistics, so let’s see how to configure , collect and report memory and CPU statisctis in unix, solaris, linux or HP-UX environment.

Write .sh File:

1.memory statistics
Most of the time people are concerned about the total memory usage rather than breakdown of cache, swap, free, buffer memory etc. hence we can measure the overall memory usage by “free” command available in UNIX flavored OSes.Write a .sh file which will log the free and used memory as follows,

#!/bin/sh
free -m -s1 >> free_mem.log

The above command means the total free and used memory will be collected for every second and stored in the free_mem log file.

2.CPU and other statistics
sometimes people are concerned about knowing everything like cache, swap, free, buffer memory apart from CPU. we can measure all these by “vmstat” command available in UNIX flavored OSes.Write a .sh file which will log these information as follows,

#!/bin/sh
vmstat 1 >> vmstat.log
The above command means the statistics such as

Procs r: The number of processes waiting for run time. b: The number of processes in uninterruptible sleep.

Memory swpd: the amount of virtual memory used. free: the amount of idle memory. buff: the amount of memory used as buffers. cache: the amount of memory used as cache. inact: the amount of inactive memory. (-a option) active: the amount of active memory. (-a option)

Swap si: Amount of memory swapped in from disk (/s). so: Amount of memory swapped to disk (/s).

IO bi: Blocks received from a block device (blocks/s). bo: Blocks sent to a block device (blocks/s).

System in: The number of interrupts per second, including the clock. cs: The number of context switches per second.

CPU These are percentages of total CPU time. us: Time spent running non-kernel code. (user time, including nice time) sy: Time spent running kernel code. (system time) id: Time spent idle. wa: Time spent waiting for IO.

will be collected for every second and stored in the vmstat.log file.

Run the .sh Files during the tests and stop it once the test is done.collect the log files once the test is done for conversion.

2.Conversion of Performance logs to csv:

Convert memory log to CSV:
Execute the below ruby program to convert the log file to the csv file

infile = ARGV[0] || ‘C:\free_mem.log’
freq = ARGV[1] || 1
outfile = ‘C:\Results’
stat = File.stat(infile)
now  = stat.mtime
t=Time.now
lines=[]

File.readlines(infile).each { |line|
    line.chomp
    if line.match(/^-/) then
        data = line.split(/[^-\/\+\w+:$][\s\t]+/)
    temp = ”
    for i in 0 .. (data.length – 1)
        temp = temp + data[i].to_s + ‘,’
    end
    temp[temp.length-1] = ”
    lines << temp
    end
}

lines.each do |row|
  File.open(outfile+t.strftime(“%m%d%Y_%H%M%S”)+”.csv”,”w”) do |the_file|
  the_file.puts “total,used,free”   
      the_file.puts lines                     
    end
  end

Convert vmstat log to CSV:
Execute the below ruby program to convert the log file to the csv file

infile = ARGV[0] || ‘C:\vmstat.log’
freq = ARGV[1] || 1
outfile = ‘C:\Results’
stat = File.stat(infile)
now  = stat.mtime
t=Time.now
lines=[]

File.readlines(infile).each { |line|
    line.chomp
    if line.match(/^\s+\d+/m) then
        now  = now + freq
         date = “#{now.day}/#{now.month}/#{now.year}”
        time = “#{now.hour}:#{now.min}:#{now.sec}”
        data = line.gsub(/^\s+/m,”").gsub(/[\s\t]+/m,”,”).gsub(/,$/m,”")
    lines<<”#{date},#{time},#{data}”
    end
}

lines.each do |row|
  File.open(outfile+t.strftime(“%m%d%Y_%H%M%S”)+”.csv”,”w”) do |the_file|
  the_file.puts “date,time,r,b,swpd,free,buff,cache,si,so,bi,bo,in,cs,us,sy,id,wa,st”    
      the_file.puts lines                      
    end
  end 

3.Reporting:
Open the csv file in which the necessary performance counters data has been collected and generate graph using excel Chart Wizard feature as below CPU sample.
Thanks for Reading the blog. Hope it was useful for you. Please don’t hesitate to post comments if you got any clarification/feedback. Thanks a lot.

How to do Performance Testing in the simplest way for Web Application

Introduction:

Performance testing is a type of testing intended to determine the responsiveness, throughput, reliability, and/or scalability of a system under a given workload. Performance testing is commonly conducted to accomplish the following:
1.Assess production readiness
2.Evaluate against performance criteria
3.Compare performance characteristics of multiple systems or system configurations
4.Find the source of performance problems
5.Support system tuning

This Blog explains how to carry out a performance testing in the simplest way without much coding, scripting with open source tools (Badboy, Jmeter) in Windows environment.

Please download Badboy from http://www.badboy.com.au/download

Please download Jmeter from http://jakarta.apache.org/site/downloads/downloads_jmeter.cgi

The 4 major steps to follow to do performance testing are as follow:
1.Scripting
2.Execution
3.Configure and Collect Performance Statistics
4.Reporting

1.Scripting:
Launch Badboy and record the business transactions to be measured.
Let’s take an example of measuring the performance of launching the Web Application and Login transaction as detailed below,

Export the Script to Jmeter using the “Export” option as mentioned below.

2.Execution:
Open the Exported jmx file in Jmeter and add necessary report features as available in Jmeter for measuring the Response Time

Configure the number of users to be run for the test as mentioned below in the ThreadGroup.

Execute the Test by typing Ctrl+E, Ctrl+R

3.Configure and Collect Performance Statistics:
All windows systems comes with “Perfmon” application to measure and monitor the Performance counters.Launch Perfmon by going to Start>Run>Perfmon of the Server.
Once Perfmon is launched , Navigate to Data collector Sets> User Defined and create an Performance Counter and configure necessary counters by adding to the set as below.



Start the Collector Set by clicking the “Start” option while running the tests so that the statistics are written in the csv file as configured. Stop the collector Set by clicking the “Stop” once the test is done.

4.Reporting:
Generate Response Time Graph from Jemeter Result as below sample.

Open the csv file in which the necessary performance counters data has been collected and generate graph using excel Chart Wizard feature as below CPU sample.

 

Thanks for Reading the blog. Hope it was useful for you. Please don’t hesitate to post comments if you got any clarification/feedback. Thanks a lot.

Follow

Get every new post delivered to your Inbox.