- Graph the current query hits over the past 24 hours from current time.

This commit is contained in:
Jordan Sissel 2009-10-29 06:58:28 +00:00
parent 8af13cdef5
commit 1331382bac
3 changed files with 27 additions and 4 deletions

View file

@ -18,12 +18,13 @@ class Search < Application
Timeout.timeout(10) do
@hits, @results = $search.search(params)
@graphdata = _graphpoints
render
end
end
def graphpoints
provides :json
def _graphpoints
#provides :json
params[:log_type] = (params[:log_type] or "linux-syslog")
orig_query = params[:q]
@ -61,7 +62,7 @@ class Search < Application
@data[entry[:time].to_i * 1000] = entry[:hits]
end
@data = @data.to_a
render
end
return @data
end
end

View file

@ -4,9 +4,11 @@
<title>Fresh Merb App</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="/stylesheets/master.css" type="text/css" media="screen" charset="utf-8" />
<script src="/javascripts/flot/jquery.js"></script>
<script src="/javascripts/flot/jquery.flot.js"></script>
</head>
<body>
<%#= message[:notice] %>
<%= catch_content :for_layout %>
</body>
</html>
</html>

View file

@ -8,6 +8,8 @@
<% end =%>
<hr>
<div id="visual" style="width:850px;height:200px;"></div>
<h4>Results <%= params[:offset] %> - <%= params[:offset] + params[:limit] %> of <%= @hits %> for <%=h params[:q] %></h4>
<% if params[:offset] > 0 %>
<%= link_to "first", url(:controller => "search", :action => "query",
@ -39,3 +41,21 @@
<pre>
<%=h @results.sort_by { |r| r[0] == nil ? 0 : r[0] }.collect { |r| r[1] }.join("\n") %>
</pre>
<script id="source">
$(function () {
var graphdata = <%= @graphdata.to_json %>;
$.plot($("#visual"),
[
{ data: graphdata,
bars: {
show: true,
barWidth: 3600000,
}
}
],
{ xaxis: { mode: "time" } }
);
});
</script>