kibana-123
Version:
Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic
77 lines (71 loc) • 2.46 kB
JavaScript
var _ = require('lodash');
var moment = require('moment');
var toMS = require('../../lib/to_milliseconds.js');
var Datasource = require('../../lib/classes/datasource');
var buildRequest = require('./lib/build_request');
import toSeriesList from './lib/agg_response_to_series_list';
module.exports = new Datasource('es', {
args: [
{
name: 'q',
types: ['string', 'null'],
multi: true,
help: 'Query in lucene query string syntax'
},
{
name: 'metric',
types: ['string', 'null'],
multi: true,
help: 'An elasticsearch single value metric agg, eg avg, sum, min, max or cardinality, followed by a field.' +
' Eg "sum:bytes", or just "count"'
},
{
name: 'split',
types: ['string', 'null'],
multi: true,
help: 'An elasticsearch field to split the series on and a limit. Eg, "hostname:10" to get the top 10 hostnames'
},
{
name: 'index',
types: ['string', 'null'],
help: 'Index to query, wildcards accepted'
},
{
name: 'timefield',
types: ['string', 'null'],
help: 'Field of type "date" to use for x-axis'
},
{
name: 'kibana',
types: ['boolean', 'null'],
help: 'Respect filters on Kibana dashboards. Only has an effect when using on Kibana dashboards'
},
{
name: 'interval', // You really shouldn't use this, use the interval picker instead
types: ['string', 'null'],
help: '**DO NOT USE THIS**. Its fun for debugging fit functions, but you really should use the interval picker'
}
],
help: 'Pull data from an elasticsearch instance',
aliases: ['elasticsearch'],
fn: function esFn(args, tlConfig) {
var config = _.defaults(_.clone(args.byName), {
q: '*',
metric: ['count'],
index: tlConfig.settings['timelion:es.default_index'],
timefield: tlConfig.settings['timelion:es.timefield'],
interval: tlConfig.time.interval,
kibana: true,
fit: 'nearest'
});
const { callWithRequest } = tlConfig.server.plugins.elasticsearch.getCluster('data');
const body = buildRequest(config, tlConfig);
return callWithRequest(tlConfig.request, 'search', body).then(function (resp) {
if (!resp._shards.total) throw new Error('Elasticsearch index not found: ' + config.index);
return {
type: 'seriesList',
list: toSeriesList(resp.aggregations, config)
};
});
}
});