Commit b82480a8 by Johannes Edmeier

Bugfix: fix missing metrics

fixes #479
parent e5754cb4
/* /*
* Copyright 2014 the original author or authors. * Copyright 2014-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
...@@ -17,121 +17,120 @@ ...@@ -17,121 +17,120 @@
module.exports = function ($scope, application) { module.exports = function ($scope, application) {
'ngInject'; 'ngInject';
var metricData = {'gauge': []};
var metricDataMax = {'gauge': 0};
$scope.showRichGauges = false; $scope.showRichGauges = false;
$scope.metrics = []; $scope.metrics = [];
application.getMetrics().then( function merge(array, obj) {
function (response) { for (var i = 0; i < array.length; i++) {
function merge(array, obj) { if (array[i].name === obj.name) {
for (var i = 0; i < array.length; i++) { for (var a in obj) {
if (array[i].name === obj.name) { if (obj.hasOwnProperty(a)) {
for (var a in obj) { array[i][a] = obj[a];
array[i][a] = obj[a];
}
return;
} }
} }
array.push(obj); return;
} }
}
array.push(obj);
}
var find = function (metrics, regexes, callbacks) { application.getMetrics().then(
for (var metric in metrics) { function (response) {
if(metrics.hasOwnProperty(metric)) { var metricData = {};
for (var i = 0; i < regexes.length; i++) {
var match = regexes[i].exec(metric);
if (match !== null) {
callbacks[i](metric, match, metrics[metric]);
break;
}
}
}
}
for (var key in metricData) { function addData(groupname, valueObj, max) {
if(metricData.hasOwnProperty(key)) { var group = metricData[groupname] || {max: 0, values: []};
$scope.metrics.push({ merge(group.values, valueObj);
name: key, if (typeof max !== 'undefined' && max > group.max) {
values: metricData[key], group.max = max;
max: metricDataMax[key] || 0
});
}
} }
}; metricData[groupname] = group;
}
var regexes = [/^(?!gauge)([a-zA-Z0-9]+)\..*/gi, /(gauge\..+)\.val/, /(gauge\..+)\.avg/, /(gauge\..+)\.min/, /(gauge\..+)\.max/, /(gauge\..+)\.count/, /(gauge\..+)\.alpha/, /(gauge\..+)/];
var callbacks = [
function (metric, match, value) {
if(typeof metricData[match[1]] === 'undefined'){
metricData[match[1]] = [];
}
if(typeof metricDataMax[match[1]] === 'undefined'){
metricDataMax[match[1]] = 0;
}
if (match.length >= 2 && match[1] !== null) {
metricData[match[1]].push({
name: metric,
value: value
});
if (value > metricDataMax[match[1]]) { var matchers = [{
metricDataMax[match[1]] = value; regex: /(gauge\..+)\.val/,
} callback: function (metric, match, value) {
} addData('gauge', {
},
function (metric, match, value) {
merge(metricData['gauge'], {
name: match[1], name: match[1],
value: value value: value
}); }, value);
$scope.showRichGauges = true; $scope.showRichGauges = true;
if (value > metricDataMax['gauge']) { }
metricDataMax['gauge'] = value; }, {
} regex: /(gauge\..+)\.avg/,
}, callback: function (metric, match, value) {
function (metric, match, value) { addData('gauge', {
merge(metricData['gauge'], {
name: match[1], name: match[1],
avg: value.toFixed(2) avg: value.toFixed(2)
}); });
}, }
function (metric, match, value) { }, {
merge(metricData['gauge'], { regex: /(gauge\..+)\.min/,
callback: function (metric, match, value) {
addData('gauge', {
name: match[1], name: match[1],
min: value min: value
}); });
}, }
function (metric, match, value) { }, {
merge(metricData['gauge'], { regex: /(gauge\..+)\.max/,
callback: function (metric, match, value) {
addData('gauge', {
name: match[1], name: match[1],
max: value max: value
}); }, value);
if (value > metricDataMax['gauge']) { }
metricDataMax['gauge'] = value; }, {
} regex: /(gauge\..+)\.count/,
}, callback: function (metric, match, value) {
function (metric, match, value) { addData('gauge', {
merge(metricData['gauge'], {
name: match[1], name: match[1],
count: value count: value
}); });
}, }
function () { /* NOP */ }, {
}, regex: /(gauge\..+)\.alpha/,
function (metric, match, value) { callback: function () { /* NOP */
merge(metricData['gauge'], { }
}, {
regex: /(gauge\..+)/,
callback: function (metric, match, value) {
addData('gauge', {
name: match[1], name: match[1],
value: value value: value
}); }, value);
if (value > metricDataMax['gauge']) { }
metricDataMax['gauge'] = value; }, {
} regex: /^([^.]+).*/,
}]; callback: function (metric, match, value) {
addData(match[1], {
name: metric,
value: value
}, value);
}
}];
find(response.data, regexes, callbacks); var metrics = response.data;
for (var metric in metrics) {
if (metrics.hasOwnProperty(metric)) {
for (var i = 0; i < matchers.length; i++) {
var match = matchers[i].regex.exec(metric);
if (match !== null) {
matchers[i].callback(metric, match, metrics[metric]);
break;
}
}
}
}
for (var groupname in metricData) {
if (metricData.hasOwnProperty(groupname)) {
$scope.metrics.push({
name: groupname,
values: metricData[groupname].values,
max: metricData[groupname].max || 0
});
}
}
} }
).catch(function (response) { ).catch(function (response) {
$scope.error = response.data; $scope.error = response.data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment