Thanks to http://googlecharts.rubyforge.org/, it give me the inspiration on how to combine ruby and Google Charts, then i just make it by ruby
Thanks to my intern Tom as well, he has helped me to re-factoring of my previous code, he made the charts a little bit fancy than mine:)
enjoy it!
Note: the data of bellowing Diagram is not real data , just for testing purpose :)
Ruby Source Code V1.0:
require 'gchart'
def getresdata(block1)
# scan for the first numeric token
str = block1.scan(/\d+/)[0];
return str;
end
# format RGB
def fill(str)
i = 6 - str.length();
while(i > 0)
str = '0' + str;
i -= 1;
end
return str;
end
def format_color(num, boundary)
return "000000" if num < boundary =" 0"> 16777215;
color = boundary;
increment = (16777216 - boundary)/num;
retStr = "%x" % [boundary];
retStr = fill(retStr);
while(num > 1)
color += increment;
str = "%x" % [color];
str = fill(str);
num -= 1;
retStr += ',' + str;
end
return retStr;
end
def Draw_Perf_data(file)
url_sum = Hash.new();
IO.foreach(file) { |line|
next if !line.include?("lb="); # skip when this is xml head line
line.strip!(); # trim
url = line.scan(/lb="\w+/)[0]; # fetch the 'lb=' token
puts url.sub!("lb=\"", ""); # fetch the value of lb
if url_sum.has_key?(url)
url_sum[url].push(getresdata(line).to_i); # exist, then add cell
else
url_sum[url] = Array.new(1, getresdata(line).to_i); #!exist, then create
end
}
datas = Array.new();
actions = Array.new();
url_sum.each { |key, val|
datas.push(val);
actions.push(key);
}
colors = format_color(3, 0);
arrayabc = Gchart.line(:size => "800x375",:title => "Request Log", :data => datas, :line_colors => colors, :legend => actions, :axis_with_labels => ['y'], :custom => "chg=100,25");
puts(arrayabc);
return arrayabc;
end
######################
# Call the method, just input your Jmeter result log as a parameter, note it should be the default format of your logs
Draw_Perf_data("123.txt");
here is my configuration for my JMeter result file:
No comments:
Post a Comment