Github
これなんだ
Fluentdを使ってMysqlのテーブルのスキーマ変更とテーブル追加、削除をフィルタリングするするプラグインを書いた
Databaseのマイグレーションがしっかりできている場合必要ないかもしれない。
使い方
テーブルのスキーマ変更を検知する場合
<source>
type in_mysql_table
tag mysql.table
host mysqlserver
username username
password password
database database_name
port 3306
interval 60 # SHOW TABLES FROM #{@database} が走るinterval
</source>
<filter mysql.table>
type change_mysql_table
host mysqlserver
username username
password password
port 3306
interval 1 # SHOW CREATE TABLE #{table_name} が走るinterval
database database_name
</filter>
<match mysql.table>
type stdout
</match>
こんな感じのQuery流す
ALTER TABLE `moge` ADD `hoge` INT NULL DEFAULT NULL AFTER `id`;
2015-08-11 09:48:34 +0000 mysql.table: ["moge"]
テーブルが追加、削除されたの検知する場合
<source>
type in_mysql_table
tag mysql.table
host mysqlserver
username username
password password
database database_name
port 3306
interval 60
</source>
<filter mysql.table>
type change_prev_record
</filter>
<match mysql.table>
type stdout
</match>
こんな感じのQuery流す
CREATE TABLE `moge` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2015-08-11 09:48:34 +0000 mysql.table: ["moge"]
最後に
change_prev_recordは前回のmessageとの違いを出してるだけなので、別のプラグインかなーとも思った。
Plugin書くのも非情に簡単でFluentd便利ですね。
pull reqお待ちしております!