fluent-plugin-datacalculatorを作りました
muddydixon/fluent-plugin-datacalculator · GitHub
fluent-plugin-datacalculator | RubyGems.org | your community gem host
id:tagomoris さんのをパクってにインスパイアされて、簡単な演算をしながら指定した時間単位で集計をしてくれるプラグインです。また、特定のキーの組み合わせを1つのレコードとして出力することもできます(aggregate tagではなく、aggregate keyのイメージです)
<match payment.quest> type datacalculator tag result.quest count_interval 5s aggregate keys area_id, mission_id formulas sum = amount * price, cnt = 1, total = amount finalizer ave = cnt > 0 ? 1.00 * sum / cnt : 0 <unmatched> type file path unmatched </unmatched> </match>
この設定ファイルのfluentdに
{area_id: 3, mission_id: 1, amount: 1, price: 300, item_name: "回復薬大"} {area_id: 2, mission_id: 3, amount: 3, price: 200, item_name: "回復薬中"} {area_id: 3, mission_id: 1, amount: 5, price: 100, item_name: "回復薬小"} {area_id: 1, mission_id: 1, amount: 1, price: 300, item_name: "回復薬大"} {area_id: 1, mission_id: 1, amount: 3, price: 200, item_name: "回復薬中"} {area_id: 2, mission_id: 2, amount: 5, price: 100, item_name: "回復薬小"}
みたいなのを流すと
{area_id: 3, mission_id: 1, sum: 800, cnt: 2, total: 6, ave: 400} {area_id: 2, mission_id: 3, sum: 600, cnt: 1, total: 3, ave: 600} {area_id: 1, mission_id: 1, sum: 900, cnt: 2, total: 4, ave: 225} {area_id: 2, mission_id: 2, sum: 500, cnt: 1, total: 5, ave: 500}
のように集計されて出てきます。
複数のCPUのログを足しあわせたどうのこうの、とか、購買ログがどうのこうのとか、そういう人は試してみてください!