From 4bb8df19f68a8b8664201bac0482e26a8f8a66b2 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Tue, 30 Oct 2018 22:44:09 +0300 Subject: [PATCH] datasource: query performance logging --- src/datasource-zabbix/datasource.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/datasource-zabbix/datasource.js b/src/datasource-zabbix/datasource.js index 31b1eee..8133f18 100644 --- a/src/datasource-zabbix/datasource.js +++ b/src/datasource-zabbix/datasource.js @@ -1,4 +1,5 @@ import _ from 'lodash'; +import config from 'grafana/app/core/config'; import * as dateMath from 'grafana/app/core/utils/datemath'; import * as utils from './utils'; import * as migrations from './migrations'; @@ -18,6 +19,8 @@ export class ZabbixDatasource { this.templateSrv = templateSrv; this.zabbixAlertingSrv = zabbixAlertingSrv; + this.enableDebugLog = config.buildInfo.env === 'development'; + // Use custom format for template variables this.replaceTemplateVars = _.partial(replaceTemplateVars, this.templateSrv); @@ -165,11 +168,21 @@ export class ZabbixDatasource { * Query target data for Metrics mode */ queryNumericData(target, timeRange, useTrends, options) { + let queryStart, queryEnd; let getItemOptions = { itemtype: 'num' }; return this.zabbix.getItemsFromTarget(target, getItemOptions) - .then(items => this.queryNumericDataForItems(items, target, timeRange, useTrends, options)); + .then(items => { + queryStart = new Date().getTime(); + return this.queryNumericDataForItems(items, target, timeRange, useTrends, options); + }).then(result => { + queryEnd = new Date().getTime(); + if (this.enableDebugLog) { + console.log(`Datasource::Performance Query Time (${this.name}): ${queryEnd - queryStart}`); + } + return result; + }); } /**