Cloudwatch Insights Cơ Bản - Phần 1
Trong phần này mình sẽ giới thiệu một số cách search cloudwatch insight cực kì đơn giản,
Và đây là một số lệnh query cơ bản
APIGW
- thống kê lượt call theo api key id
fields @timestamp, @message
| filter @message like /API Key ID/
| parse @message "API Key ID: *" as @apikeyid
| stats count(*) by @apikeyid
- thống kê lượt call theo ip
fields @timestamp, @message
| filter @message like /X-Forwarded-For/
| parse @message "X-Forwarded-For=*," as @apikeyid
| stats count(*) as tmp by @apikeyid
| sort tmp desc
- số lượng call theo path
fields @timestamp, @message
| filter @message like /Resource Path/
| parse @message "Resource Path: *" as @apipath
| stats count(*) as tmp by @apipath
| sort tmp desc
- số lượng call vào domain
fields @timestamp, @message
| filter @message like /Host/
| parse @message "Host=*," as @apipath
| stats count(*) as tmp by @apipath
| sort tmp desc
- sort latency
fields @timestamp, @message, @logStream, @log, latency
| sort latency desc
| limit 20
chú ý là latency trong apigw thì không mặc định, mà các bạn phải cấu hình để apigw return về latency. Sẽ cấu hình detail ở bài viết khác.
- max, min, avg latency
fields @timestamp, @message, @logStream, @log, latency
| max(latency) as max, min(latency) as min, avg(latency)
- filter latency
fields @timestamp, @message, @logStream, @log, latency
| filter latency > 1000
- filter status, http code
fields @timestamp, @message, @logStream, @duration
| filter @message like 'status":"500"'
| filter @message like 'pathName'
| sort @timestamp desc
với pathName thì sẽ là router của các bạn cấu hình, ví dụ như auth/login
lambda
- memory usage
filter @type = "REPORT"
| stats max(@memorySize / 1000 / 1000) as provisionedMemoryMB,
min(@maxMemoryUsed / 1000 / 1000) as smallestMemoryRequestMB,
avg(@maxMemoryUsed / 1000 / 1000) as avgMemoryUsedMB,
max(@maxMemoryUsed / 1000 / 1000) as maxMemoryUsedMB,
provisionedMemoryMB - maxMemoryUsedMB as overProvisionedMB
- latency lambda
filter @type = "REPORT"
| fields @requestId, @billedDuration, @logStream, @duration
| sort by @billedDuration desc
REPORT RequestId: 56ca8bba-aa7d-4585-b4d6-5aa53651349a Duration: 93.16 ms Billed Duration: 94 ms Memory Size: 512 MB Max Memory Used: 60 MB
Insight
- Count Số Lượng Log:
fields @timestamp, @message, @logStream, @log
| filter @logStream like /name/
| filter @message like /log data/
| stats count(*) as tmp
- Count Số Lượng response Code
- ví dụ log sẽ như thế này
{
"data": {
"status": "CREATED",
},
"responseCode": "00",
"responseId": "0a4934e6-ea6a-42b2-8703-e3444a80539c",
"responseMessage": "successfully",
"responseTime": "2024-05-03T10:45:58.124+07:00"
}
- câu search
fields @timestamp, @message, @logStream, @log
| filter @message like /"responseCode":"(\d{2})"/
| parse @message "responseCode\":\"*" as responseCode
| stats count(*) by responseCode
| limit 1000
Liên Hệ
- facebook: https://www.facebook.com/phucducdev/
- group: https://www.facebook.com/groups/575250507328049
- gmail: ducnp09081998@gmail.com
- linkedin: https://www.linkedin.com/in/phucducktpm/
- hashnode: https://hashnode.com/@OpenDev
- telegram: https://t.me/OpenDevGolang
All rights reserved