Code Monkey home page Code Monkey logo

jyolo / wlogger Goto Github PK

View Code? Open in Web Editor NEW
505.0 15.0 102.0 5.41 MB

wLogger 是一款集合 日志采集,日志解析持久化存储,web流量实时监控 。三位一体的web服务流量监控应用。 三大功能模块均可独立部署启用互不干扰。目前已内置 nginx 和 apache 的日志解析存储器,简单配置一下,开箱即用。

License: Apache License 2.0

Python 41.56% CSS 1.56% Less 1.71% JavaScript 54.03% HTML 1.03% Dockerfile 0.11%

wlogger's Introduction

介绍

wLogger 介绍

  • 介绍

    wLogger 是一款集合 日志采集,日志解析持久化存储,web流量实时监控 。三位一体的web服务流量监控应用。 三大功能模块均可独立部署启用互不干扰。目前已内置 nginx 和 apache 的日志解析存储器,简单配置一下,开箱即用。 虽然市面上已经很多类似的开源日志采集监控服务比如goaccess,用了一圈之后始终没有一款用的特别舒心。

    • 它可以在日志采集的时候可以按照日志文件的大小,或者在指定时间内自动对日志进行切割日志,存储到指定的目录 (已测2W并发切割日志不丢数据)
    • 它可以不用像goaccess那样必须配置指定格式才能解析到数据,只用指定当前使用的 nginx/apache 日志格式名称 即可解析数据
    • 它可以指定不同的项目走不同的队列服务,分别解析存储到不同的数据库,完全可以自己按需灵活配置
    • 它天然支持分布式,日志采集服务队列已内置redis LIST结构,可自行拓展kafka ,mq等其它队列服务
    • 它支持自定义持久化存储引擎,日志解析持久化存储服务已内置 mongodb 和 mysql ,可自行拓展其它数据库
    • 简单配置,开箱即用,无入侵,高拓展,灵活配置,按需应用
    • 运行环境:python3+ linux平台

    如果该项目有帮助到您,请不要吝啬随手给个star

    您也可以从数据库中取数据自己定义流量监控的UI界面和数据展现方式;

    大屏实时监控效果图 本人显示器太小,截图略显拥挤;

    QQ交流群 : 862251895

    image

功能说明

采集器 inputer

* 实时日志采集,同时支持多个web日志同时采集 
* 可指定按照日志文件大小或指定时间,自动切割文件到指定目录, (日志切割不丢数据.)
* 可自定义队列服务软件,接受采集的日志信息. 已内置redis 如需kafka  等其它mq队列可自行拓展
* 极低的cpu内存占用 ,低配小主机也能愉快的玩耍

解析存储器 outputer

* 实时解析日志并存储到指定的数据库, 已内置 mysql 和 mongodb 如需使用elastic全家桶或其它存储引擎 可自行拓展
* 采集器,解析器,web服务均可 独立分布到不同的服务器节点上运行
* 目前已内置 nginx,apache 解析器, 可随意指定日志格式, 只需在配置文件里面指定格式名称即可正确解析并存储
* 支持按日期天,周,月,年. 自动分表或集合存储日志
* 支持指定工作进程来快速消费队列数据,大流量也能实时解析并存储日志, 虚拟机中ab 实测2W并发延迟小于1秒
* 注: 当海量流量来的时候发现解析存储延迟过高的情况,可将解析器部署到集群中其它多个节点同时消费队列数据,提升解析存储效率


web服务 web

* 已内置大屏监控web面板,流量情况一目了然 
* 同时支持 mysql 或者 mongodb 作为 数据源 

快速开始

安装拓展

sudo pip3 install -r requirements.txt 

启动 采集器

sudo python3 main.py -r inputer -c config.ini

启动 解析存储器

sudo python3 main.py -r outputer -c config.ini

启动 web服务

sudo python3 main.py -r web -c config.ini

查看命令行帮助

python3 main.py --help
  • 以上三个应用均可单独部署和启用
-r --run ; start ['inputer', 'outputer','web']
-s --stop ; stop ['inputer', 'outputer']
-c --config ;  bind config.ini file

docker 支持

docker pull jyolo/wlogger:v1.3 或者 docker build -t yourTagName .

example:
    # 启动 web 服务
    docker run jyolo/wlogger:v1.3 -r web -c config.ini  #  需要把配置文件复制或者挂载进 容器中/wLogger 目录内
    
    # 启动 解析存储器 服务
    docker run jyolo/wlogger:v1.3 -r outputer -c config.ini  #  需要把配置文件复制或者挂载进 容器中/wLogger 目录内
    
* 由于采集器 inputer 中切割日志操作,需要操作容器外部 nginx/apache 相关服务器,因此无法在docker中隔离环境下运行 . 
* 如果容器中有部署nginx 或者 apache 则可以  

配置详解

公共配置

