change elk index
Closed this issue · 2 comments
dduo518 commented
I want to use different index!
well!
if change the
change to
"template": "server-1-*",
ok?
or
app.use(swStats.getMiddleware({
elasticsearch: "http://10.40.2.89:9200",
elasticsearchIndex: "server-1-*" // Configuration els index
}));
Line 11 in 1a61c6c
// swagger-stats supported options
module.exports.supportedOptions = {
// ....
// ElasticSearch URL. Enables storing of request response records in Elasticsearch.
// Default is empty (disabled).
elasticsearch: "elasticsearch",
elasticsearchIndex: "api-*", // elk default index
//...
};
swagger-stats/lib/swsElasticEmitter.js
Line 42 in 1a61c6c
// Initialize
swsElasticEmitter.prototype.initialize = function(swsOptions) {
if (typeof swsOptions === 'undefined') return;
if (!swsOptions) return;
this.options = swsOptions;
// Set or detect hostname
if (!(swsUtil.supportedOptions.elasticsearch in swsOptions)) {
debug('Elasticsearch is disabled');
return;
}
if (this.options.elasticsearchIndex) {
indexTemplate.template = this.options.elasticsearchIndex
}
//......
};
swagger-stats/lib/swsElasticEmitter.js
Line 144 in 1a61c6c
// Index Request Response Record
swsElasticEmitter.prototype.processRecord = function(rrr) {
//...
// Create metadata
var indexName = this.options.elasticsearchIndex + moment(rrr['@timestamp']).utc().format('YYYY.MM.DD');
var meta = { index: { _index: indexName, _type: this.options.elasticsearchIndex, _id: rrr.id } };
// console.log(indexTemplate)
// Add to buffer
// .....
};
it is ok?
sv2 commented
Looks right, thanks ! Will add soon
sv2 commented
new option elasticsearchIndexPrefix
is added. Use this option to specify desired index prefix, for example:
// Enable swagger-stats middleware
app.use(swStats.getMiddleware({
name: 'swagger-stats-testapp',
version: '0.95.6',
timelineBucketDuration: tlBucket,
uriPath: '/swagger-stats',
swaggerSpec:swaggerSpec,
elasticsearch:'http://127.0.0.1:9200',
elasticsearchIndexPrefix:'swagger-stats-',
onResponseFinish: function(req,res,rrr){
debug('onResponseFinish: %s', JSON.stringify(rrr));
}
}));