Browse Source

[WebUI] Use common query functions to get graph data

tags/1.7.9
Alexander Moisseev 5 years ago
parent
commit
0185cb2c82
2 changed files with 49 additions and 63 deletions
  1. 48
    62
      interface/js/app/graph.js
  2. 1
    1
      interface/js/app/stats.js

+ 48
- 62
interface/js/app/graph.js View File

@@ -212,72 +212,58 @@ define(["jquery", "d3evolution", "footable"],
graphs.graph = initGraph();
}

if (checked_server === "All SERVERS") {
rspamd.queryNeighbours("graph", function (req_data) {
var neighbours_data = req_data
.filter(function (d) { return d.status; }) // filter out unavailable neighbours
.map(function (d) { return d.data; });
(function (callback) {
callback("graph",
function (req_data) {
if (checked_server !== "All SERVERS") {
updateWidgets(req_data);
return;
}

if (neighbours_data.length > 1) {
neighbours_data.reduce(function (res, curr) {
if ((curr[0][0].x !== res[0][0].x) ||
(curr[0][curr[0].length - 1].x !== res[0][res[0].length - 1].x)) {
rspamd.alertMessage("alert-error",
"Neighbours time extents do not match. Check if time is synchronized on all servers.");
updateWidgets();
return;
}
var neighbours_data = req_data
.filter(function (d) { return d.status; }) // filter out unavailable neighbours
.map(function (d) { return d.data; });

var data = [];
curr.forEach(function (action, j) {
data.push(
action.map(function (d, i) {
return {
x: d.x,
y: ((res[j][i].y === null) ? d.y : res[j][i].y + d.y)
};
})
);
});
updateWidgets(data);
});
} else {
updateWidgets(neighbours_data[0]);
}
},
function (serv, jqXHR, textStatus, errorThrown) {
var alert_status = serv.name + "_alerted";
if (neighbours_data.length > 1) {
neighbours_data.reduce(function (res, curr) {
if ((curr[0][0].x !== res[0][0].x) ||
(curr[0][curr[0].length - 1].x !== res[0][res[0].length - 1].x)) {
rspamd.alertMessage("alert-error",
"Neighbours time extents do not match. Check if time is synchronized on all servers.");
updateWidgets();
return;
}

if (!(alert_status in sessionStorage)) {
sessionStorage.setItem(alert_status, true);
rspamd.alertMessage("alert-error", "Cannot receive RRD data from: " +
serv.name + ", error: " + errorThrown);
}
}, "GET", {}, {}, {
type: type
});
return;
}
var data = [];
curr.forEach(function (action, j) {
data.push(
action.map(function (d, i) {
return {
x: d.x,
y: ((res[j][i].y === null) ? d.y : res[j][i].y + d.y)
};
})
);
});
updateWidgets(data);
});
} else {
updateWidgets(neighbours_data[0]);
}
},
function (serv, jqXHR, textStatus, errorThrown) {
var serv_name = (typeof serv === "string") ? serv : serv.name;
var alert_status = "alerted_graph_" + serv_name;

$.ajax({
dataType: "json",
type: "GET",
url: neighbours[checked_server].url + "graph",
jsonp: false,
data: {
type: type
},
beforeSend: function (xhr) {
xhr.setRequestHeader("Password", rspamd.getPassword());
},
success: function (data) {
updateWidgets(data);
},
error: function (jqXHR, textStatus, errorThrown) {
rspamd.alertMessage("alert-error", "Cannot receive throughput data: " +
textStatus + " " + jqXHR.status + " " + errorThrown);
}
});
if (!(alert_status in sessionStorage)) {
sessionStorage.setItem(alert_status, true);
rspamd.alertMessage("alert-error", "Cannot receive throughput data from " +
serv_name + ", error: " + errorThrown);
}
},
"GET", {}, {}, {type: type}
);
}((checked_server === "All SERVERS") ? rspamd.queryNeighbours : rspamd.queryLocal));
};

ui.setup = function () {

+ 1
- 1
interface/js/app/stats.js View File

@@ -220,7 +220,7 @@ define(["jquery", "d3pie", "humanize"],
graphs.chart = getChart(rspamd, graphs.chart, checked_server);
},
function (serv, jqXHR, textStatus, errorThrown) {
var alert_status = serv.name + "_alerted";
var alert_status = "alerted_stats_" + serv.name;

if (!(alert_status in sessionStorage)) {
sessionStorage.setItem(alert_status, true);

Loading…
Cancel
Save