# 当 inputer 和 outputer 中指定了 server_type = nginx 才需此配置  
[nginx]                                         
pid_path = /www/server/nginx/logs/nginx.pid     # 指定 nginx.pid 的绝对路径       
server_conf = /www/server/nginx/conf/nginx.conf # 指定 nginx 配置文件的绝对路径   

# 当 inputer 和 outputer 中指定了 server_type = apache 才需此配置  
[apache]
apachectl_bin = /www/server/apache/bin/apachectl # 指定 apachectl 命令的绝对路径       
server_conf = /www/server/apache/conf/httpd.conf # 指定 apache 配置文件的绝对路径     
    
# 当 inputer 和 outputer 中指定了 queue = redis 才需此配置
[redis]                                               
host = 127.0.0.1
port = 6379
password = xxxxxxxx
db = 1

#  当 outputer 中 save_engine = mysql 或 web 中 data_engine = mysql 才需此配置   
[mysql]                                         
host = 127.0.0.1
port = 3306
username = nginx_logger
password = xxxxxxxx
db = nginx_logger
table = logger
split_save = day                                # 当有该配置项则代表开启自动分表 目前支持按 天,周,月,年 ;参数:[day, week, month ,year] ,进行存储

# 当 outputer 中save_engine = mongodb 或 web 中 data_engine = mongodb 需此配置 
[mongodb]                                       
host = 127.0.0.1
port = 27017
username = logger_watcher
password = xxxxxxxx
db = nginx_logger
collection = logger
split_save = day                                # 当有该配置项则代表开启自动分集合 目前支持按 天,周,月,年 ;参数:[day, week, month ,year] ,进行存储

日志采集端 配置

[inputer]
log_debug = True                       # 开启日志debug模式 会在项目中生成日志文件。 类似 : inputer_config.ini.log   名称的日志文件
node_id = server_80                    # 当前节点ID 唯一
queue = redis                          # 队列配置 目前内置了 [redis , mongodb]
queue_name = queue_logger              # 队列 key 的名称
max_batch_push_queue_size = 5000       # 每次最多批量插入队列多少条数据
max_retry_open_file_time = 10          # 当文件读取失败之后重新打开日志文件,最多重试多少次
max_retry_reconnect_time = 20          # 连接队列失败的时候,最多重试多少次

[inputer.log_file.web1]                # inputer.log_file.web1 中的 web1 代表应用名称 唯一 app_name 
server_type = nginx                    # 服务器应用 [nginx ,apache]
file_path = /wwwlogs/ww.aaa.com.log    # 日志绝对路径
log_format_name = online               # 配置文件中 日志名称 example : "access_log  /www/wwwlogs/xxx.log online;" 中的 `online` 则代表启用的日志配置名称
read_type = tail                       # 读取文件方式 支持 tail 从末尾最后一行开始 ; head 从头第一行开始 * 当文件较大的时候 建议使用 tail 
cut_file_type = filesize               # 切割文件方式 支持 filesize 文件大小单位M ;time 指定当天时间 24:00
cut_file_point = 200                   # 切割文件条件节点 当 filesize 时 200 代表200M 切一次  ; 当 time 时 24:00 代表今天该时间 切一次 
cut_file_save_dir = /wwwlogs/cut_file/ # 日志切割后存储绝对路径


[inputer.log_file.web2]                # 支持同时采集多个应用日志 追加配置即可
..........................

日志解析存储端

[outputer]
log_debug = True                      # 开启日志debug模式 会在项目中生成日志文件。 类似 : outpuer_config.ini.log   名称的日志文件
save_engine = mongodb                 # 解析后的日志存储引擎目前支持 [mysql,mongodb]
queue = redis                         # 队列引擎 此处需要和 inputer 采集端保持一致
queue_name = queue_logger             # 队列中 key 或 collection 集合的名称  此处需要和 inputer 采集端保持一致
server_type = nginx                   # 服务器的类型 
worker_process_num = 1                # 指定工作进程数量 根据自己网站流量情况而定,一般4个worker即可
max_batch_insert_db_size = 1          # 最多每次批量写入存储引擎的数量,根据自己应用情况而定,一般5000即可
max_retry_reconnect_time = 200        # 连接存储引擎失败后,最多重试连接次数

大屏监控端

[web]
env = development                     # 运行环境 development | production
debug = True                          # 是否开启 debug
secret_key = xxxx                     # flask session key 
host = 127.0.0.1                      # 指定ip   
port = 5000                           # 指定端口
server_name = 127.0.0.1:5000          # 绑定域名和端口 (不推荐 ,如果是要nginx反代进行访问的话 请不要配置此项.)
data_engine = mysql                   # 指定读取日志存储数据库引擎 目前内置了 [ mysql , mongodb ]

wlogger's People

Contributors

jyolo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wlogger's Issues

ubuntu下inputer开启不了

image

