Class: Liteboard
- Inherits:
-
Object
- Object
- Liteboard
- Defined in:
- lib/litestack/liteboard/liteboard.rb
Constant Summary collapse
- @@resolutions =
{"minute" => [300, 12], "hour" => [3600, 24], "day" => [3600 * 24, 7], "week" => [3600 * 24 * 7, 53], "year" => [3600 * 24 * 365, 100]}
- @@res_mapping =
{"hour" => "minute", "day" => "hour", "week" => "day", "year" => "week"}
- @@templates =
{}
- @@app =
Hanami::Router.new do get "/", to: ->(env) do Liteboard.new(env).call(:index) end get "/topics/Litejob", to: ->(env) do Liteboard.new(env).call(:litejob) end get "/topics/Litecache", to: ->(env) do Liteboard.new(env).call(:litecache) end get "/topics/Litedb", to: ->(env) do Liteboard.new(env).call(:litedb) end get "/topics/Litecable", to: ->(env) do Liteboard.new(env).call(:litecable) end end
Class Method Summary collapse
Instance Method Summary collapse
- #after(body = nil) ⇒ Object
- #before ⇒ Object
- #call(method) ⇒ Object
- #compose_query(field) ⇒ Object
- #dir(field) ⇒ Object
- #encode(text) ⇒ Object
- #event_sort_url(field) ⇒ Object
- #format(float) ⇒ Object
- #index ⇒ Object
- #index_sort_url(field) ⇒ Object
- #index_url ⇒ Object
-
#initialize(env) ⇒ Liteboard
constructor
A new instance of Liteboard.
- #litecable ⇒ Object
- #litecache ⇒ Object
- #litedb ⇒ Object
- #litejob ⇒ Object
- #params(key) ⇒ Object
- #round(float) ⇒ Object
- #sorted?(field) ⇒ Boolean
- #topic_sort_url(field) ⇒ Object
- #topic_url(topic) ⇒ Object
Constructor Details
#initialize(env) ⇒ Liteboard
Returns a new instance of Liteboard.
36 37 38 39 40 41 |
# File 'lib/litestack/liteboard/liteboard.rb', line 36 def initialize(env) @env = env @params = @env["router.params"] @running = true @lm = Litemetric.instance end |
Class Method Details
.app ⇒ Object
401 402 403 |
# File 'lib/litestack/liteboard/liteboard.rb', line 401 def self.app @@app end |
Instance Method Details
#after(body = nil) ⇒ Object
53 54 55 |
# File 'lib/litestack/liteboard/liteboard.rb', line 53 def after(body = nil) [200, {"Cache-Control" => "no-cache"}, [body]] end |
#before ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/litestack/liteboard/liteboard.rb', line 57 def before @res = params(:res) || "day" @resolution = @@res_mapping[@res] if !@resolution @res = "day" @resolution = @@res_mapping[@res] end @step = @@resolutions[@resolution][0] @count = @@resolutions[@resolution][1] @order = params(:order) @order = nil if @order == "" @dir = params(:dir) @dir = "desc" if @dir.nil? || @dir == "" @dir = @dir.downcase @idir = if @dir == "asc" "desc" else "asc" end @search = params(:search) @search = nil if @search == "" @topics = @lm.topic_summaries(@resolution, @step * @count, @order, @dir, @search) end |
#call(method) ⇒ Object
47 48 49 50 51 |
# File 'lib/litestack/liteboard/liteboard.rb', line 47 def call(method) before res = send(method) after(res) end |
#compose_query(field) ⇒ Object
364 365 366 367 |
# File 'lib/litestack/liteboard/liteboard.rb', line 364 def compose_query(field) field.downcase! "res=#{@res}&order=#{field}&dir=#{(@order == field) ? @idir : @dir}&search=#{@search}" end |
#dir(field) ⇒ Object
373 374 375 376 377 378 379 380 381 382 |
# File 'lib/litestack/liteboard/liteboard.rb', line 373 def dir(field) if sorted?(field) if @dir == "asc" return "<span class='material-icons'>arrow_drop_up</span>" else return "<span class='material-icons'>arrow_drop_down</span>" end end " " end |
#encode(text) ⇒ Object
384 385 386 |
# File 'lib/litestack/liteboard/liteboard.rb', line 384 def encode(text) URI.encode_uri_component(text) end |
#event_sort_url(field) ⇒ Object
360 361 362 |
# File 'lib/litestack/liteboard/liteboard.rb', line 360 def event_sort_url(field) "/topics/#{encode(@topic)}/events/#{encode(@event)}?#{compose_query(field)}" end |
#format(float) ⇒ Object
393 394 395 396 397 398 399 |
# File 'lib/litestack/liteboard/liteboard.rb', line 393 def format(float) string = float.to_s whole, decimal = string.split(".") whole = whole.chars.reverse.each_slice(3).map(&:join).join(",").reverse whole = [whole, decimal].join(".") if decimal whole end |
#index ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/litestack/liteboard/liteboard.rb', line 81 def index @order ||= "topic" @topics.each do |topic| data_points = @lm.topic_data_points(@step, @count, @resolution, topic[0]) topic << data_points.collect { |r| [r[0], r[2] || 0] } end render :index end |
#index_sort_url(field) ⇒ Object
352 353 354 |
# File 'lib/litestack/liteboard/liteboard.rb', line 352 def index_sort_url(field) "/?#{compose_query(field)}" end |
#index_url ⇒ Object
344 345 346 |
# File 'lib/litestack/liteboard/liteboard.rb', line 344 def index_url "/?res=#{@res}&order=#{@order}&dir=#{@dir}&search=#{@search}" end |
#litecable ⇒ Object
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 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/litestack/liteboard/liteboard.rb', line 297 def litecable @order ||= "rcount" @topic = "Litecable" @events = @lm.events_summaries(@topic, @resolution, @order, @dir, @search, @step * @count) @events.each do |event| data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event["name"]) event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"] || 0] } end @subscription_count = begin @events.find { |t| t["name"] == "subscribe" }["rcount"] rescue 0 end @broadcast_count = begin @events.find { |t| t["name"] == "broadcast" }["rcount"] rescue 0 end @message_count = begin @events.find { |t| t["name"] == "message" }["rcount"] rescue 0 end @subscriptions_over_time = begin @events.find { |t| t["name"] == "subscribe" }["counts"] rescue [] end @broadcasts_over_time = begin @events.find { |t| t["name"] == "broadcast" }["counts"] rescue [] end @messages_over_time = begin @events.find { |t| t["name"] == "message" }["counts"] rescue [] end @messages_over_time = @messages_over_time.collect.with_index { |msg, i| [msg[0], @broadcasts_over_time[i][1], msg[1]] } @top_subscribed_channels = @lm.keys_summaries(@topic, "subscribe", @resolution, @order, @dir, @search, @step * @count).first(8) @top_messaged_channels = @lm.keys_summaries(@topic, "message", @resolution, @order, @dir, @search, @step * @count).first(8) render :litecable end |
#litecache ⇒ Object
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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/litestack/liteboard/liteboard.rb', line 90 def litecache @order ||= "rcount" @topic = "Litecache" @events = @lm.events_summaries(@topic, @resolution, @order, @dir, @search, @step * @count) @events.each do |event| data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event["name"]) event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"]] } event["values"] = data_points.collect { |r| [r["rtime"], r["ravg"]] } end @snapshot = read_snapshot(@topic) @size = begin @snapshot[0][:summary][:size] rescue 0 end @max_size = begin @snapshot[0][:summary][:max_size] rescue 0 end @full = begin (@size / @max_size) * 100 rescue 0 end @entries = begin @snapshot[0][:summary][:entries] rescue 0 end @gets = @events.find { |t| t["name"] == "get" } @sets = @events.find { |t| t["name"] == "set" } @reads = begin @gets["rcount"] rescue 0 end @writes = begin @sets["rcount"] rescue 0 end @hitrate = begin @gets["ravg"] rescue 0 end @hits = @reads * @hitrate @misses = @reads - @hits @reads_vs_writes = begin @gets["counts"].collect.with_index { |obj, i| obj.clone << @sets["counts"][i][1] } rescue [] end @hits_vs_misses = begin @gets["values"].collect.with_index { |obj, i| [obj[0], obj[1].to_f * @gets["counts"][i][1].to_f, (1 - obj[1].to_f) * @gets["counts"][i][1].to_f] } rescue [] end @top_reads = @lm.keys_summaries(@topic, "get", @resolution, @order, @dir, nil, @step * @count).first(8) @top_writes = @lm.keys_summaries(@topic, "set", @resolution, @order, @dir, nil, @step * @count).first(8) render :litecache end |
#litedb ⇒ Object
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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/litestack/liteboard/liteboard.rb', line 154 def litedb @order ||= "rcount" @topic = "Litedb" @events = @lm.events_summaries(@topic, @resolution, @order, @dir, @search, @step * @count) @events.each do |event| data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event["name"]) event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"] || 0] } event["values"] = data_points.collect { |r| [r["rtime"], r["rtotal"] || 0] } end @snapshot = read_snapshot(@topic) @size = begin @snapshot[0][:summary][:size] rescue 0 end @tables = begin @snapshot[0][:summary][:tables] rescue 0 end @indexes = begin @snapshot[0][:summary][:indexes] rescue 0 end @gets = @events.find { |t| t["name"] == "Read" } @sets = @events.find { |t| t["name"] == "Write" } @reads = begin @gets["rcount"] rescue 0 end @writes = begin @sets["rcount"] rescue 0 end @time = begin @gets["ravg"] rescue 0 end @reads_vs_writes = begin @gets["counts"].collect.with_index { |obj, i| obj.clone << @sets["counts"][i][1] } rescue [] end @reads_vs_writes_times = begin @gets["values"].collect.with_index { |obj, i| [obj[0], obj[1], @sets["values"][i][1].to_f] } rescue [] end @read_times = begin @gets["rtotal"] rescue 0 end @write_times = begin @sets["rtotal"] rescue 0 end @slowest = @lm.keys_summaries(@topic, "Read", @resolution, "ravg", "desc", nil, @step * @count).first(8) @slowest += @lm.keys_summaries(@topic, "Write", @resolution, "ravg", "desc", nil, @step * @count).first(8) @slowest = @slowest.sort_by { |a| a["ravg"] }.last(8).reverse @popular = @lm.keys_summaries(@topic, "Read", @resolution, "rtotal", "desc", nil, @step * @count).first(8) @popular += @lm.keys_summaries(@topic, "Write", @resolution, "rtotal", "desc", nil, @step * @count).first(8) @popular = @popular.sort_by { |a| a["rtotal"] }.last(8).reverse render :litedb end |
#litejob ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 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 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/litestack/liteboard/liteboard.rb', line 225 def litejob @order ||= "rcount" @topic = "Litejob" @events = @lm.events_summaries(@topic, @resolution, @order, @dir, @search, @step * @count) @events.each do |event| data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event["name"]) event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"] || 0] } event["values"] = data_points.collect { |r| [r["rtime"], r["rtotal"] || 0] } end @snapshot = read_snapshot(@topic) @size = begin @snapshot[0][:summary][:size] rescue 0 end @jobs = begin @snapshot[0][:summary][:jobs] rescue 0 end @queues = begin @snapshot[0][:queues] rescue {} end @processed_jobs = @events.find { |e| e["name"] == "perform" } @processed_count = begin @processed_jobs["rcount"] rescue 0 end @processing_time = begin @processed_jobs["rtotal"] rescue 0 end keys_summaries = @lm.keys_summaries(@topic, "perform", @resolution, "rcount", "desc", nil, @step * @count) @processed_count_by_queue = keys_summaries.collect { |r| [r["key"], r["rcount"]] } @processing_time_by_queue = keys_summaries.collect { |r| [r["key"], r["rtotal"]] } # .sort{|r1, r2| r1['rtotal'] > r2['rtotal'] } @processed_count_over_time = begin @events.find { |e| e["name"] == "perform" }["counts"] rescue [] end @processing_time_over_time = begin @events.find { |e| e["name"] == "perform" }["values"] rescue [] end @processed_count_over_time_by_queues = [] @processing_time_over_time_by_queues = [] keys = ["Time"] keys_summaries.each_with_index do |summary, i| key = summary["key"] keys << key data_points = @lm.key_data_points(@step, @count, @resolution, @topic, "perform", key) if i == 0 data_points.each do |dp| @processed_count_over_time_by_queues << [dp["rtime"]] @processing_time_over_time_by_queues << [dp["rtime"]] end end data_points.each_with_index do |dp, j| @processed_count_over_time_by_queues[j] << (dp["rcount"] || 0) @processing_time_over_time_by_queues[j] << (dp["rtotal"] || 0) end end @processed_count_over_time_by_queues.unshift(keys) @processing_time_over_time_by_queues.unshift(keys) render :litejob end |
#params(key) ⇒ Object
43 44 45 |
# File 'lib/litestack/liteboard/liteboard.rb', line 43 def params(key) URI.decode_uri_component(@params[key].to_s) end |
#round(float) ⇒ Object
388 389 390 391 |
# File 'lib/litestack/liteboard/liteboard.rb', line 388 def round(float) return 0 unless float.is_a? Numeric (float * 100).round.to_f / 100 end |
#sorted?(field) ⇒ Boolean
369 370 371 |
# File 'lib/litestack/liteboard/liteboard.rb', line 369 def sorted?(field) @order == field end |
#topic_sort_url(field) ⇒ Object
356 357 358 |
# File 'lib/litestack/liteboard/liteboard.rb', line 356 def topic_sort_url(field) "/topics/#{encode(@topic)}?#{compose_query(field)}" end |
#topic_url(topic) ⇒ Object
348 349 350 |
# File 'lib/litestack/liteboard/liteboard.rb', line 348 def topic_url(topic) "/topics/#{encode(topic)}?res=#{@res}&order=#{@order}&dir=#{@dir}&search=#{@search}" end |