-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate sqs metricset to use cloudwatch input as light weight module (#…
- Loading branch information
1 parent
87846d9
commit 0d60f49
Showing
12 changed files
with
144 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package sqs | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
awssdk "github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/sqs" | ||
"github.com/aws/aws-sdk-go-v2/service/sqs/sqsiface" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/elastic/beats/v7/libbeat/logp" | ||
"github.com/elastic/beats/v7/metricbeat/mb" | ||
awscommon "github.com/elastic/beats/v7/x-pack/libbeat/common/aws" | ||
) | ||
|
||
const metadataPrefix = "aws.sqs.queue" | ||
|
||
// AddMetadata adds metadata for SQS queues from a specific region | ||
func AddMetadata(endpoint string, regionName string, awsConfig awssdk.Config, events map[string]mb.Event) map[string]mb.Event { | ||
svc := sqs.New(awscommon.EnrichAWSConfigWithEndpoint( | ||
endpoint, "sqs", regionName, awsConfig)) | ||
|
||
// Get queueUrls for each region | ||
queueURLs, err := getQueueUrls(svc) | ||
if err != nil { | ||
logp.Error(fmt.Errorf("getQueueUrls failed, skipping region %s: %w", regionName, err)) | ||
return events | ||
} | ||
|
||
// collect monitoring state for each instance | ||
for _, queueURL := range queueURLs { | ||
queueURLParsed := strings.Split(queueURL, "/") | ||
queueName := queueURLParsed[len(queueURLParsed)-1] | ||
if _, ok := events[queueName]; !ok { | ||
continue | ||
} | ||
events[queueName].RootFields.Put(metadataPrefix+"name", queueName) | ||
} | ||
return events | ||
} | ||
|
||
func getQueueUrls(svc sqsiface.ClientAPI) ([]string, error) { | ||
// ListQueues | ||
listQueuesInput := &sqs.ListQueuesInput{} | ||
req := svc.ListQueuesRequest(listQueuesInput) | ||
output, err := req.Send(context.TODO()) | ||
if err != nil { | ||
err = errors.Wrap(err, "Error ListQueues") | ||
return nil, err | ||
} | ||
return output.QueueUrls, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ metricsets: | |
- ec2 | ||
- elb | ||
- ebs | ||
- sqs | ||
- usage | ||
- sns | ||
- s3_daily_storage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
default: true | ||
input: | ||
module: aws | ||
metricset: cloudwatch | ||
defaults: | ||
metrics: | ||
- namespace: AWS/SQS | ||
resource_type: sqs | ||
statistic: ["Average"] | ||
name: | ||
- ApproximateAgeOfOldestMessage | ||
- ApproximateNumberOfMessagesDelayed | ||
- ApproximateNumberOfMessagesNotVisible | ||
- ApproximateNumberOfMessagesVisible | ||
- NumberOfMessagesDeleted | ||
- NumberOfMessagesReceived | ||
- NumberOfMessagesSent | ||
- NumberOfEmptyReceives | ||
- SentMessageSize | ||
processors: | ||
- rename: | ||
ignore_missing: true | ||
fields: | ||
- from: "aws.sqs.metrics.ApproximateAgeOfOldestMessage.avg" | ||
to: "aws.sqs.oldest_message_age.sec" | ||
- from: "aws.sqs.metrics.ApproximateNumberOfMessagesDelayed.avg" | ||
to: "aws.sqs.messages.delayed" | ||
- from: "aws.sqs.metrics.ApproximateNumberOfMessagesNotVisible.avg" | ||
to: "aws.sqs.messages.not_visible" | ||
- from: "aws.sqs.metrics.ApproximateNumberOfMessagesVisible.avg" | ||
to: "aws.sqs.messages.visible" | ||
- from: "aws.sqs.metrics.NumberOfMessagesDeleted.avg" | ||
to: "aws.sqs.messages.deleted" | ||
- from: "aws.sqs.metrics.NumberOfMessagesReceived.avg" | ||
to: "aws.sqs.messages.received" | ||
- from: "aws.sqs.metrics.NumberOfMessagesSent.avg" | ||
to: "aws.sqs.messages.sent" | ||
- from: "aws.sqs.metrics.NumberOfEmptyReceives.avg" | ||
to: "aws.sqs.empty_receives" | ||
- from: "aws.sqs.metrics.SentMessageSize.avg" | ||
to: "aws.sqs.sent_message_size.bytes" | ||
|
||
- drop_fields: | ||
ignore_missing: true | ||
fields: | ||
- "aws.sqs.metrics" |
Oops, something went wrong.