简体   繁体   English

AWS Cloudwatch 将 Stream 记录到 Amazon Elasticsearch 服务

[英]AWS Cloudwatch Logs Stream to Amazon Elasticsearch Service

I'm streaming CWL to Amazon Elasticsearch Service with Subscription.我正在通过订阅将 CWL 流式传输到 Amazon Elasticsearch 服务。 The index was created automatically, but I want to change the number of shards.索引是自动创建的,但我想更改分片的数量。 I'm looking at a Lambda function, but I can't find any code that specifies the number of shards.我正在查看 Lambda function,但我找不到任何指定分片数量的代码。

Also, how can I make the index look like cwl-{logGroup Title}-00001?另外,如何使索引看起来像 cwl-{logGroup Title}-00001?

Can anyone give me some advice?谁能给我一些建议?

To have the index with logGroup title you can use below code:要获得带有 logGroup 标题的索引,您可以使用以下代码:

At Line 62 of the Lambda function you will see the following section of code:在 Lambda function 的第 62 行,您将看到以下代码部分:

// index name format: cwl-YYYY.MM.DD
var indexName = [
'cwl-' + timestamp.getUTCFullYear(),              // cwl + time
('0' + (timestamp.getUTCMonth() + 1)).slice(-2),  // month
('0' + timestamp.getUTCDate()).slice(-2)          // day
].join('.');

Replace it with the following code:将其替换为以下代码:

// index name format: cwl-log-group-YYYY.MM.DD
var indexName = [
'cwl-' + payload.logGroup.toLowerCase().split('/').join('-') + '-' + timestamp.getUTCFullYear(),              // cwl + log group + time
('0' + (timestamp.getUTCMonth() + 1)).slice(-2),  // month
('0' + timestamp.getUTCDate()).slice(-2)          // day
].join('.');

This change will create a separate index for each log group.此更改将为每个日志组创建一个单独的索引。 Please test the same in your testing environment first before deploying in production.请先在您的测试环境中进行测试,然后再部署到生产环境中。

For changing the number of shards, you can create an index template at AWS ES end for this specific index pattern.要更改分片数量,您可以在 AWS ES 端为此特定索引模式创建一个索引模板

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM