Module: GraphHelper
- Included in:
- RhoconnectConsole::Server
- Defined in:
- lib/rhoconnect/graph_helper.rb
Instance Method Summary collapse
- #average_data(data, ymin, ymax) ⇒ Object
- #count_graph(uri, title, name, metric) ⇒ Object
- #get_http_routes ⇒ Object
- #get_sources(partition_type) ⇒ Object
- #get_user_count(name = nil, metric_p = nil, start = nil, finish = nil) ⇒ Object
- #http_timing(params) ⇒ Object
- #http_timing_key(params) ⇒ Object
- #source_timing(params) ⇒ Object
Instance Method Details
#average_data(data, ymin, ymax) ⇒ Object
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/rhoconnect/graph_helper.rb', line 295 def average_data(data,ymin,ymax) data_buckets = {} data_count = {} data_result = [] days = false data.each do |d_arr| bucket = Time.at(d_arr.first[0]/1000) bucket_key = "#{bucket.year}-#{bucket.month}-#{bucket.day} #{bucket.hour}:0:0" if data_buckets.include? bucket_key data_buckets[bucket_key] += d_arr.first[1] data_count[bucket_key] += 1 else data_buckets[bucket_key] = d_arr.first[1] data_count[bucket_key] = 1 end ymin = d_arr.first[1].to_f if d_arr.first[1].to_f < ymin.to_f ymax = d_arr.first[1].to_f if d_arr.first[1].to_f > ymax.to_f end data_buckets.each do |index,value| average_val = value/data_count[index] data_result << [[Time.at(Time.parse(index).to_i),average_val.round(3)]] end unless data_buckets.size < 2 start_day = Time.parse(data_buckets.first.first) end_day = Time.parse(data_buckets.last.first) days = true if start_day.month != end_day.month and start_day.day != end_day.day end return data_result,ymin,ymax,days end |
#count_graph(uri, title, name, metric) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/rhoconnect/graph_helper.rb', line 211 def count_graph(uri,title,name,metric) start = 0 finish = -1 now = Time.now.to_i format = "%m/%d/%y" thisdata = [] series = [] series << = { :legend => { :show => false }, :title => title } @sources = [] s = {} usercount = [] usercount = get_user_count(nil,metric,start,finish) usercount.each do |count| user, = count.split(':') user = user.to_i = .to_i * 1000 thisdata << [,user] end [:axes] = { :xaxis => { :autoscale => true, :renderer=>'$.jqplot.DateAxisRenderer', :tickOptions => {:formatString => format}}, :yaxis => {:label => name, :labelRenderer => '$.jqplot.CanvasAxisLabelRenderer'} } [:cursor] = {:zoom => true, :showTooltip => true} [:seriesDefaults] = {:pointLabels => { :show=>true },:rendererOptions => {:smooth => true}} s['name'] = name s['data'] = [thisdata] s['options'] = @sources << s erb :jqplot, :layout => false end |
#get_http_routes ⇒ Object
202 203 204 205 206 207 208 209 |
# File 'lib/rhoconnect/graph_helper.rb', line 202 def get_http_routes() keys = get_user_count("http:*:*") keys.each do |k| client_id = k.split("/")[4] k.gsub!(client_id,"*") if client_id end keys.uniq end |
#get_sources(partition_type) ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/rhoconnect/graph_helper.rb', line 276 def get_sources(partition_type) # app.sources returns reference # so we need to make a copy # otherwise we will end up modifying the @@sources variable in App sources = App.load(APP_NAME).sources.clone 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 |
#get_user_count(name = nil, metric_p = nil, start = nil, finish = nil) ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/rhoconnect/graph_helper.rb', line 250 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.strip 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 usercount = ["0:#{Time.now.to_i}"] end end |
#http_timing(params) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/rhoconnect/graph_helper.rb', line 134 def http_timing(params) @uri = 'timing/httptiming' #name,data,options @displayname = params['display_name'] names = ["GET","POST"] @sources = [] names = [params['display_name']] names.each do |name| s = {} data = [] series = [] = { :legend => { :show => true, :location => 'ne' }, :title => name } s['name'] = name 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} 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 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 [: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 [:series] = series [:cursor] = {:zoom => true, :showTooltip => true} [:seriesDefaults] = {:rendererOptions => {:smooth => true}} s['options'] = @sources << s end @graph_t = 'http' @data = [[[1,2],[3,4],[5,6]]].to_json erb :jqplot, :layout => false end |
#http_timing_key(params) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rhoconnect/graph_helper.rb', line 71 def http_timing_key(params) @uri = 'timing/httptiming' #name,data,options @displayname = params['display_name'] @sources = [] name = key = params['display_name'] s = {} data = [] series = [] = { :legend => { :show => false }, :title => name } s['name'] = name xmin = 9999999999999999 xmax = -1 ymin = 9999999999999999 ymax = -1 keys = Rhoconnect::Stats::Record.keys(key) keys.each_with_index do |k,index| method = key.gsub(/http:.*?:/,"") #method.gsub!(/:.*/,"") unless name == "*" series << {:showLabel => true, :label => method, :showLine => false } range = get_user_count(nil,k,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 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 data_normalized,ymin,ymax,days = average_data(data,ymin,ymax) #puts "dn is ****************** #{data_normalized}" format_str = days ? "%m/%d%y" : "%H" label_time = days ? "Days" : "#{data_normalized.first.first[0].year}-#{data_normalized.first.first[0].month}-#{data_normalized.first.first[0].day} (Hours)" [:axes] = { :yaxis => { :tickOptions => { :formatString =>'%.3f'}, :autoscale => true, :min => 0, :max => ymax + (ymax * 0.05), :label => 'Seconds', :labelRenderer => '$.jqplot.CanvasAxisLabelRenderer' }, :xaxis => { :autoscale => true, :label => label_time, :renderer=>'$.jqplot.DateAxisRenderer', :tickOptions => {:formatString => format_str}} } s['data'] = data_normalized [:series] = series [:cursor] = {:zoom => true, :showTooltip => true, :show => true} [:seriesDefaults] = {:pointLabels => { :show=>true },:rendererOptions => {:smooth => true}} s['options'] = @sources << s erb :jqplot, :layout => false end |
#source_timing(params) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rhoconnect/graph_helper.rb', line 4 def source_timing(params) #name,data,options @displayname = params['display_name'] names = [] names = [params['display_name']] @sources = [] names.each do |name| s = {} data = [] series = [] = { :legend => { :show => true }, :title => name } s['name'] = name s['data'] = [] @keys = get_user_count("source:*:#{name}") @keyname = params['key'] || @keys.first xmin = 9999999999999999 xmax = -1 ymin = 9999999999999999 ymax = -1 if @keyname method = @keyname.gsub(/source:/,"").gsub(/:.*/,"") series << {:showLabel => true, :label => method } range = get_user_count(nil,@keyname,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 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 [: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 [:series] = series [:cursor] = {:zoom => true, :showTooltip => true} [:seriesDefaults] = {:pointLabels => { :show=>true }} s['options'] = end @sources << s end erb :jqplot, :layout => false end |