Fix db connection query post processing
This commit is contained in:
@@ -154,7 +154,7 @@ export function seriesToDataFrame(timeseries, target: ZabbixMetricsQuery, valueM
|
||||
}
|
||||
|
||||
// Converts DataResponse to the format which backend works with (for data processing)
|
||||
export function dataResponseToTimeSeries(response: DataFrameJSON[], items) {
|
||||
export function dataResponseToTimeSeries(response: DataFrameJSON[], items, request) {
|
||||
const series = [];
|
||||
if (response.length === 0) {
|
||||
return [];
|
||||
@@ -181,7 +181,7 @@ export function dataResponseToTimeSeries(response: DataFrameJSON[], items) {
|
||||
const item = _.find(items, { 'itemid': itemid });
|
||||
|
||||
// Convert interval to nanoseconds in order to unmarshall it on the backend to time.Duration
|
||||
let interval = utils.parseItemInterval(item.delay) * 1000000;
|
||||
let interval = request.intervalMs * 1000000;
|
||||
if (interval === 0) {
|
||||
interval = null;
|
||||
}
|
||||
|
||||
@@ -3,29 +3,31 @@
|
||||
*/
|
||||
|
||||
function historyQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction) {
|
||||
const time_expression = `clock DIV ${intervalSec} * ${intervalSec}`;
|
||||
return `
|
||||
SELECT CAST(itemid AS CHAR) AS metric, MIN(clock) AS time_sec, ${aggFunction}(value) AS value
|
||||
SELECT CAST(itemid AS CHAR) AS metric, ${time_expression} AS time_sec, ${aggFunction}(value) AS value
|
||||
FROM ${table}
|
||||
WHERE itemid IN (${itemids})
|
||||
AND clock
|
||||
> ${timeFrom}
|
||||
AND clock
|
||||
< ${timeTill}
|
||||
GROUP BY (clock-${timeFrom}) DIV ${intervalSec}, metric
|
||||
GROUP BY ${time_expression}, metric
|
||||
ORDER BY time_sec ASC
|
||||
`;
|
||||
}
|
||||
|
||||
function trendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn) {
|
||||
const time_expression = `clock DIV ${intervalSec} * ${intervalSec}`;
|
||||
return `
|
||||
SELECT CAST(itemid AS CHAR) AS metric, MIN(clock) AS time_sec, ${aggFunction}(${valueColumn}) AS value
|
||||
SELECT CAST(itemid AS CHAR) AS metric, ${time_expression} AS time_sec, ${aggFunction}(${valueColumn}) AS value
|
||||
FROM ${table}
|
||||
WHERE itemid IN (${itemids})
|
||||
AND clock
|
||||
> ${timeFrom}
|
||||
AND clock
|
||||
< ${timeTill}
|
||||
GROUP BY (clock-${timeFrom}) DIV ${intervalSec}, metric
|
||||
GROUP BY ${time_expression}, metric
|
||||
ORDER BY time_sec ASC
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -456,24 +456,24 @@ export class Zabbix implements ZabbixConnector {
|
||||
});
|
||||
}
|
||||
|
||||
getHistoryTS(items, timeRange, options) {
|
||||
getHistoryTS(items, timeRange, request) {
|
||||
const [timeFrom, timeTo] = timeRange;
|
||||
if (this.enableDirectDBConnection) {
|
||||
return this.getHistoryDB(items, timeFrom, timeTo, options)
|
||||
.then(history => responseHandler.dataResponseToTimeSeries(history, items));
|
||||
return this.getHistoryDB(items, timeFrom, timeTo, request)
|
||||
.then(history => responseHandler.dataResponseToTimeSeries(history, items, request));
|
||||
} else {
|
||||
return this.zabbixAPI.getHistory(items, timeFrom, timeTo)
|
||||
.then(history => responseHandler.handleHistory(history, items));
|
||||
}
|
||||
}
|
||||
|
||||
getTrends(items, timeRange, options) {
|
||||
getTrends(items, timeRange, request) {
|
||||
const [timeFrom, timeTo] = timeRange;
|
||||
if (this.enableDirectDBConnection) {
|
||||
return this.getTrendsDB(items, timeFrom, timeTo, options)
|
||||
.then(history => responseHandler.dataResponseToTimeSeries(history, items));
|
||||
return this.getTrendsDB(items, timeFrom, timeTo, request)
|
||||
.then(history => responseHandler.dataResponseToTimeSeries(history, items, request));
|
||||
} else {
|
||||
const valueType = options.consolidateBy || options.valueType;
|
||||
const valueType = request.consolidateBy || request.valueType;
|
||||
return this.zabbixAPI.getTrend(items, timeFrom, timeTo)
|
||||
.then(history => responseHandler.handleTrends(history, items, valueType))
|
||||
.then(responseHandler.sortTimeseries); // Sort trend data, issue #202
|
||||
|
||||
Reference in New Issue
Block a user