Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x][status api] opt in to v6 metrics #10481

Merged
merged 4 commits into from
Feb 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/core_plugins/status_page/public/status_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,35 @@ const chrome = require('ui/chrome')
}

const data = resp.data;
ui.metrics = data.metrics;
const metrics = data.metrics;
const v6Timestamp = _.get(metrics, 'last_updated');
if (v6Timestamp) {
const timestamp = new Date(v6Timestamp).getTime();
ui.metrics = {
heapTotal: [
[timestamp, _.get(metrics, 'process.mem.heap_max_in_bytes')]
],
heapUsed: [
[timestamp, _.get(metrics, 'process.mem.heap_used_in_bytes')]
],
load: [[timestamp, [
_.get(metrics, 'os.cpu.load_average.1m'),
_.get(metrics, 'os.cpu.load_average.5m'),
_.get(metrics, 'os.cpu.load_average.15m')
]]],
responseTimeAvg: [
[timestamp, _.get(metrics, 'response_times.avg_in_millis')]
],
responseTimeMax: [
[timestamp, _.get(metrics, 'response_times.max_in_millis')]
],
requestsPerSecond: [
[timestamp, _.get(metrics, 'requests.total') * 1000 / _.get(metrics, 'collection_interval_in_millis')]
]
};
} else {
ui.metrics = data.metrics;
}
ui.name = data.name;

ui.statuses = data.status.statuses;
Expand Down
1 change: 1 addition & 0 deletions src/core_plugins/status_page/public/status_page.less
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
border: 0;

