[PYTHON] I searched for the contents of CloudWatch Logs Agent

Introduction

I checked the contents of the CloudWatch Logs agent (halfway). I looked it up. I will proceed on the assumption that I have read the above blog.

Conclusion

/var/awslogs/lib/python2.7/site-packages/cwlogs/push.py

Was the code that reads the monitored logs and pushes the event to the CloudWatch Logs service. It's about 1800 lines of code. It's hard for me to read it, but the main processing is completed in this code, so you can read it to see how it works. FileEventsReader._run (self) is the part that actually reads the log

The future is a digression.

awscli does not contain logs code

Because it is included in aws cli,

/usr/lib/python2.7/dist-packages/awscli  (awscli installation directory)
https://github.com/aws/aws-cli  (awscli git repository)
https://github.com/boto/boto3/  (Library used by awscli)

I searched for subordinates, but there was nothing.

Cloudwatch logs agent execution process

I turned around and looked at the runtime options for the cloudwatch logs agent. /var/awslogs/bin/awslogs-agent-launcher.sh Looking at, it is as follows.

/usr/bin/env -i \
HTTPS_PROXY=$HTTPS_PROXY \
HTTP_PROXY=$HTTP_PROXY \
NO_PROXY=$NO_PROXY \
AWS_CONFIG_FILE=/var/awslogs/etc/aws.conf \
HOME=/root \
/bin/nice -n 4 \
/var/awslogs/bin/aws logs push \
--config-file /var/awslogs/etc/awslogs.conf \
--additional-configs-dir /var/awslogs/etc/config \
>> /var/log/awslogs.log 2>&1

When I actually executed this command while erasing the setting, it worked if there was the following

AWS_CONFIG_FILE=/var/awslogs/etc/aws.conf \
/var/awslogs/bin/aws logs push \
--config-file /var/awslogs/etc/awslogs.conf

Looking at the contents of AWS_CONFIG_FILE, it is as follows.

$ cat /var/awslogs/etc/aws.conf
[plugins]
cwlogs = cwlogs
[default]
region = us-west-2

awscli plugin

Oh. Plugin! So if you look for a python package /var/awslogs/lib/python2.7/site-packages/cwlogs Exists and has the following files

filter.py
__init__.py
kvstore.py
parser.py
pull.py
push.py
retry.py
threads.py
utils.py

Of these, push.py and pull.py were commands and the rest were utility classes. I haven't investigated the function of pull because I have no guts.

in conclusion

For the first time, I learned that AWS CLI can add functionality with plugins. I think it may be possible to create a plugin by referring to cwlogs.

reference

I checked the contents of the CloudWatch Logs agent (halfway) Summary of research on the behavior of CloudWatch Logs Agent

Recommended Posts

I searched for the contents of CloudWatch Logs Agent
I checked the contents of docker volume
I searched for railway senryu from the data
[Python] I searched for the longest Pokemon Shiritori
Mongodb Shortest Introduction (2) I searched for tens of thousands
Simulation of the contents of the wallet
I searched for CD commands.
Change the log retention period of CloudWatch Logs in Lambda
I investigated the mechanism of flask-login!
Understand the contents of sklearn's pipeline
I searched for a similar card of Hearthstone with Deep Learning
See the contents of Kumantic Segumantion
Introductory table of contents for python3
I analyzed the voting results of the Osaka Metropolis Plan for each ward
I read the Sudachi synonym dictionary with Pandas and searched for synonyms
I tried the asynchronous server of Django 3.0
I tried tensorflow for the first time
I checked the options of copyMakeBorder of OpenCV
I summarized the folder structure of Flask
I didn't know the basics of Python
The third night of the loop with for
Pandas of the beginner, by the beginner, for the beginner [Python]
The Python project template I think of.
Read all the contents of proc / [pid]
I searched for prime numbers in python
I read the implementation of golang channel
The second night of the loop with for
[Python] I searched for various types! (Typing)
I tried to summarize the settings for various databases of Django (MySQL, PostgreSQL)
[Bash] While read, pass the contents of the file to variables for each column
I want to add silence to the beginning of a wav file for 1 second
I searched for the skills needed to become a web engineer in Python
I tried to automate the face hiding work of the coordination image for wear
I tried using scrapy for the first time
Get the contents of git diff from python
I tried the pivot table function of pandas
I checked the library for using the Gracenote API
I tried cluster analysis of the weather map
The story of low learning costs for Python
vprof --I tried using the profiler for Python
I read the implementation of range (Objects / rangeobject.c)
The contents of the Python tutorial (Chapter 5) are itemized.
The contents of the Python tutorial (Chapter 4) are itemized.
I solved the deepest problem of Hiroshi Yuki.
Watch out for the return value of __len__
I checked the list of shortcut keys of Jupyter
I played with Floydhub for the time being
I tried python programming for the first time.
The contents of the Python tutorial (Chapter 10) are itemized.
I tried to correct the keystone of the image
Try the free version of Progate [Python I]
I checked the session retention period of django
I checked the processing speed of numpy one-dimensionalization
I tried Mind Meld for the first time
I touched some of the new features of Python 3.8 ①
Dump the contents of redis db with lua
Code for checking the operation of Python Matplotlib
The contents of the Python tutorial (Chapter 6) are itemized.
I read and implemented the Variants of UKR
The contents of the Python tutorial (Chapter 3) are itemized.
I want to customize the appearance of zabbix