lib/rhoconnect/graph_helper.rb in rhoconnect-3.3.1.beta4 vs lib/rhoconnect/graph_helper.rb in rhoconnect-3.3.1
- old
+ new
@@ -1,37 +1,41 @@
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
+ # begin
+ # names = get_sources('all')
+ # rescue Exception => e
+ # puts "errror #{e.message}"
+ # end
+ names = [params['display_name']]
@sources = []
names.each do |name|
s = {}
data = []
series = []
options = { :legend => { :show => true }, :title => name }
s['name'] = name
+ s['data'] = []
- keys = get_user_count("source:*:#{name}") #RhoconnectApi::stats(session[:server],session[:token], :names => "source:*:#{name}")
-
+ @keys = get_user_count("source:*:#{name}")
+ @keyname = params['key'] || @keys.first
+
xmin = 9999999999999999
xmax = -1
ymin = 9999999999999999
ymax = -1
- keys.each do |key|
- method = key.gsub(/source:/,"").gsub(/:.*/,"")
+
+ if @keyname
+ method = @keyname.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})
+
+ range = get_user_count(nil,@keyname,0,-1)
thisdata = []
range.each do |value|
count = value.split(',')[0]
value.gsub!(/.*,/,"")
thisdata << value.split(":").reverse
@@ -44,103 +48,182 @@
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'}}
- }
+ 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['data'] = data
+ options[:series] = series
+ options[:cursor] = {:zoom => true, :showTooltip => true}
- s['options'] = options
-
+ s['options'] = options
+ end
+
@sources << s
end
@graph_t = 'source'
@data = [[[1,2],[3,4],[5,6]]].to_json
erb :jqplot, :layout => false
- end
+ end
- def http_timing(params)
- @uri = 'timing/httptiming'
+ def http_timing_key(params)
+ @uri = 'timing/httptiming'
+
+ #name,data,options
+ @displayname = params['display_name']
+ #names = ["GET","POST"]
+ # begin
+ # names = get_sources('all')
+ # rescue Exception => e
+ # puts "errror #{e.message}"
+ # end
+ @sources = []
+ name = key = params['display_name']
+
+ s = {}
+ data = []
+ series = []
+ options = { :legend => { :show => true, :location => 'ne' }, :title => name }
+ s['name'] = name
+
+ xmin = 9999999999999999
+ xmax = -1
+ ymin = 9999999999999999
+ ymax = -1
+
+ method = key.gsub(/http:.*?:/,"")
+ #method.gsub!(/:.*/,"")
+ series << {:showLabel => true, :label => method}
+ range = get_user_count(nil,key,0,-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
- #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 = []
+ 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
- names.each do |name|
- s = {}
- data = []
- series = []
- options = { :legend => { :show => true }, :title => name }
- s['name'] = name
+ 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
- name = "*" if name == "ALL"
- keys = get_user_count("http:*:#{name}") #RhoconnectApi::stats(session[:server],session[:token], :names => "http:*:#{name}")
+
+ 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
+
+ @graph_t = 'http'
+ @data = [[[1,2],[3,4],[5,6]]].to_json
+ erb :jqplot, :layout => false
+ end
+
+ def http_timing(params)
+ @uri = 'timing/httptiming'
- 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
+ #name,data,options
+
+ @displayname = params['display_name']
+ names = ["GET","POST"]
+
+ @sources = []
+ names = [params['display_name']]
- 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
+ names.each do |name|
+ s = {}
+ data = []
+ series = []
+ options = { :legend => { :show => true, :location => 'ne' }, :title => name }
+ s['name'] = name
- 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
+ name = "*" if name == "ALL"
+ keys = get_user_count("http:*:#{name}")
+ xmin = 9999999999999999
+ xmax = -1
+ ymin = 9999999999999999
+ ymax = -1
+ keys.each_with_index do |key,index|
+ method = key.gsub(/http:.*?:/,"")
+ method.gsub!(/:.*/,"") unless name == "*"
+ series << {:showLabel => true, :label => method}
- 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'}}
- }
+ range = get_user_count(nil,key,0,-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
- s['data'] = data
- options[:series] = series
- options[:cursor] = {:zoom => true, :showTooltip => true}
+ 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
- s['options'] = options
-
- @sources << s
+ 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
- @graph_t = 'http'
- @data = [[[1,2],[3,4],[5,6]]].to_json
- erb :jqplot, :layout => false
+
+ 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 get_http_routes()
+ keys = get_user_count("http:*:*")
+ method = key.gsub(/http:.*?:/,"")
+ #sources = get_sources('all')
+
+ #loop through arrays and remove any regex matches
+ # keysf = keys.inject([]) do |keys_final, element|
+ # found = true
+ # sources.each do |s|
+ # found = false if element.match(s)
+ # end
+ # keys_final << element.strip if found
+ # keys_final
+ # end
+
+ end
+
def count_graph(uri,title,name,metric)
start = 0
finish = -1
now = Time.now.to_i
format = "%m/%d/%y"
@@ -176,17 +259,17 @@
@sources << s
erb :jqplot, :layout => false
end
def get_user_count(name=nil,metric_p=nil,start=nil,finish=nil)
- begin
+ begin
if Rhoconnect.stats == true
names = name
if names
Rhoconnect::Stats::Record.keys(names)
else
- metric = metric_p
+ metric = metric_p.strip
rtype = Rhoconnect::Stats::Record.rtype(metric)
if rtype == 'zset'
# returns [] if no results
Rhoconnect::Stats::Record.range(metric,start,finish)
elsif rtype == 'string'
@@ -196,13 +279,12 @@
end
end
else
raise ApiException.new(500, "Stats not enabled")
end
- rescue Exception => e
- puts "error #{e.message} -- #{metric}"
+ rescue Exception => e
usercount = ["0:#{Time.now.to_i}"]
- end
+ end
end
def get_sources(partition_type)
# app.sources returns reference
# so we need to make a copy
\ No newline at end of file