Python 实现日志中心
Python 实现日志中心
什么是日志中心?
日志中心是针对日志类数据一站式管理,日志中心分成两部分,分别是采集端和收集端。 采集器从各服务器采集数据,然后发送给接收端,接收端接到数据后,将日志保存到磁盘上。用户能在日志中心服务器上查询和分析日志,帮助运维、运营提升效率。 当年我开发此程序的时候还没有出现如今流行的ELK方案,接下来就让我为大家介绍如何使用 Python 开发一个日志采集和接受程序。
工作原理
日志采集端:有两种工作方式:一种是文件采集,另一种是标准输出采集。文件采集又分为,静态日志文件采集,将整个文件给接收端。动态文件采集,仅采集添加到日志文件尾部的更新内容,即每次只读取日志追加的内容。 日志接收端: 启动后进入后台,开启UDP端口,等候采集端发送内容。
安装
pip 安装
[root@localhost ~]# pip3 install netkiller-logging
源码安装
[root@localhost ~]# git clone https://github.com/netkiller/logging.git
[root@localhost ~]# cd logging
[root@localhost ~]# python3 setup.py sdist
[root@localhost ~]# python3 setup.py install
命令
日志采集端
日志采集端名师是 rlog
[root@localhost ~]# whereis rlog
rlog: /usr/local/bin/rlog
[root@localhost ~]# rlog
Usage: rlog [options] filename
Options:
-h, --help show this help message and exit
-H localhost, --host=localhost
push log to remote host
-p 1214, --port=1214 port
--sleep=0.05 with -s, sleep for approximately S seconds between
iterations
-d, --daemon run as daemon
-f, --full Full text
--stdin cat file | prog ...
-e /tmp/rlog.log, --errlog=/tmp/rlog.log
error log
--postion save postion of log file
Homepage: http://netkiller.github.io Author: Neo <netkiller@msn.com>
日志接收端
日志接收端命令式 collection
[root@localhost ~]# collection
Usage: collection [options] module
Options:
-h, --help show this help message and exit
-p 1214, --port=1214 port