outputer和web都已经正常运行

outputer因为收不到数据,一直卡着
web已经可以正常访问,接口正常,就是没有数据

页面显示数据异常

页面打开无法显示实时数据

My Question

  • 请教一下,我现在遇到的一个问题就是数据库里面已经有数据了,页面也能打开,但就是无法显示数据,get_total_ip以及get_total_pv等在F12里面都是红色的提醒。

Environment

  • Operating System: Centos 8

VMWare IP

  • 192.168.31.13

Nginx Configuration

  • 192.168.31.13:8080->127.0.0.1:5000

image

数据库表没有自动创建

数据库表没有自动创建
sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1146, "Table 'logger.logger_watcher_2020_12_31' doesn't exist")
[SQL:
select count(*) as total_num ,ua from logger_watcher_2020_12_31
where MATCH(ua) AGAINST('spider')
GROUP BY ua
ORDER BY total_num desc
]
(Background on this error at: http://sqlalche.me/e/13/f405)
微信图片_20201231145612

请问地图上方的信息流 都流向了广东 我可以修改流动目标到其他省份吗 ?

还有一个nginx 路径反代的问题

location /abc {
proxy_pass http://localhost:8899/;
root /path/to/wLogger/webServer;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
}

我用这段代码反向代理 所有静态资源都无法正确加载 只能打开页面

还望大佬赐教 谢谢!

提示online日志格式不存在

2020-12-31 11:38:06 DEBUG /usr/local/src/abc/wLogger/Src/Core.py 353 online日志格式不存在 ; read threading stop pid: 27479
2020-12-31 11:38:06 DEBUG /usr/local/src/abc/wLogger/Src/Core.py 259 online日志格式不存在 ; cutFile threading stop pid: 27479
2020-12-31 11:38:06 ERROR /usr/local/src/abc/wLogger/QueueAdapter/Redis.py 45 online日志格式不存在 ; pushQueue threading stop pid: 27479 ---- tid: 139733623940864
微信图片_20201231113914

log_format_name error

在配置完成启动后,发现日志报错数据解析错误,提示检查client配置中的日志格式名称是否和log_foramt_name一致,我nginx配置默认日志名称为main,log_format_name 设置也为main,请问试什么问题?

pid : 12795 数据解析错误: ('解析日志失败,请检查client 配置中 日志的 格式名称是否一致 log_format_name',) 数据: {"node_id": "server_80", "app_name": "web1", "log_format_name": "main", "line": "192.168.191.4 - [29/Dec/2021:10:50:40 +0800] \"GET / HTTP/1.1\" 304 0 \"-\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36\" \"-\"", "log_format_str": "$remote_addr $remote_user [$time_local] \"$request\" '\n '$status $body_bytes_sent \"$http_referer\" '\n '\"$http_user_agent\" \"$http_x_forwarded_for\"", "log_format_vars": "$remote_addr<@>$remote_user<@>$time_local<@>$request<@>$status<@>$body_bytes_sent<@>$http_referer<@>$http_user_agent<@>$http_x_forwarded_for"}

可否兼容Win平台

试用了一下,效果拔群!
不知是否可以兼容Win平台,在win平台测试时错误
执行命令python main.py -r inputer -c config.ini时
报错
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py", line 315, in _bootstrap
self.run()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "C:\data\wLogger-master\main.py", line 13, in runReader
r = Reader(log_file_conf=log_files_conf ,config_name=config_name)
File "C:\data\wLogger-master\Src\Core.py", line 192, in init
self.server_conf = loggerParse(log_file_conf['server_type'],self.conf[log_file_conf['server_type']]['server_conf']).logger_format
File "C:\data\wLogger-master\Src\Core.py", line 28, in init
self.logger_format = self.__handler.getLoggerFormatByServerConf(server_conf_path=server_conf)
File "C:\data\wLogger-master\ParserAdapter\Nginx.py", line 404, in getLoggerFormatByServerConf
content = fd.read().decode(encoding="utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 4226: invalid start byte

已使用三年,反馈几个小问题

我一直在Windows下使用,将三部分分别注册为inputer outputer web三个服务, 环境为nginx+mongodb,三年来非常稳定,但是有几个问题
1.mongodb有时会占用CPU100%,重启也不能解决,但是只要将outputer服务重启一下问题立刻解决,因为此问题触发几率极低,未能找到原因。

2.近期才发生的问题,我现在的文件存储在mongodb的GridFS Buckets中,通过nginx对外访问。但是现在要访问文件速度非常非常的慢,经常访问失败, 刷新很多次以后才能成功。
前几天偶然把web服务关掉,访问速度立即恢复。然后我又做了多次试验,确定只要关掉web就能保证GridFS的访问速度。
而如果web开着,只有GridFS的访问速度会受影响,数据不受影响。

不知道其他使用者有没有碰到以上问题

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.