
尾部AWS CloudWatch登錄的最佳方法是從您的終端登錄。
作者 - 盧卡·格拉拉(Luca Grulla)-https://www.lucagrulla.com
Local時區或UTC (默認)。2d1h20m表示2天,1小時20分鐘前。13:10表示今天的13:10。2018-10-20T8:53 。cw tail my-auth-service my-web 。--grep )和GREPV ( --grepv )。--query Flag匹配)echo my-group | cw tail and cat groups.txt | cw tail 。cw tail -f my-stream >> myfile.txt 。--no-color標誌。--profile profile和--region標誌來實現覆蓋。 brew tap lucagrulla/tap
brew install cwbrew tap lucagrulla/tap
brew install cw從“版本”頁面下載.deb或.rpm ,並分別使用dpkg -i和rpm -i安裝。
注意:如果您升級到3.3.0,請注意新的別名命令。這是遵守Snapcraft新發布規則所必需的。
snap install cw-sh
sudo snap connect cw-sh:dot-aws-config-credentials
sudo snap alias cw-sh.cw cw cw嚴格限制運行;需要訪問.aws/config和.aws/credentials文件,需要dot-aws-config-credentials接口連接
scoop bucket add cw https://github.com/lucagrulla/cw-scoop-bucket.git
scoop install cwgo get github.com/lucagrulla/cw--profile=profile-name覆蓋用於連接的AWS配置文件。--region=aws-region覆蓋目標AWS區域。--no-color禁用彩色輸出。--endpoint目標AWS端點URL。默認情況下,CW將使用默認的AWS端點。--no-version-check忽略檢查是否有新版本的模塊可用。cw ls列出了組中的所有日誌組/日誌流
Usage: cw ls <command>
show an entity
Flags:
-h, --help Show context-sensitive help.
--endpoint=URL The target AWS endpoint url. By default cw will use the default aws endpoints. NOTE: v4.0.0
dropped the flag short version.
--profile=PROFILE The target AWS profile. By default cw will use the default profile defined in the
.aws/credentials file. NOTE: v4.0.0 dropped the flag short version.
--region=REGION The target AWS region. By default cw will use the default region defined in the
.aws/credentials file. NOTE: v4.0.0 dropped the flag short version.
--no-color Disable coloured output.NOTE: v4.0.0 dropped the flag short version.
--version Print version information and quit
--no-version-check Ignore checks if a newer version of the module is available.
Commands:
ls groups
Show all groups.
ls streams <group>
Show all streams in a given log group.
cw: error: expected one of "groups", "streams" cw tail尾給定的日誌組/日誌流
Usage: cw tail <groupName[:logStreamPrefix]> ...
Tail log groups/streams.
Arguments:
<groupName[:logStreamPrefix]> ... The log group and stream name, with group:prefix syntax. Stream name can be just the prefix. If no stream name is specified all stream names in the given
group will be tailed. Multiple group/stream tuple can be passed. e.g. cw tail group1:prefix1 group2:prefix2 group3:prefix3.
Flags:
-h, --help Show context-sensitive help.
--endpoint=URL The target AWS endpoint url. By default cw will use the default aws endpoints. NOTE: v4.0.0 dropped the flag short version.
--profile=PROFILE The target AWS profile. By default cw will use the default profile defined in the .aws/credentials file. NOTE: v4.0.0 dropped the flag short version.
--region=REGION The target AWS region. By default cw will use the default region defined in the .aws/credentials file. NOTE: v4.0.0 dropped the flag short version.
--no-color Disable coloured output.NOTE: v4.0.0 dropped the flag short version.
--version Print version information and quit
--no-version-check Ignore checks if a newer version of the module is available.
-f, --follow Don't stop when the end of streams is reached, but rather wait for additional data to be appended.
-t, --timestamp Print the event timestamp.
-i, --event-id Print the event Id.
-s, --stream-name Print the log stream name this event belongs to.
-n, --group-name Print the log group name this event belongs to.
-r, --retry Keep trying to open a log group/log stream if it is inaccessible.
-b, --start="2021-04-11T08:21:52" The UTC start time. Passed as either date/time or human-friendly format. The human-friendly format accepts the number of days, hours and minutes prior to
the present. Denote days with 'd', hours with 'h' and minutes with 'm' i.e. 80m, 4h30m, 2d4h. If just time is used (format: hh[:mm]) it is expanded to
today at the given time. Full available date/time format: 2017-02-27[T09[:00[:00]].
-e, --end=STRING The UTC end time. Passed as either date/time or human-friendly format. The human-friendly format accepts the number of days, hours and minutes prior to the
present. Denote days with 'd', hours with 'h' and minutes with 'm' i.e. 80m, 4h30m, 2d4h. If just time is used (format: hh[:mm]) it is expanded to today at
the given time. Full available date/time format: 2017-02-27[T09[:00[:00]].
-l, --local Treat date and time in Local timezone.
-g, --grep=STRING Pattern to filter logs by. See http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html for syntax.
-v, --grepv=STRING Equivalent of grep --invert-match. Invert match pattern to filter logs by.
-q, --query=STRING Equivalent of the --query flag in AWS CLI. Takes a JMESPath expression to filter JSON logs by. If the query fails (e.g. the log message was not JSON) then the original line is returned. 可用日誌組列表
cw ls groups給定日誌組中的日誌流列表
cw ls streams my-log-group尾巴並遵循給定的日誌組/流
cw tail -f my-log-groupcw tail -f my-log-group:my-log-stream-prefixcw tail -f my-log-group:my-log-stream-prefix my-log-group2cw tail -f my-log-group:my-log-stream-prefix -b2017-01-01T08:10:10 -e2017-01-01T08:05:00cw tail -f my-log-group:my-log-stream-prefix -b7d從7天前開始。cw tail -f my-log-group:my-log-stream-prefix -b3h從3小時前開始。cw tail -f my-log-group:my-log-stream-prefix -b100m從100分鐘前開始。cw tail -f my-log-group:my-log-stream-prefix -b2h30m從2小時30分鐘開始。cw tail -f my-log-group -b9:00 -e9:01使用jmespath語法查詢JSON日誌
cw tail -f my-log-group --query "machines[?state=='running'].name"默認情況下,時間和日期被視為UTC。如果您喜歡使用本地區域,請使用--local標誌。
cw使用默認憑據配置文件(存儲在./aws/credentials中)進行身份驗證和共享配置(.aws/config)來識別目標AWS區域。輪廓和區域都可以通過profile和region全局標誌覆蓋。
如果您可以支持AWS SSO:
default或替代命名配置文件)sso_start_url , sso_account_id , sso_role_name等aws sso login如果您收到一個錯誤消息,其中包括...failed to sign request: failed to retrieve credentials: the SSO session has expired or is invalid...那麼您應該通過aws sso login續訂SSO會話(如果適用,並指定命名配置文件,請指定)。
cw請根據AWS CLI的要求使用HTTP_PROXY環境變量:https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-proxy.html
在這裡閱讀