Get, sort and analyse AWS CloudWatch logs from multiple log groups using AWS CloudWatch Insights service
Project description
awsinsights
Get and filter logs from multiple log groups of AWS CloudWatch and filter CloudWatch logs using predefined regular expressions.
This script uses AWS CloudWatch Insights service.
Install
awsinsights is released to public PyPI - awsinsights. It can be installed using this command:
pip install awsinsights
Basic Usage
-
Set up AWS Credentials.
-
Define apps (sets of CloudWatch log groups assigned to app name) in
$HOME/.awsinsights.jsonfile. See example file below. -
Get all logs from the
simplebookapp (2 log groups pre-defined) since last 30 minutes:
awsinsights --timedelta 30m --appname simplebook
- Filter logs from
simplebookapp since last 7d containing words 'Monday' or 'Tuesday' (you can use any Regular Expression in )
awsinsights --timedelta 7d --appname simplebook --filter "Monday|Tuesday"
Advanced Usage
- Get logs from
simplebookfrom 1 Jan 2021 10:00am to 2 Jan 2021 9:00am which contain 'Exception' or 'ERROR' on PROD environment
awsinsights --env prod --start 2021-01-01 10:00:00 --end 2021-01-02 09:00:00 --appname simplebook --filter "Exception|ERROR"
- Get all logs from CloudWatch log groups
group-one-devand/aws/lambda/group-two-devsince last 2 hours:
awsinsights --timedelta 2h --log_groups "group-one-dev" "/aws/lambda/group-two-dev"
Tail mode
awsinsights allows to listen CloudWatch in live mode which is called tail mode.
It can be activated using --tail option.
Example - listening for ERRORs and Exceptions in tail mode:
awsinsights --timedelta 30m --appname simplebook --filter "ERROR|Exception" --tail
NOTE: Please notice that there might be few mins delay between the time when log really happened
and the time when it will appear in output of awsinsights' tail mode.
Example of config file
Config file should be placed in $HOME/.awsinsights.json
This example file contains 2 apps: simplebook and secondapp.
Each app consits of 2 CloudWatch log groups.
{
"simplebook": [
"/aws/lambda/simple-books-catalog-api-$ENV",
"/aws/lambda/api-task-2-ad"
],
"secondapp": [
"first-log-group",
"/aws/lambda/second-log-group"
]
}
Output file
Logs will be written to output file. Output file will be:
/tmp/{appname}.logif app name is defined using--appnameoption OR/tmp/awsinsights.logif app name is NOT defined
Help
awsinsights [-h] [--timedelta TIMEDELTA] [--start START] [--end END]
[--filter FILTER]
(--appname APPNAME | --log_groups LOG_GROUPS [LOG_GROUPS ...])
[--env ENV] [--query QUERY]
optional arguments:
-h, --help show this help message and exit
--timedelta TIMEDELTA
delta time since now when logs should be filtered ex.
120m, 3h, 2d. Default: 60m
--start START start time of grabbing logs. Format: YYYY-MM-DD
HH:MM:SS
--end END end time of grabbing logs. Format: YYYY-MM-DD HH:MM:SS
--filter FILTER Regular expression for filtering logs
--appname APPNAME name of the app which logs should be analysed. App
names should have logs groups configured in
.awsinsightsrc file. See README.md file.
--log_groups LOG_GROUPS [LOG_GROUPS ...]
list of the log groups " "to analyse (up to 20)
--env ENV env name. It can be used to resolve "{env}" var in log
groups names. Default: dev
--query QUERY Custom full AWS CloudWatch Insights query. " "Default:
fields @timestamp, @message | filter @message like //
| sort @timestamp
--tail TAIL MODE. If set to "true", It will listen for live
logs forever
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file awsinsights-1.0.4.tar.gz.
File metadata
- Download URL: awsinsights-1.0.4.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c9bb4776ca69f66db598654fb1d82be929e3d764b98d4219f66292739554d37
|
|
| MD5 |
9921b8ef15bdac79c251c833b07b39dd
|
|
| BLAKE2b-256 |
6c07d7915ef6c6841c04f1c5e06df7f3353ec13d17deb495efa613679c83613c
|
File details
Details for the file awsinsights-1.0.4-py3-none-any.whl.
File metadata
- Download URL: awsinsights-1.0.4-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
615d31ad7739a4d064cd5b75e949e8a0552c3d1c69e01ee80175e946c586ee80
|
|
| MD5 |
40545821d56c959140a012fe73061628
|
|
| BLAKE2b-256 |
a38225728a36a7cb05aac7b4d92dd4b559c6dd9b7a1eb91aa1aa812f654732c9
|