LoginSignup
2
3

More than 5 years have passed since last update.

fluentdで集めたログをslackやelasticsearchに流すための設定メモ

Last updated at Posted at 2015-10-31

事前準備

使ったfluentdのプラグイン

slackのwebhookの設定

slack_webhook.png

http://xxxx.slack.com/services/newの下の方にある「incomming WebHooks」のリンクからwebhook urlの情報を取得します

fluent.confの設定

fluent.conf

<source>
  type tail
  path log/rails_application_development.log
  tag slack
  format multiline
  format_firstline /^., /
  format1 /^., \[(?<time>[^\.]+).+\][ ]+(?<level>[^ ]+) -- :(?<message>.*)$/
  time_format %Y-%m-%dT%H:%M:%S
</source>

<match rails.*>
  host 192.***.**.***
  port 9200
  index_name famiphoto 
  type_name fluentd
  type elasticsearch
</match>

<match slack>
  type slack
  webhook_url https://hooks.slack.com/services/***********/*********
  channel general
  username rails_dog
  flush_interval 5s
  icon_emoji :dog:
  message_keys level,message
  message "[%s] %s"
</match>

elasticsearchにログを入れる設定と同じくslackにapplicationログの内容を通知する設定。実際はslackに通知するのはエラーの場合だけでいいけど。
一旦はメモとして残す。

同じ要領でslow-logも通知するようにする。

mysqlのスローログを通知する設定(仮)

my.cnfにスローログをファイルに出す設定にしておいて、fluent.confを編集します。

fluent.conf
<source>
  type mysql_slow_query
  path log/mysql_query.log
  tag mysql_slow_query_slack_notifier
</source>

<match mysql_slow_query_slack_notifier>
  type slack
  webhook_url https://hooks.slack.com/services/***********
  channel general
  username mysql_slowlog_ghost
  icon_emoji :ghost:
  color danger
  message "Query_time:%s\r\nLock_time:%s\r\nRows_sent:%s\r\nRows_examined:%s"
  message_keys Query_time,Lock_time,Rows_sent,Rows_examined
  flush_interval 1m
</match>

こんな感じになります。color dangerを指定しているのでslack上で赤い表示がされます。

2
3
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
2
3