Home > Backend Development > PHP Tutorial > 使用logstash收集php-fpm slow log

使用logstash收集php-fpm slow log

WBOY
Release: 2016-06-20 12:26:06
Original
1405 people have browsed it

目前php-fpm的服务部署在了docker中,对php-fpm的log和php error log可以通过syslog协议的形式发送出去,而php-fpm的slow log却不能配置为syslog协议,只能输出到文件中,因为一条slow log的是有多行组成的。

为了收集slow log,可以通过logstash、flume等工具进行收集,本文采用logstash对slow log进行收集,并将收集的log写入到kafka中,便于后续的处理。logstash的input采用读取文件的方式,即跟tail -f的原理类似。为了能够将多行日志作为一行,采用了filter中的multiline来对多行日志进行合并操作。logstash的配置如下:

input {    file {        path => [“/var/log/php-fpm/fpm-slow.log"]    }}filter {    multiline {        pattern => "^$"        negate => true        what => "previous"    }}output {    stdout{codec => rubydebug}    kafka {        codec => plain {           format => “tag|%{host}%{message}"        }        topic_id => "fpm-slowlog"        bootstrap_servers => “kafka1.hostname:8082,kafka2.hostname:8082"    }}
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template