从文件导入记录器消息并生成Kibana可视化
logger-to-kibana的Python项目详细描述
基巴纳伐木工人
集成此项目以根据遇到的日志消息生成视图。在
python可执行文件位于https://pypi.org/project/logger-to-kibana/
您需要通过运行
pip install -r requirements.txt
要获取程序帮助,只需键入:
^{pr2}$这将返回:
Usage: main.py [OPTIONS] COMMAND [ARGS]... Process the file provided according to conditions Options: --help Show this message and exit. Commands: pommands: process Process the folder process_and_generate Process the folder and generate visualization process_generate_and_send Process the folder, generate visualization and send
我创造了一个开发至这个系列解释了这个项目是如何运作的,以及我从中得到的任何学习。你可以在https://dev.to/ismaelmartinez/setting-up-my-first-opensource-python-project-4k1o找到它
默认设置
默认设置可以在settings.ini文件中找到。您可以提供不同的设置 将其指定为环境变量LOGGER_TO_KIBANA_CONFIG
命令
当前可用的命令有:
过程
处理一个文件夹并按以下格式打印出已处理的函数/日志:
[{'subfolder': '<folder_name>', 'filename': '<filename>', 'function': '<function_name>', 'type': '<log_type>', 'query': 'message: "<log_filter>"', 'label': '<log_type>: <log_filter>'}]
要执行命令run:
python main.py process -f <folder_location>
查看How does it work部分下的表以获取有关日志类型和日志筛选器的更多信息。在
过程生成
处理一个文件夹(如过程部分所示)并为kibana生成一个表格可视化。在
要执行命令run:
python main.py process_and_generate -f <folder_location>
处理“生成”和“发送”
处理一个文件夹,为kibana生成一个表可视化,并将其发送到kibana(当前在本地主机:5601)在
要执行命令run:
python main.py process_and_generate -f <folder_location>
它是如何工作的
默认情况下,它扫描指定文件夹下的文件,并使用app/src/**/*.py
模式。您可以在settings.ini中的filematchfilter中指定另一个模式
这个程序使用不同的regex detectors
来过滤要处理的日志和文件。在
这些可以在settings.ini文件中更改。在
目前可用的探测器有:
Detector | Default Value | Propose |
---|---|---|
FilesMatchFilter | app/src/**/*.py | Filter the files to process in the provided folder |
FunctionMappingDetector | def | Detect a function |
FunctionMappingFilter | (?<=def ).*?(?=() | Filter the function name |
LogDebugDetector | LOG.debug | Detect the log debug message |
LogDebugFilter | (?<=LOG.debug(["']).*?(?=["']) | Filter the log debug message |
LogInfoDetector | LOG.info | Detect the log info message |
LogInfoFilter | (?<=LOG.info(["']).*?(?=["']) | Filter the log info message |
LogWarnDetector | LOG.warn | Detect the log warn message |
LogWarnFilter | (?<=LOG.warn(["']).*?(?=["']) | Filter the log warn message |
LogErrorDetector | LOG.error | Detect the log error message |
LogErrorFilter | (?<=LOG.error(["']).*?(?=["']) | Filter the log error message |
LogCriticalDetector | LOG.critical | Detect the log critical message |
LogCriticalFilter | (?<=LOG.critical(["']).*?(?=["']) | Filter the log critical message |
LogExceptionDetector | LOG.exception | Detect the log exception message |
LogExceptionFilter | (?<=LOG.exception(["']).*?(?=["']) | Filter the log exception message |
中提供的其他配置设置.ini文件包括:
^{tb2}$过程
应用程序的命令按以下逻辑顺序执行。在
process -> generate -> send
例如,在tests/unit/resources/example.py
中处理包含以下内容的文件时:
deflambda_handler(_event:dict,_context):LOG.debug('Initialising')LOG.info('Processing')LOG.warn('Success')LOG.error('Failure')LOG.critical('Bananas')LOG.exception('Exception'))
将返回下一个对象:
[{'subfolder':'resources','filename':'example.py','function':'lambda_handler','type':'debug','query':'message: "Initialising"','label':'debug: Initialising'},{'subfolder':'resources','filename':'example.py','function':'lambda_handler','type':'info','query':'message: "Processing"','label':'info: Processing'},{'subfolder':'resources','filename':'example.py','function':'lambda_handler','type':'warn','query':'message: "Success"','label':'warn: Success'},{'subfolder':'resources','filename':'example.py','function':'lambda_handler','type':'error','query':'message: "Failure"','label':'error: Failure'},{'subfolder':'resources','filename':'example.py','function':'lambda_handler','type':'critical','query':'message: "Bananas"','label':'critical: Bananas'},{'subfolder':'resources','filename':'example.py','function':'lambda_handler','type':'exception','query':'message: "Exception"','label':'exception: Exception'}]
它将为所有找到的日志生成一个带有过滤器的度量可视化。在
这些可视化将按函数、文件名和子文件夹进行拆分。在
您可以通过修改settings.ini中的VisualizationType来更改生成的可视化类型。当前可用值为公制或表格。默认值为公制。在
最后,它使用以下名称格式将生成的可视化发送到Kibana:
[Generated - <folder> <subfolder> <filename> <function> ]
局限性
它不检测分配给变量或常量的日志。它们不会出现在你的视觉化中。#40应该解决这个问题。在
- 项目
标签: