-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Changes from 2 commits
d3fcebe
7aec256
91a342f
873a765
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
border: 0; | ||
|
||
.content { | ||
display: block; | ||
text-align: right; | ||
padding: 15px; | ||
padding-right: 20px; | ||
|
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)); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
}); | ||
|
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 }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are your thoughts on swapping this, creating |
||
|
||
const now = Date.now(); | ||
const secSinceLast = (now - lastReport) / 1000; | ||
lastReport = now; | ||
|
@@ -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]) | ||
}; | ||
} |
There was a problem hiding this comment.
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.