0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[fluentd][Amazon Linux2] php-fpm のエラーログに Fatal Error が出現したらメール送信する

Last updated at Posted at 2021-06-22

メモです。
Fluentd の連携先としてメールしか選べないシステムだったので...

Amazon Linux2 への fluentd のインストール

curl -L https://toolbelt.treasuredata.com/sh/install-amazon2-td-agent4.sh | sh
sudo td-agent-gem install fluent-plugin-mail

/etc/td-agent/td-agent.conf

<source>
  type tail
  path /var/log/php-fpm/error.log
  tag php-fpm.error
  pos_file /var/log/td-agent/php-fpm-error_log.pos
  format none
  read_from_head true
</source>

<source>
  type tail
  path /var/log/php-fpm/www-error.log
  tag php-fpm.www-error
  pos_file /var/log/td-agent/php-fpm-www-error_log.pos
  format none
  read_from_head true
</source>

<match **>
  @type copy
  <store>
    @type stdout
    @id @all.logging
  </store>
  <store>
    @type relabel
    @label @handle.error
  </store>
</match>

<label @handle.error>
  <filter **>
    @type record_transformer
    <record>
      host ${hostname}
    </record>
  </filter>

  <filter **>
    @type grep

    <regexp>
      key message
      pattern /Fatal error/i
    </regexp>
  </filter>

  <match **>
    @type mail
    host localhost
    port 25
    from no-reply@example.com
    to alert@example.com

    subject "PHP Fatal Error"

    out_keys host, message
  </match>
</label>

source は /var/log/php-fpm/error.log/var/log/php-fpm/www-error.log

stdout と @handle.error に copy

@type record_transformer で host レコードを追加

@type grepFatal error が含まれる行だけを抽出

@type mail でメール送信

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?