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");
* you may not use this file except in compliance with the License.
* 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
* distributed under the License is distributed on an "AS IS" BASIS,
......@@ -17,121 +17,120 @@
module.exports = function ($scope, application) {
'ngInject';
var metricData = {'gauge': []};
var metricDataMax = {'gauge': 0};
$scope.showRichGauges = false;
$scope.metrics = [];
application.getMetrics().then(
function (response) {
function merge(array, obj) {
for (var i = 0; i < array.length; i++) {
if (array[i].name === obj.name) {
for (var a in obj) {
array[i][a] = obj[a];
}
return;
function merge(array, obj) {
for (var i = 0; i < array.length; i++) {
if (array[i].name === obj.name) {
for (var a in obj) {
if (obj.hasOwnProperty(a)) {
array[i][a] = obj[a];
}
}
array.push(obj);
return;
}
}
array.push(obj);
}
var find = function (metrics, regexes, callbacks) {
for (var metric in metrics) {
if(metrics.hasOwnProperty(metric)) {
for (var i = 0; i < regexes.length; i++) {
var match = regexes[i].exec(metric);
if (match !== null) {
callbacks[i](metric, match, metrics[metric]);
break;
}
}
}
}
application.getMetrics().then(
function (response) {
var metricData = {};
for (var key in metricData) {
if(metricData.hasOwnProperty(key)) {
$scope.metrics.push({
name: key,
values: metricData[key],
max: metricDataMax[key] || 0
});
}
function addData(groupname, valueObj, max) {
var group = metricData[groupname] || {max: 0, values: []};
merge(group.values, valueObj);
if (typeof max !== 'undefined' && max > group.max) {
group.max = max;
}
};
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
});
metricData[groupname] = group;
}
if (value > metricDataMax[match[1]]) {
metricDataMax[match[1]] = value;
}
}
},
function (metric, match, value) {
merge(metricData['gauge'], {
var matchers = [{
regex: /(gauge\..+)\.val/,
callback: function (metric, match, value) {
addData('gauge', {
name: match[1],
value: value
});
}, value);
$scope.showRichGauges = true;
if (value > metricDataMax['gauge']) {
metricDataMax['gauge'] = value;
}
},
function (metric, match, value) {
merge(metricData['gauge'], {
}
}, {
regex: /(gauge\..+)\.avg/,
callback: function (metric, match, value) {
addData('gauge', {
name: match[1],
avg: value.toFixed(2)
});
},
function (metric, match, value) {
merge(metricData['gauge'], {
}
}, {
regex: /(gauge\..+)\.min/,
callback: function (metric, match, value) {
addData('gauge', {
name: match[1],
min: value
});
},
function (metric, match, value) {
merge(metricData['gauge'], {
}
}, {
regex: /(gauge\..+)\.max/,
callback: function (metric, match, value) {
addData('gauge', {
name: match[1],
max: value
});
if (value > metricDataMax['gauge']) {
metricDataMax['gauge'] = value;
}
},
function (metric, match, value) {
merge(metricData['gauge'], {
}, value);
}
}, {
regex: /(gauge\..+)\.count/,
callback: function (metric, match, value) {
addData('gauge', {
name: match[1],
count: value
});
},
function () { /* NOP */
},
function (metric, match, value) {
merge(metricData['gauge'], {
}
}, {
regex: /(gauge\..+)\.alpha/,
callback: function () { /* NOP */
}
}, {
regex: /(gauge\..+)/,
callback: function (metric, match, value) {
addData('gauge', {
name: match[1],
value: value
});
if (value > metricDataMax['gauge']) {
metricDataMax['gauge'] = value;
}
}];
}, 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) {
$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