diff --git a/README.md b/README.md index 4d8f4ed..8ac4b8a 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,16 @@ The app needs sqs list and read access to the sqs policies ## Running -**You need to specify the region you to connect to** -Running on an ec2 machine using IAM roles: -`docker run -e AWS_REGION= -d -p 9434:9434 ashiddo11/sqs-exporter` +To run the SQS exporter on Docker, you need to specify the region to connect to. -Or running it externally: -`docker run -d -p 9384:9384 -e AWS_ACCESS_KEY_ID= -e AWS_SECRET_ACCESS_KEY= -e AWS_REGION= ashiddo11/sqs-exporter` \ No newline at end of file +When running on an ec2 machine using IAM role: + +``` +$ docker run -e AWS_REGION= -d -p 9434:9434 ashiddo11/sqs-exporter +``` + +When running it externally: + +``` +$ docker run -d -p 9434:9434 -e AWS_ACCESS_KEY_ID= -e AWS_SECRET_ACCESS_KEY= -e AWS_REGION= ashiddo11/sqs-exporter +``` \ No newline at end of file diff --git a/collector/collector.go b/collector/collector.go index c538e6a..a87ce58 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -2,18 +2,19 @@ package collector import ( "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/sqs" "log" "net/http" "strings" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/sqs" ) type MetricHandler struct{} func (h MetricHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - queues,listQueueTags := getQueues() + queues, listQueueTags := getQueues() for queue, attr := range queues { msgAvailable := *attr.Attributes["ApproximateNumberOfMessages"] msgDelayed := *attr.Attributes["ApproximateNumberOfMessagesDelayed"] @@ -62,11 +63,13 @@ func getQueues() (queues map[string]*sqs.GetQueueAttributesOutput, tags map[stri QueueUrl: aws.String(*urls), } - resp, _ := client.GetQueueAttributes(params) - tagsResp, _ := client.ListQueueTags(tagsParams) queueName := getQueueName(*urls) - queues[queueName] = resp - tags[queueName] = tagsResp + resp, _ := client.GetQueueAttributes(params) + tagsResp, err := client.ListQueueTags(tagsParams) + if err == nil { + queues[queueName] = resp + tags[queueName] = tagsResp + } } - return queues,tags + return queues, tags }