Collect php-fpm slow log using Logstash

Source: Internet
Author: User
Tags php error php error log syslog logstash
Currently PHP-FPM services are deployed in Docker, PHP-FPM log and PHP error log can be sent through the Syslog protocol, while PHP-FPM's slow log cannot be configured as a syslog protocol, only output to a file, Because a slow log is composed of multiple lines.

In order to collect slow log, can be collected through Logstash, Flume and other tools, this article uses Logstash to collect the slow log, and writes the collected log to Kafka for easy follow-up processing. Logstash input takes the form of a read file, which is similar to the tail-f principle. In order to be able to use multiple lines of log as a row, the multiline in filter is used to merge multiple rows of logs. The configuration of the Logstash is as follows:

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"    }}
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.