mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
- Try to dynamically size the histogram based on number of data points
found. This will incur multiple backend queries if a happy range of data points is not found. Currently will try again with a new histogram interval if point count, x is outside range [6, 50]
This commit is contained in:
parent
6d98b64514
commit
ecb0afad5d
1 changed files with 43 additions and 13 deletions
|
@ -29,20 +29,50 @@
|
|||
|
||||
if (options.graph != false) {
|
||||
/* Load the default histogram graph */
|
||||
jQuery.getJSON("/api/histogram", logstash.params, function(histogram, text, jqxhr) {
|
||||
/* Load the data into the graph */
|
||||
flot_data = [];
|
||||
// histogram is an array of { "key": ..., "count": ... }
|
||||
for (var i in histogram) {
|
||||
flot_data.push([parseInt(histogram[i]["key"]), histogram[i]["count"]])
|
||||
}
|
||||
|
||||
logstash.plot(flot_data);
|
||||
});
|
||||
logstash.params.interval = 3600000; /* 1 hour, default */
|
||||
logstash.histogram();
|
||||
} /* if options.graph != false */
|
||||
$("#query").val(logstash.params.q);
|
||||
}, /* search */
|
||||
|
||||
histogram: function(tries) {
|
||||
if (typeof(tries) == 'undefined') {
|
||||
tries = 5;
|
||||
}
|
||||
|
||||
/* Uncomment to activate GeoCities mode on the graph while waiting . */
|
||||
$("#visual").html("<center><img src='/media/truckconstruction.gif'><center>");
|
||||
|
||||
jQuery.getJSON("/api/histogram", logstash.params, function(histogram, text, jqxhr) {
|
||||
/* Load the data into the graph */
|
||||
flot_data = [];
|
||||
// histogram is an array of { "key": ..., "count": ... }
|
||||
for (var i in histogram) {
|
||||
flot_data.push([parseInt(histogram[i]["key"]), histogram[i]["count"]])
|
||||
}
|
||||
//console.log("Histo:" + flot_data.length);
|
||||
|
||||
/* Try to be intelligent about how we choose the histogram interval.
|
||||
* If there are too few data points, try a smaller interval.
|
||||
* If there are too many data points, try a larger interval.
|
||||
* Give up after a few tries and go with the last result.
|
||||
*
|
||||
* This queries the backend several times, but should be reasonably
|
||||
* speedy as this behaves roughly as a binary search. */
|
||||
if (flot_data.length < 6 && tries > 0) {
|
||||
//console.log("Histogram bucket " + logstash.params.interval + " has only " + flot_data.length + " data points, trying smaller...");
|
||||
logstash.params.interval /= 2;
|
||||
logstash.histogram(tries - 1);
|
||||
} else if (flot_data.length > 50 && tries > 0) {
|
||||
//console.log("Histogram bucket " + logstash.params.interval + " too many (" + flot_data.length + ") data points, trying larger interval...");
|
||||
logstash.params.interval *= 2;
|
||||
logstash.histogram(tries - 1);
|
||||
} else {
|
||||
logstash.plot(flot_data, logstash.params.interval);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
parse_params: function(href) {
|
||||
var query = href.replace(/^[^?]*\?/, "");
|
||||
if (query == href) {
|
||||
|
@ -70,7 +100,7 @@
|
|||
logstash.search(newquery.trim());
|
||||
}, /* appendquery */
|
||||
|
||||
plot: function(data) {
|
||||
plot: function(data, interval) {
|
||||
var target = $("#visual");
|
||||
target.css("display", "block");
|
||||
var plot = $.plot(target,
|
||||
|
@ -78,7 +108,7 @@
|
|||
data: data,
|
||||
bars: {
|
||||
show: true,
|
||||
barWidth: 3600000,
|
||||
barWidth: interval,
|
||||
}
|
||||
} ],
|
||||
{ /* options */
|
||||
|
@ -90,7 +120,7 @@
|
|||
target.bind("plotclick", function(e, pos, item) {
|
||||
if (item) {
|
||||
start = logstash.ms_to_iso8601(item.datapoint[0]);
|
||||
end = logstash.ms_to_iso8601(item.datapoint[0] + 3600000);
|
||||
end = logstash.ms_to_iso8601(item.datapoint[0] + interval);
|
||||
|
||||
/* Clicking on the graph means a new search, means
|
||||
* we probably don't want to keep the old offset since
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue