module GraphHelper def source_timing(params) #name,data,options puts "display is #{params}" @displayname = params['display_name'] names = [] begin names = get_sources('all') #RhoconnectApi::list_sources(session[:server],session[:token],:all) rescue Exception => e puts "errror #{e.message}" end @sources = [] names.each do |name| s = {} data = [] series = [] options = { :legend => { :show => true }, :title => name } s['name'] = name keys = get_user_count("source:*:#{name}") #RhoconnectApi::stats(session[:server],session[:token], :names => "source:*:#{name}") xmin = 9999999999999999 xmax = -1 ymin = 9999999999999999 ymax = -1 keys.each do |key| method = key.gsub(/source:/,"").gsub(/:.*/,"") series << {:showLabel => true, :label => method } range = get_user_count(nil,key,0,-1) #RhoconnectApi::stats(session[:server],session[:token], {:metric => key, :start => 0, :finish => -1}) thisdata = [] range.each do |value| count = value.split(',')[0] value.gsub!(/.*,/,"") thisdata << value.split(":").reverse thisdata[-1][0] = thisdata[-1][0].to_i * 1000 thisdata[-1][1] = thisdata[-1][1].to_f thisdata[-1][1] /= count.to_f ymin = thisdata[-1][1].to_f if thisdata[-1][1] && thisdata[-1][1].to_f < ymin ymax = thisdata[-1][1].to_f if thisdata[-1][1] && thisdata[-1][1].to_f > ymax end data << thisdata xmin = thisdata[0][0].to_i if thisdata[0] && thisdata[0][0].to_i < xmin xmax = thisdata[-1][0].to_i if thisdata[-1] && thisdata[-1][0].to_i > xmax end options[:axes] = { :yaxis => { :tickOptions => { :formatString =>'%.3f'}, :autoscale => true, :min => 0, :max => ymax + (ymax * 0.05), :label => 'Seconds', :labelRenderer => '$.jqplot.CanvasAxisLabelRenderer' }, :xaxis => { :autoscale => true, :renderer=>'$.jqplot.DateAxisRenderer', :tickOptions => {:formatString => '%m/%d/%y'}} } s['data'] = data options[:series] = series options[:cursor] = {:zoom => true, :showTooltip => true} s['options'] = options @sources << s end @graph_t = 'source' @data = [[[1,2],[3,4],[5,6]]].to_json erb :jqplot, :layout => false end def http_timing(params) @uri = 'timing/httptiming' #name,data,options @displayname = params['display_name'] names = ["GET","POST"] begin names = get_sources('all') #RhoconnectApi::list_sources(session[:server],session[:token],:all) rescue Exception => e puts "errror #{e.message}" end names << "ALL" @sources = [] names.each do |name| s = {} data = [] series = [] options = { :legend => { :show => true }, :title => name } s['name'] = name name = "*" if name == "ALL" keys = get_user_count("http:*:#{name}") #RhoconnectApi::stats(session[:server],session[:token], :names => "http:*:#{name}") xmin = 9999999999999999 xmax = -1 ymin = 9999999999999999 ymax = -1 keys.each do |key| method = key.gsub(/http:.*?:/,"") method.gsub!(/:.*/,"") unless name == "*" series << {:showLabel => true, :label => method } range = get_user_count(nil,key,0,-1) #RhoconnectApi::stats(session[:server],session[:token], {:metric => key, :start => 0, :finish => -1}) thisdata = [] range.each do |value| count = value.split(',')[0] value.gsub!(/.*,/,"") thisdata << value.split(":").reverse thisdata[-1][0] = thisdata[-1][0].to_i * 1000 thisdata[-1][1] = thisdata[-1][1].to_f thisdata[-1][1] /= count.to_f ymin = thisdata[-1][1].to_f if thisdata[-1][1] && thisdata[-1][1].to_f < ymin ymax = thisdata[-1][1].to_f if thisdata[-1][1] && thisdata[-1][1].to_f > ymax end data << thisdata xmin = thisdata[0][0].to_i if thisdata[0] && thisdata[0][0].to_i < xmin xmax = thisdata[-1][0].to_i if thisdata[-1] && thisdata[-1][0].to_i > xmax end options[:axes] = { :yaxis => { :tickOptions => { :formatString =>'%.3f'}, :autoscale => true, :min => 0, :max => ymax + (ymax * 0.05), :label => 'Seconds', :labelRenderer => '$.jqplot.CanvasAxisLabelRenderer' }, :xaxis => { :autoscale => true, :renderer=>'$.jqplot.DateAxisRenderer', :tickOptions => {:formatString => '%m/%d/%y'}} } s['data'] = data options[:series] = series options[:cursor] = {:zoom => true, :showTooltip => true} s['options'] = options @sources << s end @graph_t = 'http' @data = [[[1,2],[3,4],[5,6]]].to_json erb :jqplot, :layout => false end def count_graph(uri,title,name,metric) start = 0 finish = -1 now = Time.now.to_i format = "%m/%d/%y" thisdata = [] series = [] series << options = { :legend => { :show => false }, :title => title } @sources = [] s = {} usercount = [] usercount = get_user_count(nil,metric,start,finish) usercount.each do |count| user,timestamp = count.split(':') user = user.to_i timestamp = timestamp.to_i * 1000 thisdata << [timestamp,user] end options[:axes] = { :xaxis => { :autoscale => true, :renderer=>'$.jqplot.DateAxisRenderer', :tickOptions => {:formatString => format}}, :yaxis => {:label => name, :labelRenderer => '$.jqplot.CanvasAxisLabelRenderer'} } options[:cursor] = {:zoom => true, :showTooltip => true} s['name'] = name s['data'] = [thisdata] s['options'] = options @sources << s erb :jqplot, :layout => false end def get_user_count(name=nil,metric_p=nil,start=nil,finish=nil) begin if Rhoconnect.stats == true names = name if names Rhoconnect::Stats::Record.keys(names) else metric = metric_p rtype = Rhoconnect::Stats::Record.rtype(metric) if rtype == 'zset' # returns [] if no results Rhoconnect::Stats::Record.range(metric,start,finish) elsif rtype == 'string' Rhoconnect::Stats::Record.get_value(metric) || '' else raise ApiException.new(404, "Unknown metric") end end else raise ApiException.new(500, "Stats not enabled") end rescue Exception => e puts "error #{e.message} -- #{metric}" usercount = ["0:#{Time.now.to_i}"] end end def get_sources(partition_type) sources = App.load(APP_NAME).sources puts "sources is -- #{sources}" if partition_type.nil? or partition_type == 'all' sources else res = [] sources.each do |name| s = Source.load(name,{:app_id => APP_NAME,:user_id => '*'}) if s.partition_type and s.partition_type == partition_type.to_sym res << name end end res end end end