从文件导入记录器消息并生成Kibana可视化

logger-to-kibana的Python项目详细描述


基巴纳伐木工人

Build Status


集成此项目以根据遇到的日志消息生成视图。在

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文件中更改。在

目前可用的探测器有:

DetectorDefault ValuePropose
FilesMatchFilterapp/src/**/*.pyFilter the files to process in the provided folder
FunctionMappingDetectordefDetect a function
FunctionMappingFilter(?<=def ).*?(?=()Filter the function name
LogDebugDetectorLOG.debugDetect the log debug message
LogDebugFilter(?<=LOG.debug(["']).*?(?=["'])Filter the log debug message
LogInfoDetectorLOG.infoDetect the log info message
LogInfoFilter(?<=LOG.info(["']).*?(?=["'])Filter the log info message
LogWarnDetectorLOG.warnDetect the log warn message
LogWarnFilter(?<=LOG.warn(["']).*?(?=["'])Filter the log warn message
LogErrorDetectorLOG.errorDetect the log error message
LogErrorFilter(?<=LOG.error(["']).*?(?=["'])Filter the log error message
LogCriticalDetectorLOG.criticalDetect the log critical message
LogCriticalFilter(?<=LOG.critical(["']).*?(?=["'])Filter the log critical message
LogExceptionDetectorLOG.exceptionDetect 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应该解决这个问题。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java的单元测试测试用例库。util。列出实现   java通过超类进行序列化/反序列化   java Android获取设备语言ISO字符串   java如何打开广告的行动。移动   Eclipse IDE for(嵌入式C/C++)开发者202012:经典的深色主题深黑色背景和菜单中的文本   java使用不同的内容动态创建TableView(JavaFX)   java JAXB将多个同名节点解组   java ClassDefNotFoundException,即使类由类加载器加载(服务器上安装了多个应用程序)   java有没有办法关闭在后端生成的MqttClient线程?   html如何在网站上的java小程序中包含图像?   java无法访问已分配给超类引用的子类实例变量   java在TableViewer中双击打开对话框   列出如何创建ListNode。JAVA   java如何从文本中输出的数组中放入随机图像