postgres: add char format for itemid
This commit is contained in:
13
dist/datasource-zabbix/zabbixDBConnector.js
vendored
13
dist/datasource-zabbix/zabbixDBConnector.js
vendored
@@ -3,7 +3,7 @@
|
|||||||
System.register(['angular', 'lodash'], function (_export, _context) {
|
System.register(['angular', 'lodash'], function (_export, _context) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var angular, _, _createClass, DEFAULT_QUERY_LIMIT, HISTORY_TO_TABLE_MAP, TREND_TO_TABLE_MAP, consolidateByFunc, consolidateByTrendColumns, TEST_MYSQL_QUERY, TEST_POSTGRES_QUERY;
|
var angular, _, _createClass, DEFAULT_QUERY_LIMIT, HISTORY_TO_TABLE_MAP, TREND_TO_TABLE_MAP, consolidateByFunc, consolidateByTrendColumns, TEST_MYSQL_QUERY, itemid_format, TEST_POSTGRES_QUERY;
|
||||||
|
|
||||||
function _classCallCheck(instance, Constructor) {
|
function _classCallCheck(instance, Constructor) {
|
||||||
if (!(instance instanceof Constructor)) {
|
if (!(instance instanceof Constructor)) {
|
||||||
@@ -226,19 +226,15 @@ System.register(['angular', 'lodash'], function (_export, _context) {
|
|||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////
|
|
||||||
// PostgreSQL //
|
|
||||||
////////////////
|
|
||||||
|
|
||||||
function buildPostgresHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction) {
|
function buildPostgresHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction) {
|
||||||
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
|
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
|
||||||
var query = '\n SELECT DISTINCT to_char(itemid, \'FM9999999999999\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(value) OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, value\n ORDER BY time ASC\n ';
|
var query = '\n SELECT DISTINCT to_char(itemid, \'' + itemid_format + '\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(value) OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, value\n ORDER BY time ASC\n ';
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildPostgresTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn) {
|
function buildPostgresTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn) {
|
||||||
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
|
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
|
||||||
var query = '\n SELECT DISTINCT to_char(itemid, \'FM9999999999999\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(' + valueColumn + ') OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, ' + valueColumn + '\n ORDER BY time ASC\n ';
|
var query = '\n SELECT DISTINCT to_char(itemid, \'' + itemid_format + '\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(' + valueColumn + ') OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, ' + valueColumn + '\n ORDER BY time ASC\n ';
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +288,8 @@ System.register(['angular', 'lodash'], function (_export, _context) {
|
|||||||
'max': 'value_max'
|
'max': 'value_max'
|
||||||
};
|
};
|
||||||
angular.module('grafana.services').factory('ZabbixDBConnector', ZabbixDBConnectorFactory);TEST_MYSQL_QUERY = 'SELECT itemid AS metric, clock AS time_sec, value_avg AS value FROM trends_uint LIMIT 1';
|
angular.module('grafana.services').factory('ZabbixDBConnector', ZabbixDBConnectorFactory);TEST_MYSQL_QUERY = 'SELECT itemid AS metric, clock AS time_sec, value_avg AS value FROM trends_uint LIMIT 1';
|
||||||
TEST_POSTGRES_QUERY = '\n SELECT to_char(itemid, \'FM9999999999999\') AS metric, clock AS time, value_avg AS value\n FROM trends_uint LIMIT 1\n';
|
itemid_format = 'FM99999999999999999999';
|
||||||
|
TEST_POSTGRES_QUERY = '\n SELECT to_char(itemid, \'' + itemid_format + '\') AS metric, clock AS time, value_avg AS value\n FROM trends_uint LIMIT 1\n';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -270,16 +270,18 @@ var TEST_MYSQL_QUERY = 'SELECT itemid AS metric, clock AS time_sec, value_avg AS
|
|||||||
// PostgreSQL //
|
// PostgreSQL //
|
||||||
////////////////
|
////////////////
|
||||||
|
|
||||||
|
var itemid_format = 'FM99999999999999999999';
|
||||||
|
|
||||||
function buildPostgresHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction) {
|
function buildPostgresHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction) {
|
||||||
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
|
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
|
||||||
var query = '\n SELECT DISTINCT to_char(itemid, \'FM9999999999999\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(value) OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, value\n ORDER BY time ASC\n ';
|
var query = '\n SELECT DISTINCT to_char(itemid, \'' + itemid_format + '\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(value) OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, value\n ORDER BY time ASC\n ';
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildPostgresTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn) {
|
function buildPostgresTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn) {
|
||||||
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
|
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
|
||||||
var query = '\n SELECT DISTINCT to_char(itemid, \'FM9999999999999\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(' + valueColumn + ') OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, ' + valueColumn + '\n ORDER BY time ASC\n ';
|
var query = '\n SELECT DISTINCT to_char(itemid, \'' + itemid_format + '\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(' + valueColumn + ') OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, ' + valueColumn + '\n ORDER BY time ASC\n ';
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
var TEST_POSTGRES_QUERY = '\n SELECT to_char(itemid, \'FM9999999999999\') AS metric, clock AS time, value_avg AS value\n FROM trends_uint LIMIT 1\n';
|
var TEST_POSTGRES_QUERY = '\n SELECT to_char(itemid, \'' + itemid_format + '\') AS metric, clock AS time, value_avg AS value\n FROM trends_uint LIMIT 1\n';
|
||||||
|
|||||||
@@ -241,10 +241,12 @@ const TEST_MYSQL_QUERY = `SELECT itemid AS metric, clock AS time_sec, value_avg
|
|||||||
// PostgreSQL //
|
// PostgreSQL //
|
||||||
////////////////
|
////////////////
|
||||||
|
|
||||||
|
const itemid_format = 'FM99999999999999999999';
|
||||||
|
|
||||||
function buildPostgresHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction) {
|
function buildPostgresHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction) {
|
||||||
let time_expression = `clock / ${intervalSec} * ${intervalSec}`;
|
let time_expression = `clock / ${intervalSec} * ${intervalSec}`;
|
||||||
let query = `
|
let query = `
|
||||||
SELECT DISTINCT to_char(itemid, 'FM9999999999999') AS metric,
|
SELECT DISTINCT to_char(itemid, '${itemid_format}') AS metric,
|
||||||
${time_expression} AS time,
|
${time_expression} AS time,
|
||||||
${aggFunction}(value) OVER (PARTITION BY clock / ${intervalSec}) AS value
|
${aggFunction}(value) OVER (PARTITION BY clock / ${intervalSec}) AS value
|
||||||
FROM ${table}
|
FROM ${table}
|
||||||
@@ -259,7 +261,7 @@ function buildPostgresHistoryQuery(itemids, table, timeFrom, timeTill, intervalS
|
|||||||
function buildPostgresTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn) {
|
function buildPostgresTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn) {
|
||||||
let time_expression = `clock / ${intervalSec} * ${intervalSec}`;
|
let time_expression = `clock / ${intervalSec} * ${intervalSec}`;
|
||||||
let query = `
|
let query = `
|
||||||
SELECT DISTINCT to_char(itemid, 'FM9999999999999') AS metric,
|
SELECT DISTINCT to_char(itemid, '${itemid_format}') AS metric,
|
||||||
${time_expression} AS time,
|
${time_expression} AS time,
|
||||||
${aggFunction}(${valueColumn}) OVER (PARTITION BY clock / ${intervalSec}) AS value
|
${aggFunction}(${valueColumn}) OVER (PARTITION BY clock / ${intervalSec}) AS value
|
||||||
FROM ${table}
|
FROM ${table}
|
||||||
@@ -272,6 +274,6 @@ function buildPostgresTrendsQuery(itemids, table, timeFrom, timeTill, intervalSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
const TEST_POSTGRES_QUERY = `
|
const TEST_POSTGRES_QUERY = `
|
||||||
SELECT to_char(itemid, 'FM9999999999999') AS metric, clock AS time, value_avg AS value
|
SELECT to_char(itemid, '${itemid_format}') AS metric, clock AS time, value_avg AS value
|
||||||
FROM trends_uint LIMIT 1
|
FROM trends_uint LIMIT 1
|
||||||
`;
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user