.content {
display: block;
text-align: right;
padding: 15px;
padding-right: 20px;
Expand Down
3 changes: 2 additions & 1 deletion src/server/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ module.exports = () => Joi.object({
}).default(),

status: Joi.object({
allowAnonymous: Joi.boolean().default(false)
allowAnonymous: Joi.boolean().default(false),
v6ApiFormat: Joi.boolean().default(false)
}).default(),
tilemap: Joi.object({
manifestServiceUrl: Joi.string().default('https://tiles.elastic.co/v2/manifest'),
Expand Down
56 changes: 56 additions & 0 deletions src/server/status/__tests__/metrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import _ from 'lodash';
import expect from 'expect.js';

import { getMetrics } from '../metrics';

describe('Metrics', function () {
const mockOps = {
'requests': { '5603': { 'total': 22, 'disconnects': 0, 'statusCodes': { '200': 22 } } },
'responseTimes': { '5603': { 'avg': 1.8636363636363635, 'max': 4 } },
'sockets': {
'http': { 'total': 0 },
'https': { 'total': 0 }
},
'osload': [2.20751953125, 2.02294921875, 1.89794921875],
'osmem': { 'total': 17179869184, 'free': 102318080 },
'osup': 1008991,
'psup': 7.168,
'psmem': { 'rss': 193716224, 'heapTotal': 168194048, 'heapUsed': 130553400 },
'concurrents': { '5603': 0 },
'psdelay': 1.6091690063476562,
'host': '123'
};
const config = {
ops: {
interval: 5000
},
server: {
port: 5603
}
};

let metrics;
beforeEach(() => {
metrics = getMetrics({
event: _.cloneDeep(mockOps),
config: {
get: path => _.get(config, path)
}
});
});

it('should snake case the request object', () => {
expect(metrics.requests.status_codes).not.to.be(undefined);
expect(metrics.requests.statusCodes).to.be(undefined);
});

it('should provide defined metrics', () => {
(function checkMetrics(currentMetric) {
_.forOwn(currentMetric, value => {
if (typeof value === 'object') return checkMetrics(value);
expect(currentMetric).not.to.be(undefined);
});

}(metrics));
});
});
22 changes: 19 additions & 3 deletions src/server/status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,39 @@ export default function (kbnServer, server, config) {
kbnServer.status = new ServerStatus(kbnServer.server);

if (server.plugins['even-better']) {
kbnServer.mixin(require('./metrics'));
kbnServer.mixin(require('./metrics').collectMetrics);
}

const wrapAuth = wrapAuthConfig(config.get('status.allowAnonymous'));

const matchSnapshot = /-SNAPSHOT$/;
server.route(wrapAuth({
method: 'GET',
path: '/api/status',
handler: function (request, reply) {
const v6Format = config.get('status.v6ApiFormat');
if (v6Format) {
return reply({
name: config.get('server.name'),
uuid: config.get('server.uuid'),
version: {
number: config.get('pkg.version').replace(matchSnapshot, ''),
build_hash: config.get('pkg.buildSha'),
build_number: config.get('pkg.buildNum'),
build_snapshot: matchSnapshot.test(config.get('pkg.version'))
},
status: kbnServer.status.toJSON(),
metrics: kbnServer.metrics
});
}

return reply({
name: config.get('server.name'),
version: config.get('pkg.version'),
buildNum: config.get('pkg.buildNum'),
buildSha: config.get('pkg.buildSha'),
uuid: config.get('server.uuid'),
status: kbnServer.status.toJSON(),
metrics: kbnServer.metrics
metrics: kbnServer.legacyMetrics
});
}
}));
Expand Down
44 changes: 39 additions & 5 deletions src/server/status/metrics.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import _ from 'lodash';
import Samples from './samples';
module.exports = function (kbnServer, server, config) {
let lastReport = Date.now();
import { keysToSnakeCaseShallow } from '../../utils/case_conversion';

kbnServer.metrics = new Samples(12);
export function collectMetrics(kbnServer, server, config) {
let lastReport = Date.now();
kbnServer.legacyMetrics = new Samples(12);

server.plugins['even-better'].monitor.on('ops', function (event) {
kbnServer.metrics = getMetrics({ event, config });

const now = Date.now();
const secSinceLast = (now - lastReport) / 1000;
lastReport = now;
Expand All @@ -14,7 +17,7 @@ module.exports = function (kbnServer, server, config) {
const requests = _.get(event, ['requests', port, 'total'], 0);
const requestsPerSecond = requests / secSinceLast;

kbnServer.metrics.add({
kbnServer.legacyMetrics.add({
heapTotal: _.get(event, 'psmem.heapTotal'),
heapUsed: _.get(event, 'psmem.heapUsed'),
load: event.osload,
Expand All @@ -24,4 +27,35 @@ module.exports = function (kbnServer, server, config) {
});

});
};
}

export function getMetrics({ event, config }) {
const port = config.get('server.port');
const timestamp = new Date().toISOString();
return {
last_updated: timestamp,
collection_interval_in_millis: config.get('ops.interval'),
uptime_in_millis: process.uptime() * 1000,
process: {
mem: {
heap_max_in_bytes: _.get(event, 'psmem.heapTotal'),
heap_used_in_bytes: _.get(event, 'psmem.heapUsed')
}
},
os: {
cpu: {
load_average: {
'1m': _.get(event, 'osload.0'),
'5m': _.get(event, 'osload.1'),
'15m': _.get(event, 'osload.2')
}
}
},
response_times: {
avg_in_millis: _.get(event, ['responseTimes', port, 'avg']),
max_in_millis: _.get(event, ['responseTimes', port, 'max'])
},
requests: keysToSnakeCaseShallow(_.get(event, ['requests', port])),
concurrent_connections: _.get(event, ['concurrents', port])
};
}
2 changes: 1 addition & 1 deletion src/ui/public/ingest/ingest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import RefreshKibanaIndexProvider from 'plugins/kibana/management/sections/indices/_refresh_kibana_index';
import { keysToCamelCaseShallow, keysToSnakeCaseShallow } from '../../../core_plugins/kibana/common/lib/case_conversion';
import { keysToCamelCaseShallow, keysToSnakeCaseShallow } from '../../../utils/case_conversion';
import _ from 'lodash';
import angular from 'angular';
import chrome from 'ui/chrome';
Expand Down