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

change elk index #47

Closed
dduo518 opened this issue Aug 9, 2018 · 2 comments
Closed

change elk index #47

dduo518 opened this issue Aug 9, 2018 · 2 comments
Assignees

Comments

@dduo518
Copy link

dduo518 commented Aug 9, 2018

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
}));

module.exports.supportedOptions = {

// 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

   //...

};

swsElasticEmitter.prototype.initialize = function (swsOptions) {

// 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
    }

   //......

};

swsElasticEmitter.prototype.processRecord = function(rrr){

// 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
Copy link
Collaborator

sv2 commented Aug 9, 2018

Looks right, thanks ! Will add soon

@sv2 sv2 self-assigned this Aug 9, 2018
@sv2 sv2 added the enhancement label Aug 9, 2018
sv2 added a commit that referenced this issue Sep 1, 2018
@sv2
Copy link
Collaborator

sv2 commented Sep 1, 2018

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));
            }
        }));

@sv2 sv2 closed this as completed Sep 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants