module Pencil::Helpers
Public Instance Methods
append_query_string(str)
click to toggle source
# File lib/pencil/helpers.rb, line 115 def append_query_string(str) v = str.dup (v << "?#{request.query_string}") unless request.query_string.empty? return v end
cluster_graph(g, cluster, title="wtf")
click to toggle source
# File lib/pencil/helpers.rb, line 18 def cluster_graph(g, cluster, title="wtf") image_url = \ @dash.render_cluster_graph(g, cluster, :title => title, :dynamic_url_opts => merge_opts) zoom_url = cluster_graph_link(@dash, g, cluster) return image_url, zoom_url end
cluster_graph_link(dash, g, cluster)
click to toggle source
# File lib/pencil/helpers.rb, line 27 def cluster_graph_link(dash, g, cluster) link = dash.graph_opts[g]["click"] || "/dash/#{cluster}/#{dash.name}/#{g.name}" return append_query_string(link) end
cluster_link(cluster)
click to toggle source
# File lib/pencil/helpers.rb, line 90 def cluster_link(cluster) return append_query_string("/dash/#{cluster}") end
cluster_selector()
click to toggle source
# File lib/pencil/helpers.rb, line 144 def cluster_selector @clusters = settings.config.clusters.sort + ["global"] erb :'partials/cluster_selector', :layout => false end
cluster_switcher(clusters)
click to toggle source
# File lib/pencil/helpers.rb, line 131 def cluster_switcher(clusters) @clusters = clusters erb :'partials/cluster_switcher', :layout => false end
cluster_zoom_graph(g, cluster, host, title)
click to toggle source
# File lib/pencil/helpers.rb, line 33 def cluster_zoom_graph(g, cluster, host, title) image_url = g.render_url([host.name], [cluster], :title => title, :dynamic_url_opts => merge_opts) zoom_url = cluster_zoom_link(cluster, host) return image_url, zoom_url end
cluster_zoom_link(cluster, host)
click to toggle source
# File lib/pencil/helpers.rb, line 40 def cluster_zoom_link(cluster, host) return append_query_string("/host/#{cluster}/#{host}") end
css_url()
click to toggle source
fixme this isn’t used anymore, but should
# File lib/pencil/helpers.rb, line 95 def css_url style = File.join(settings.root, "public/style.css") mtime = File.mtime(style).to_i.to_s return \ %Q[<link href="/style.css?#{mtime}" rel="stylesheet" type="text/css">] end
dash_link(dash, cluster)
click to toggle source
# File lib/pencil/helpers.rb, line 86 def dash_link(dash, cluster) return append_query_string("/dash/#{cluster}/#{dash.name}") end
dash_switcher()
click to toggle source
# File lib/pencil/helpers.rb, line 136 def dash_switcher erb :'partials/dash_switcher', :layout => false end
dash_uplink()
click to toggle source
# File lib/pencil/helpers.rb, line 159 def dash_uplink link = append_query_string(request.path.split("/")[0..-2].join("/")) "zoom out: <a href=\"#{link}\">#{@params[:cluster]}</a>" end
graph_switcher()
click to toggle source
# File lib/pencil/helpers.rb, line 140 def graph_switcher erb :'partials/graph_switcher', :layout => false end
graph_uplink()
click to toggle source
# File lib/pencil/helpers.rb, line 154 def graph_uplink link = append_query_string(request.path.split("/")[0..-2].join("/")) "zoom out: <a href=\"#{link}\">#{@dash}</a>" end
header(str)
click to toggle source
fixme this is a hack
# File lib/pencil/helpers.rb, line 165 def header(str) <<-FOO <div class="path_container"> <h2>#{@title}</h2> <span class="zoom"> #{str} </span> </div> <div id="timeslice_container"> <h3 id="timeslice">#{range_string}</h3> #{permalink unless @no_graphs} </div> FOO end
host_uplink()
click to toggle source
# File lib/pencil/helpers.rb, line 149 def host_uplink link = "/dash/#{append_query_string(@host.cluster)}" "zoom out: <a href=\"#{link}\">#{@host.cluster}</a>" end
hosts_selector(hosts, print_clusters=false)
click to toggle source
# File lib/pencil/helpers.rb, line 109 def hosts_selector(hosts, print_clusters=false) @print_clusters = print_clusters @hosts = hosts erb :'partials/hosts_selector', :layout => false end
input_boxes()
click to toggle source
generate the input box fields, filled in to current parameters if specified
# File lib/pencil/helpers.rb, line 81 def input_boxes @prefs = @@prefs erb :'partials/input_boxes', :layout => false end
merge_opts()
click to toggle source
# File lib/pencil/helpers.rb, line 121 def merge_opts static_opts = ["cluster", "dashboard", "zoom", "host", "session_id"] opts = params.dup session.merge(opts).delete_if { |k,v| static_opts.member?(k) || v.empty? } end
nowish()
click to toggle source
# File lib/pencil/helpers.rb, line 180 def nowish if settings.config.global_config[:now_threshold] == false return false end threshold = settings.config.global_config[:now_threshold] || 300 return @request_time.to_i - @etime.to_i < threshold end
param_lookup(name)
click to toggle source
convert keys to symbols before lookup
# File lib/pencil/helpers.rb, line 11 def param_lookup(name) sym_hash = {} session.each { |k,v| sym_hash[k.to_sym] = v unless v.empty? } params.each { |k,v| sym_hash[k.to_sym] = v unless v.empty? } settings.config.global_config[:url_opts].merge(sym_hash)[name.to_sym] end
permalink()
click to toggle source
# File lib/pencil/helpers.rb, line 206 def permalink return "" unless @stime && @duration format = "%F %T" # chronic REALLY understands this url = request.path + "?" url << "&start=#{@stime.strftime(format)}" url << "&duration=#{ChronicDuration.output(@duration)}" "<a id=\"permalink\" href=\"#{url}\">permalink</a>" end
range_string()
click to toggle source
# File lib/pencil/helpers.rb, line 188 def range_string format = settings.config.global_config[:date_format] || "%X %x" if @stime && @etime if nowish "timeslice: from #{@stime.strftime(format)}" else "timeslice: #{@stime.strftime(format)} - #{@etime.strftime(format)}" end else "invalid time range" end end
refresh()
click to toggle source
# File lib/pencil/helpers.rb, line 102 def refresh if settings.config.global_config[:refresh_rate] != false && nowish rate = settings.config.global_config[:refresh_rate] || 60 return %Q[<meta http-equiv="refresh" content="#{rate}">] end end
shortcuts(str)
click to toggle source
# File lib/pencil/helpers.rb, line 127 def shortcuts(str) @str = str erb :'partials/shortcuts', :layout => false end
suggest_cluster_links(clusters, g)
click to toggle source
# File lib/pencil/helpers.rb, line 44 def suggest_cluster_links(clusters, g) links = [] clusters.each do |c| href = append_query_string("/dash/#{c}/#{params[:dashboard]}/#{g.name}") links << "<a href=\"#{href}\">#{c}</a>" end return "zoom (" + links.join(", ") + ")" end
suggest_dashboards(host, graph)
click to toggle source
it’s mildly annoying that when this set is empty there’re no uplinks consider adding a link up to the cluster (which is best we can do)
# File lib/pencil/helpers.rb, line 67 def suggest_dashboards(host, graph) ret = Set.new host.graphs.each do |g| Dashboard.find_by_graph(g).each do |d| valid, _ = d.get_valid_hosts(g, host['cluster']) ret << d.name if valid.member?(host) end end return ret end
suggest_dashboards_links(host, graph)
click to toggle source
# File lib/pencil/helpers.rb, line 53 def suggest_dashboards_links(host, graph) suggested = suggest_dashboards(host, graph) return "" if suggested.length == 0 links = [] suggested.each do |d| links << "<a href=\"/dash/#{host.cluster}/#{append_query_string(d)}\">" + "#{d}</a>" end return "(" + links.join(", ") + ")" end
valid_time(s)
click to toggle source
# File lib/pencil/helpers.rb, line 202 def valid_time (s) Chronic.parse(s) || s =~ /^\d+$/ end