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 2 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),
v6Api: Joi.boolean().default(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should default this to 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 { getV6Metrics } 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 = getV6Metrics({
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));
});
});
29 changes: 24 additions & 5 deletions src/server/status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,40 @@ 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.v6Api');
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.v6Metrics
});
}

return reply({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return should be legacy format with without the nested version information. Metrics also needs to be of the legacy format.

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'),
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
});
Expand Down
40 changes: 37 additions & 3 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';

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

server.plugins['even-better'].monitor.on('ops', function (event) {
kbnServer.v6Metrics = getV6Metrics({ event, config });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on swapping this, creating kbnServer.legacyMetrics. Reason being is we are exposing the cgroup information via this interface.


const now = Date.now();
const secSinceLast = (now - lastReport) / 1000;
lastReport = now;
Expand All @@ -24,4 +27,35 @@ module.exports = function (kbnServer, server, config) {
});

});
};
}

export function getV6Metrics({ 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