Skip to content

Commit

Permalink
Resolved #11 - add scale filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Jun 20, 2015
1 parent 721d978 commit c4df472
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
18 changes: 14 additions & 4 deletions zabbix/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ function (angular, _, kbn) {

if ((from < useTrendsFrom) && self.trends) {
return self.getTrends(items, from, to)
.then(_.partial(self.handleTrendResponse, items));
.then(_.partial(self.handleTrendResponse, items, target.scale));
} else {
return self.performTimeSeriesQuery(items, from, to)
.then(_.partial(self.handleHistoryResponse, items));
.then(_.partial(self.handleHistoryResponse, items, target.scale));
}
}
});
Expand Down Expand Up @@ -190,7 +190,7 @@ function (angular, _, kbn) {
};


ZabbixAPIDatasource.prototype.handleTrendResponse = function(items, trends) {
ZabbixAPIDatasource.prototype.handleTrendResponse = function(items, scale, trends) {

// Group items and trends by itemid
var indexed_items = _.indexBy(items, 'itemid');
Expand All @@ -204,6 +204,11 @@ function (angular, _, kbn) {

// Value must be a number for properly work
var value = Number(p.value_avg);

// Apply scale
if (scale) {
value *= scale;
}
return [value, p.clock * 1000];
})
};
Expand All @@ -226,7 +231,7 @@ function (angular, _, kbn) {
* datapoints: [[<value>, <unixtime>], ...]
* }
*/
ZabbixAPIDatasource.prototype.handleHistoryResponse = function(items, history) {
ZabbixAPIDatasource.prototype.handleHistoryResponse = function(items, scale, history) {
/**
* Response should be in the format:
* data: [
Expand All @@ -253,6 +258,11 @@ function (angular, _, kbn) {

// Value must be a number for properly work
var value = Number(p.value);

// Apply scale
if (scale) {
value *= scale;
}
return [value, p.clock * 1000];
})
};
Expand Down
9 changes: 9 additions & 0 deletions zabbix/partials/query.editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@
placeholder="Item filter (regex)"
ng-blur="targetBlur()">
</li>
<!-- Scale -->
<li>
<input type="text"
class="tight-form-input input-small"
ng-model="target.scale"
spellcheck='false'
placeholder="Set scale"
ng-blur="targetBlur()">
</li>
</ul>

<div class="clearfix"></div>
Expand Down

0 comments on commit c4df472

Please sign in to comment.