使用rsyslog v8.2.2,我想分组多行消息,比如由MySQL Slow Query日志输出的消息。
每条新消息都以连续的三行开头,其中'#'作为行的第一个字符,尽pipe一些消息在消息的开头只有两行有'#'。 ( 我怀疑由PHP的cli,而不是标准的PHP引发的查询,不带# Time:戳 )。 例:
# Time: 140817 0:59:22 # User@Host: root[root] @ localhost [] # Query_time: 5.864315 Lock_time: 0.000033 Rows_sent: 857715 Rows_examined: 857715 SET timestamp=1408237162; SELECT /*!40001 SQL_NO_CACHE */ * FROM `sales_flat_quote_shipping_rate`; # Time: 140817 1:00:06 # User@Host: user2[user2] @ localhost [] # Query_time: 4.070595 Lock_time: 0.000068 Rows_sent: 0 Rows_examined: 1536 use db2; SET timestamp=1408237206; DELETE FROM `catalog_product_index_price_idx`; # User@Host: db3[db3] @ localhost [] # Query_time: 3.892674 Lock_time: 0.046493 Rows_sent: 0 Rows_examined: 659 use db3; SET timestamp=1408237206; UPDATE user SET cert = 'yes' WHERE site_id < 10; # Time: 140817 1:00:06 # User@Host: user2[user2] @ localhost [] # Query_time: 4.070595 Lock_time: 0.000068 Rows_sent: 0 Rows_examined: 1536 use db2; SET timestamp=1408237206; DELETE FROM `catalog_product_index_price_idx`; # User@Host: db3[db3] @ localhost [] # Query_time: 3.892674 Lock_time: 0.046493 Rows_sent: 0 Rows_examined: 659 use db3; SET timestamp=1408237206; UPDATE user SET cert = 'yes' WHERE site_id < 10;
如何configurationrsyslog将它们作为单个消息发送?
Rsyslog可以通过imfile模块将多行日志消息分组为单个消息,但只支持以下三种读取模式:
你的情况不符合这些,所以你不能直接通过rsyslog进行分组。 但是,您可以parsing您的日志文件,并将其转换为rsyslog将能够理解的格式。 简单的shell脚本可以完成这项工作,或者你可以看看logstash等全function的日志pipe理工具。