Skip to content

Commit

Permalink
Hide timeseries table views if step is too small
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuele-f committed Dec 22, 2018
1 parent e7503c7 commit 8d1a268
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 9 deletions.
77 changes: 72 additions & 5 deletions httpdocs/js/graph_utils.js
Expand Up @@ -306,7 +306,7 @@ function hideQuerySlow() {
}

// add a new updateStackedChart function
function attachStackedChartCallback(chart, schema_name, chart_id, zoom_reset_id, params, step, align_step, show_all_smooth, initial_range) {
function attachStackedChartCallback(chart, schema_name, chart_id, zoom_reset_id, params, step, align_step, show_all_smooth, initial_range, ts_table_shown) {
var pending_chart_request = null;
var pending_table_request = null;
var d3_sel = d3.select(chart_id);
Expand Down Expand Up @@ -458,7 +458,7 @@ function attachStackedChartCallback(chart, schema_name, chart_id, zoom_reset_id,

function checkQueryCompleted() {
var flows_dt = $("#chart1-flows");
var wait_num_queries = flows_dt.data("datatable") ? 2 : 1;
var wait_num_queries = (ts_table_shown && ($("#chart1-flows").css("display") !== "none")) ? 2 : 1;

query_completed += 1;

Expand Down Expand Up @@ -856,10 +856,12 @@ function attachStackedChartCallback(chart, schema_name, chart_id, zoom_reset_id,
var flows_dt = $("#chart1-flows");

/* Reload datatable */
if(flows_dt.data("datatable")) {
if(ts_table_shown) {
/* note: flows_dt.data("datatable") will change after this call */
updateGraphsTableView(null, params);
pending_table_request = flows_dt.data("datatable").pendingRequest;

if($("#chart1-flows").css("display") !== "none")
pending_table_request = flows_dt.data("datatable").pendingRequest;
}
}

Expand Down Expand Up @@ -889,9 +891,74 @@ function tsQueryToTags(ts_query) {
}, {});
}

/* Hide or show the timeseries table items based on the current time range */
function recheckGraphTableEntries() {
var table_view = graph_table_views;
var tdiff = (graph_params.epoch_end - graph_params.epoch_begin);
var reset_selection = false;
$("#chart1-flows").show();
$("#graphs-table-selector").show();

for(view_id in table_view) {
var view = table_view[view_id];
var elem = $("#" + view.html_id);

if(tdiff <= view.min_step) {
if(graph_old_view.id === view_id)
reset_selection = true;

elem.hide();
} else
elem.show();
}

/* Hide/show the headers */
var items_ul = $("#graphs-table-active-view").closest(".btn-group").find("ul:first");

items_ul.find("li.dropdown-header").each(function(idx,e) {
var next_item = $(e).nextAll("li").filter(function(idx,e) {
return(($(e).css("display") !== "none") || (!$(e).attr("data-view-id")));
}).first();
var divider = $(e).nextAll(".divider").first();

if(!next_item.attr("data-view-id")) {
$(e).hide();
divider.hide();
} else {
$(e).show();
divider.show();
}
});

if(reset_selection) {
/* Select the first available view */
var first_view = items_ul.find("li[data-view-id]").filter(function(idx,e) {
return($(e).css("display") !== "none");
}).first();

if(first_view.length)
setActiveGraphsTableView(first_view.attr("data-view-id"));
else {
$("#chart1-flows").hide();
$("#graphs-table-selector").hide();
}

return false;
}

return true;
}

function updateGraphsTableView(view, graph_params, has_nindex, nindex_query, per_page) {
if(view) {
if(view)
graph_old_view = view;

if(!recheckGraphTableEntries(graph_params)) {
/* handled by setActiveGraphsTableView */
return;
}

if(view) {
graph_old_has_nindex = has_nindex;
graph_old_nindex_query = nindex_query;
} else {
Expand Down
2 changes: 1 addition & 1 deletion httpdocs/js/ntop.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion httpdocs/js/ntop.min.js.map

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion scripts/lua/modules/timeseries/schemas/ts_5min.lua
Expand Up @@ -168,7 +168,6 @@ schema:addMetric("as_server")

-- ##############################################

-- NOTE: not shown
schema = ts_utils.newSchema("host:l4protos", {step=300})
schema:addTag("ifid")
schema:addTag("host")
Expand All @@ -192,3 +191,12 @@ schema:addTag("ifid")
schema:addTag("host")
schema:addTag("category")
schema:addMetric("bytes")

-- ##############################################

-- NOTE: these are "virtual" schema, they do not correspond to actual timeseries
schema = ts_utils.newSchema("local_senders", {step=300})
schema:addTag("ifid")

schema = ts_utils.newSchema("local_receivers", {step=300})
schema:addTag("ifid")
2 changes: 1 addition & 1 deletion scripts/lua/modules/timeseries/ts_utils_core.lua
Expand Up @@ -52,7 +52,7 @@ function ts_utils.getSchema(name)
local schema = loaded_schemas[name]

if schema and ts_utils.hasHighResolutionTs() then
if((schema.options.step == 300) and (not starts(schema.name, "snmp"))) then
if((schema.options.step == 300) and (not starts(schema.name, "snmp")) and (not starts(schema.name, "local_"))) then
schema.options.insertion_step = 60
schema.options.step = 60

Expand Down

0 comments on commit 8d1a268

Please sign in to comment.