LoginSignup
38
41

More than 5 years have passed since last update.

Fluentdを使ってRDSのSlowLogをSlackに通知する

Last updated at Posted at 2015-07-06

これはなにか

RDSのSlowLogをSlackに通知したかった。
AWSのAPIで download-db-log-file-portion があったが通知するには使い勝手が悪かったので
MySQLのテーブルにSlowLogを保存して、それをFluentdからSELECT & Clear をすることにした。
この記事はMysqlの設定なので、他のDBの場合はよしなに変更してください。

使ったもの

fluent-plugin-slack : https://github.com/sowawa/fluent-plugin-slack
fluent-plugin-rds-slowlog : https://github.com/kenjiskywalker/fluent-plugin-rds-slowlog

RDSの設定

  • Parameter Group

    • slow_query_log : 1
    • long_query_time : ?秒(ご自由に)
    • log_output : TABLE
  • ユーザー作成

    • CREATE USER hoge;
    • SET PASSWORD FOR 'hoge'@'%' = PASSWORD('hogehoge');
    • GRANT select ON mysql.slow_log TO hoge;
    • GRANT EXECUTE ON PROCEDURE mysql.rds_rotate_slow_log TO hoge;

Slackの設定

  • IncomingWebHookでWebhookURL取得

Fluentdの設定

<source>
  type rds_slowlog
  tag rds.slow_query
  host ****************************.ap-northeast-1.rds.amazonaws.com
  username hoge
  password hogehoge
</source>

<match rds.slow_query>
  type buffered_slack
  webhook_url [WebhookURL]
  channel [channel名]
  username [通知ユーザー名]
  color danger
  message "start_time:%s\r\nuser_host:%s\r\nquery_time:%s\r\nlock_time:%s\r\nrows_sent:%s\r\nrows_examined:%s\r\ndb:%s\r\nlast_insert_id:%s\r\ninsert_id:%s\r\nserver_id:%s\r\nsql_text:%s"
  message_keys start_time,user_host,query_time,lock_time,rows_sent,rows_examined,db,last_insert_id,insert_id,server_id,sql_text
  flush_interval 1m
</match>

通知されたもの

スクリーンショット 2015-07-06 11.07.25.png

最後に

そのまま使うと危険なので適当に変更してください。

38
41
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
38
41