mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
fix status and devServer grunt tasks
This commit is contained in:
parent
b1e0344099
commit
91f0e125e8
15 changed files with 123 additions and 132 deletions
|
@ -3,12 +3,10 @@ var join = require('path').join;
|
|||
|
||||
var KbnServer = require('../server');
|
||||
|
||||
function run(grunt) {
|
||||
var opt = grunt ? _.bindKey(grunt, 'option') : _.noop;
|
||||
|
||||
function run(port, quiet) {
|
||||
return (new KbnServer({
|
||||
'logging.quiet': opt('debug') && opt('verbose'),
|
||||
'kibana.server.port': opt('port') || 5601,
|
||||
'logging.quiet': quiet,
|
||||
'kibana.server.port': port || 5601,
|
||||
'kibana.pluginPaths': [
|
||||
join(__dirname, 'dev_statics_plugin')
|
||||
],
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
module.exports = function (kibana) {
|
||||
var status = kibana.status;
|
||||
var Series = require('./lib/series');
|
||||
|
||||
return new kibana.Plugin({
|
||||
|
||||
init: function (server, options) {
|
||||
|
||||
var config = server.config();
|
||||
|
||||
var fiveMinuteData = {
|
||||
rss: new Series(60),
|
||||
heapTotal: new Series(60),
|
||||
heapUsed: new Series(60),
|
||||
load: new Series(60),
|
||||
delay: new Series(60),
|
||||
concurrency: new Series(60),
|
||||
responseTimeAvg: new Series(60),
|
||||
responseTimeMax: new Series(60),
|
||||
requests: new Series(60),
|
||||
};
|
||||
|
||||
server.plugins.good.monitor.on('ops', function (event) {
|
||||
var port = String(config.get('kibana.server.port'));
|
||||
fiveMinuteData.rss.push(event.psmem.rss);
|
||||
fiveMinuteData.heapTotal.push(event.psmem.heapTotal);
|
||||
fiveMinuteData.heapUsed.push(event.psmem.heapUsed);
|
||||
fiveMinuteData.load.push(event.osload);
|
||||
fiveMinuteData.delay.push(event.psdelay);
|
||||
fiveMinuteData.concurrency.push(parseInt(event.concurrents[port], 0));
|
||||
if (event.responseTimes[port]) {
|
||||
var responseTimeAvg = event.responseTimes[port].avg;
|
||||
if (isNaN(responseTimeAvg)) responseTimeAvg = 0;
|
||||
fiveMinuteData.responseTimeAvg.push(responseTimeAvg);
|
||||
fiveMinuteData.responseTimeMax.push(event.responseTimes[port].max);
|
||||
} else {
|
||||
fiveMinuteData.responseTimeAvg.push(0);
|
||||
fiveMinuteData.responseTimeMax.push(0);
|
||||
}
|
||||
if (event.requests[port]) {
|
||||
fiveMinuteData.requests.push(event.requests[port].total);
|
||||
} else {
|
||||
fiveMinuteData.requests.push(0);
|
||||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/status/health',
|
||||
handler: function (request, reply) {
|
||||
return reply({
|
||||
metrics: fiveMinuteData,
|
||||
status: status
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
};
|
|
@ -1,15 +0,0 @@
|
|||
function Series(size) {
|
||||
this.size = size;
|
||||
this.data = [];
|
||||
}
|
||||
|
||||
Series.prototype.push = function (value) {
|
||||
this.data.unshift([Date.now(), value]);
|
||||
if (this.data.length > this.size) this.data.pop();
|
||||
};
|
||||
|
||||
Series.prototype.toJSON = function () {
|
||||
return this.data;
|
||||
};
|
||||
|
||||
module.exports = Series;
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"name": "status",
|
||||
"version": "1.0.0"
|
||||
}
|
|
@ -52,46 +52,31 @@ module.exports = function (kibana) {
|
|||
}
|
||||
});
|
||||
|
||||
// initialize the browser runtime for the app
|
||||
server.route({
|
||||
path: '/app/{id}/{filePath*}',
|
||||
method: 'GET',
|
||||
handler: function (req, reply) {
|
||||
var id = req.params.id;
|
||||
var apps = server.getApps();
|
||||
// provide access to an app's public directories
|
||||
server.exposeStaticDir('/app/{id}/{path*}', function pickDir(req) {
|
||||
var id = req.params.id;
|
||||
var app = server.getApps()[id];
|
||||
|
||||
var app = apps[id];
|
||||
if (!app) return reply(Boom.notFound('Unkown app ' + id));
|
||||
|
||||
return reply.file(join(app.publicDir, req.params.filePath));
|
||||
}
|
||||
if (!app) return Boom.notFound('Unkown app ' + id);
|
||||
return app.publicDir || Boom.notFound(id + ' does not server public files');
|
||||
});
|
||||
|
||||
// expose the first bower_components directory found within kibana's rootDir starting
|
||||
// in this directory and moving out
|
||||
server.exposeStaticDir('/bower_components/{path*}', (function findBowerComponents() {
|
||||
var dir = __dirname;
|
||||
|
||||
server.route({
|
||||
path: '/bower_components/{path*}',
|
||||
method: 'GET',
|
||||
handler: {
|
||||
directory: {
|
||||
path: (function findBowerComponents() {
|
||||
// find bower_components by searching up until reaching the kibana dir
|
||||
var dir = __dirname;
|
||||
while (!exists(join(dir, 'bower_components'))) {
|
||||
var prev = dir;
|
||||
dir = join(dir, '..');
|
||||
|
||||
while (!exists(join(dir, 'bower_components'))) {
|
||||
var prev = dir;
|
||||
dir = join(dir, '..');
|
||||
|
||||
if (dir === prev || relative(kibana.rootDir, dir) === '..') {
|
||||
throw new Error('unable to find bower_components');
|
||||
}
|
||||
}
|
||||
|
||||
return join(dir, 'bower_components');
|
||||
}()),
|
||||
listing: true
|
||||
if (dir === prev || relative(kibana.rootDir, dir) === '..') {
|
||||
throw new Error('unable to find bower_components');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return join(dir, 'bower_components');
|
||||
}()));
|
||||
|
||||
|
||||
require('fs')
|
||||
|
|
|
@ -8,4 +8,25 @@ module.exports = function (kibana) {
|
|||
port: config.get('kibana.server.port')
|
||||
});
|
||||
|
||||
server.decorate('server', 'exposeStaticDir', function (routePath, dirPath) {
|
||||
this.route({
|
||||
path: routePath,
|
||||
method: 'GET',
|
||||
handler: {
|
||||
directory: {
|
||||
path: dirPath,
|
||||
listing: true,
|
||||
redirectToSlash: true,
|
||||
lookupCompressed: true
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
server.ext('onPreResponse', function (request, reply) {
|
||||
var response = request.response;
|
||||
response.header('X-App-Name', 'kibana');
|
||||
return reply.continue();
|
||||
});
|
||||
|
||||
};
|
||||
|
|
|
@ -13,10 +13,10 @@ function KbnServer(settings) {
|
|||
this.server = new Hapi.Server();
|
||||
this.settings = settings || {};
|
||||
this.ready = _.constant(this.mixin(
|
||||
require('./status'),
|
||||
require('./config'),
|
||||
require('./connections'),
|
||||
require('./logging'),
|
||||
require('./status'),
|
||||
require('./fe-exports'),
|
||||
require('./plugins')
|
||||
));
|
||||
|
@ -42,6 +42,7 @@ KbnServer.prototype.listen = function () {
|
|||
.then(
|
||||
function () {
|
||||
server.log('server', 'Server running at ' + server.info.uri);
|
||||
return server;
|
||||
},
|
||||
function (err) {
|
||||
server.log('fatal', err);
|
||||
|
|
26
src/server/status/Samples.js
Normal file
26
src/server/status/Samples.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
var _ = require('lodash');
|
||||
|
||||
function Samples(max) {
|
||||
this.vals = {};
|
||||
this.max = max || Infinity;
|
||||
this.length = 0;
|
||||
}
|
||||
|
||||
Samples.prototype.add = function (sample) {
|
||||
var vals = this.vals;
|
||||
var length = this.length = Math.min(this.length + 1, this.max);
|
||||
|
||||
_.forOwn(sample, function (val, name) {
|
||||
if (val == null) val = null;
|
||||
|
||||
if (!vals[name]) vals[name] = new Array(length);
|
||||
vals[name].unshift([Date.now(), val]);
|
||||
vals[name].length = length;
|
||||
});
|
||||
};
|
||||
|
||||
Samples.prototype.toJSON = function () {
|
||||
return this.vals;
|
||||
};
|
||||
|
||||
module.exports = Samples;
|
|
@ -1,5 +1,42 @@
|
|||
var KbnStatus = require('./KbnStatus');
|
||||
|
||||
module.exports = function (kibana) {
|
||||
var _ = require('lodash');
|
||||
var Samples = require('./Samples');
|
||||
var KbnStatus = require('./KbnStatus');
|
||||
var join = require('path').join;
|
||||
|
||||
var server = kibana.server;
|
||||
var config = server.config();
|
||||
|
||||
kibana.status = new KbnStatus(kibana.server);
|
||||
kibana.metrics = new Samples(60);
|
||||
|
||||
server.exposeStaticDir('/status/{path*}', join(__dirname, 'public'));
|
||||
|
||||
server.plugins.good.monitor.on('ops', function (event) {
|
||||
var port = config.get('kibana.server.port');
|
||||
|
||||
kibana.metrics.add({
|
||||
rss: event.psmem.rss,
|
||||
heapTotal: event.psmem.heapTotal,
|
||||
heapUsed: event.psmem.heapUsed,
|
||||
load: event.osload,
|
||||
delay: event.psdelay,
|
||||
concurrency: _.get(event, ['concurrents', port]),
|
||||
responseTimeAvg: _.get(event, ['responseTimes', port, 'avg']),
|
||||
responseTimeMax: _.get(event, ['responseTimes', port, 'max']),
|
||||
requests: _.get(event, ['requests', port, 'total'], 0)
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/status/health',
|
||||
handler: function (request, reply) {
|
||||
return reply({
|
||||
status: kibana.status,
|
||||
metrics: kibana.metrics
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -8,7 +8,7 @@ module.exports = function (grunt) {
|
|||
options: {
|
||||
directory: directory,
|
||||
branch: 'master',
|
||||
fresh: true,
|
||||
fresh: !grunt.option('esvm-no-fresh'),
|
||||
config: {
|
||||
path: {
|
||||
data: dataDir
|
||||
|
|
|
@ -6,7 +6,7 @@ module.exports = function (grunt) {
|
|||
'less:dev',
|
||||
'jade',
|
||||
'esvm:dev',
|
||||
'maybe_start_kibana',
|
||||
'maybeStartKibana',
|
||||
'watch'
|
||||
];
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
module.exports = function (grunt) {
|
||||
var _ = require('lodash');
|
||||
|
||||
grunt.registerTask('kibana_server', function (keepalive) {
|
||||
require('./utils/dev_server')(grunt)
|
||||
grunt.registerTask('devServer', function (keepalive) {
|
||||
var quiet = !(grunt.option('debug') || grunt.option('verbose'));
|
||||
var port = grunt.option('port');
|
||||
|
||||
require('../src/dev_server')(port, quiet)
|
||||
.then(function (server) {
|
||||
grunt.log.ok('Server started: ' + server.info.uri);
|
||||
if (keepalive) {
|
|
@ -15,7 +15,7 @@ module.exports = function (grunt) {
|
|||
|
||||
function onResponse(res) {
|
||||
grunt.log.debug('Server responded with', res.statusCode);
|
||||
if (res.statusCode === 200) {
|
||||
if (res.statusCode === 200 && res.headers['x-app-name'] === 'kibana') {
|
||||
grunt.log.ok('Kibana server already started on port', options.port);
|
||||
} else {
|
||||
grunt.log.error('Another server is already running on port', options.port);
|
||||
|
@ -49,9 +49,9 @@ module.exports = function (grunt) {
|
|||
};
|
||||
};
|
||||
|
||||
grunt.registerTask('maybe_start_kibana', maybeStartServer({
|
||||
grunt.registerTask('maybeStartKibana', maybeStartServer({
|
||||
name: 'kibana-server',
|
||||
port: grunt.option('port') || 5601,
|
||||
tasks: ['kibana_server']
|
||||
tasks: ['devServer']
|
||||
}));
|
||||
};
|
|
@ -10,7 +10,7 @@ module.exports = function (grunt) {
|
|||
'licenses',
|
||||
'jshint:source',
|
||||
'jscs:source',
|
||||
'maybe_start_kibana',
|
||||
'maybeStartKibana',
|
||||
'jade',
|
||||
'less:build',
|
||||
'simplemocha:all',
|
||||
|
@ -24,7 +24,7 @@ module.exports = function (grunt) {
|
|||
|
||||
grunt.registerTask('quick-test', function () {
|
||||
grunt.task.run([
|
||||
'maybe_start_kibana',
|
||||
'maybeStartKibana',
|
||||
'simplemocha:all',
|
||||
'mocha:unit'
|
||||
]);
|
||||
|
@ -32,12 +32,12 @@ module.exports = function (grunt) {
|
|||
|
||||
grunt.registerTask('coverage', [
|
||||
'blanket',
|
||||
'maybe_start_kibana',
|
||||
'maybeStartKibana',
|
||||
'mocha:coverage'
|
||||
]);
|
||||
|
||||
grunt.registerTask('test:watch', [
|
||||
'maybe_start_kibana',
|
||||
'maybeStartKibana',
|
||||
'watch:test'
|
||||
]);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue