Postfixのログの「status=...」の行をfluentdに流そうと思ったんですよ。
要件としては
- メアドはマスクしたい
- メアドからドメインとりたい
- statusは値と詳細に分けたい
- 大量にメールが流れるので早くしたい
それで何も考えずにCの拡張ライブラリを作って、それでflunetdのプラグインを書いたんですよ。
以下のような感じで、fluentdにログを流せます。
<source>
@type tail
path /var/log/mail.log
pos_file /var/log/td-agent/postfix-mail.log.pos
tag postfix.mail
format none
</source>
<filter postfix.mail>
@type grep
regexp1 message status=
</filter>
<filter postfix.mail>
@type parse_postfix
</filter>
<match postfix.mail>
@type stdout
</match>
ただ、そもそも既存の処理のベンチマークを取っていなかったので、EC2/t2.microで速度を測ったんですよ。
ちなみに、正規表現は以下の記事を参考にしました。
SIOS ビッグデータ技術ブログ: Postfixのログをfluentdを使ってTreasureDataに送る
で、結果が次の通り。
user system total real
07:09:55 psl(1): 2.450000 0.000000 2.450000 ( 2.450314)
07:09:58 psl(2): 2.460000 0.000000 2.460000 ( 2.464074)
07:10:00 psl(3): 2.830000 0.000000 2.830000 ( 2.834007)
07:10:03 psl(4): 2.500000 0.000000 2.500000 ( 2.505221)
07:10:05 psl(5): 2.570000 0.000000 2.570000 ( 2.565137)
>sec/prs: 0.000005 0.000000 0.000005 ( 0.000005)
>prs/sec: 195160.031226 Inf Inf (195026.773633)
user system total real
07:10:11 psl+m(1): 2.620000 0.000000 2.620000 ( 2.623226)
07:10:14 psl+m(2): 2.610000 0.000000 2.610000 ( 2.600343)
07:10:16 psl+m(3): 2.590000 0.000000 2.590000 ( 2.594375)
07:10:19 psl+m(4): 2.560000 0.000000 2.560000 ( 2.557504)
07:10:21 psl+m(5): 2.560000 0.000000 2.560000 ( 2.563402)
>sec/prs: 0.000005 0.000000 0.000005 ( 0.000005)
>prs/sec: 193199.381762 Inf Inf (193216.547290)
user system total real
07:10:27 rgx(1): 6.420000 0.000000 6.420000 ( 6.423937)
07:10:33 rgx(2): 6.410000 0.000000 6.410000 ( 6.402610)
07:10:40 rgx(3): 6.410000 0.000000 6.410000 ( 6.415075)
07:10:46 rgx(4): 6.470000 0.000000 6.470000 ( 6.465956)
07:10:53 rgx(5): 6.560000 0.000000 6.560000 ( 6.564861)
>sec/prs: 0.000013 0.000000 0.000013 ( 0.000013)
>prs/sec: 77471.335606 Inf Inf (77465.479252)
user system total real
07:11:02 rgx+m(1): 7.110000 0.000000 7.110000 ( 7.110184)
07:11:09 rgx+m(2): 6.940000 0.000000 6.940000 ( 6.938133)
07:11:16 rgx+m(3): 6.970000 0.000000 6.970000 ( 6.968497)
07:11:23 rgx+m(4): 7.150000 0.000000 7.150000 ( 7.157125)
07:11:30 rgx+m(5): 6.950000 0.000000 6.950000 ( 6.945317)
>sec/prs: 0.000014 0.000000 0.000014 ( 0.000014)
>prs/sec: 71184.510251 Inf Inf (71186.016988)
秒間19万行をパースする速度が必要だったかといえばそんなわけはなく。
Rubyは十分速いなぁ…先に速度測れよなぁ…という教訓が得られました。