Skip to content

Commit

Permalink
Cloudwatch metrics and logs examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisguest75 committed Dec 24, 2023
1 parent 245176c commit 0e3952a
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 33_awscli/CLOUDWATCH_LOGS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# LOGS

Cloudwatch Logs.

## Groups

```sh
# list groups
aws --no-cli-pager logs describe-log-groups --query 'logGroups[*]' | jq .

# list names
aws logs describe-log-groups --query 'logGroups[*].logGroupName' | jq .

# show sizes, dates and names
aws logs describe-log-groups --query 'logGroups[?storedBytes==`0`]' | jq -c '.[] | [.storedBytes, (.creationTime | (./1000 | strftime("%Y-%m-%d %H:%M:%S"))), .logGroupName]'
```

## Resouces
92 changes: 92 additions & 0 deletions 33_awscli/CLOUDWATCH_METRICS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Cloudwatch Metrics

Demonstrate some example commands for managing Cloudwatch Metrics.

NOTE:

* list-metrics seems to take a long time
```sql
SELECT SUM(NumberOfMessagesSent) FROM SCHEMA("AWS/SQS", QueueName) GROUP BY QueueName ORDER BY SUM() DESC LIMIT 10

# s3
SELECT AVG(TotalRequestLatency) FROM SCHEMA("AWS/S3", BucketName, FilterId) WHERE FilterId = 'EntireBucket' GROUP BY BucketName ORDER BY AVG() DESC
```

## Namespaces

Metrics have namespaces

```txt
"AWS/ApiGateway"
"AWS/ApplicationELB"
"AWS/AutoScaling"
"AWS/Backup"
"AWS/Billing"
"AWS/CertificateManager"
"AWS/CloudFront"
"AWS/DynamoDB"
"AWS/EBS"
"AWS/EC2"
"AWS/ECR"
"AWS/ECS"
"AWS/ECS/ManagedScaling"
"AWS/EFS"
"AWS/ELB"
"AWS/ES"
"AWS/ElastiCache"
"AWS/Events"
"AWS/Firehose"
"AWS/Inspector"
"AWS/Lambda"
"AWS/Logs"
"AWS/NATGateway"
"AWS/NetworkELB"
"AWS/PrivateLinkEndpoints"
"AWS/Route53"
"AWS/S3"
"AWS/SNS"
"AWS/SQS"
"AWS/Schemas"
"AWS/SecretsManager"
"AWS/States"
"AWS/TransitGateway"
"AWS/Translate"
"AWS/Usage"
"AWS/WAFV2"
"AWS/X-Ray"
"ContainerInsights"
"ECS/ContainerInsights"
```

## Metrics

```sh
export AWS_PAGER=

aws cloudwatch list-metric-streams --max-results 10
aws cloudwatch list-metrics --max-items 10

# aggregate the metrics namespaces
aws --profile ${AWS_PROFILE} --region ${AWS_REGION} cloudwatch list-metrics | jq '.Metrics[].Namespace' | sort | uniq


# list metrics names
aws --profile ${AWS_PROFILE} --region ${AWS_REGION} cloudwatch list-metrics --namespace "AWS/EC2"

aws --profile ${AWS_PROFILE} --region ${AWS_REGION} cloudwatch list-metrics --namespace "AWS/S3"

aws --profile ${AWS_PROFILE} --region ${AWS_REGION} cloudwatch list-metrics --namespace "AWS/Lambda"
```

## S3

```sh
aws --profile ${AWS_PROFILE} --region ${AWS_REGION} cloudwatch list-metrics --namespace "AWS/S3" --dimensions Name=BucketName,Value=${BUCKET_NAME}

## This is not working
aws --profile ${AWS_PROFILE} --region ${AWS_REGION} cloudwatch get-metric-statistics --namespace "AWS/S3" --metric-name "NumberOfObjects" --dimensions Name=BucketName,Value=${BUCKET_NAME} Name=StorageType,Value=AllStorageTypes --start-time $(gdate -u -d "1 day ago" +"%Y-%m-%dT%H:%M:%SZ") --end-time $(gdate -u +"%Y-%m-%dT%H:%M:%SZ") --period 86400 --statistics "Maximum"
```

## Resources

* cloudwatch cli [here](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/index.html)

0 comments on commit 0e3952a

Please sign in to comment.