LoginSignup
10

More than 5 years have passed since last update.

fluent-plugin-twitter & fluent-plugin-datacounter

Last updated at Posted at 2013-03-08

fluent-plugin-twitter

y-ken さんが公開して下さっている fluent-plugin-twitter を使うと tweetstream gem を使って streaming api でツイートを受信して fluentd で扱うことができるようになる。

fluent-plugin-datacounter

tagomoris さんが公開して下さっている fluent-plugin-datacounter を使うと指定した時間内に正規表現にマッチするログが何件あるかを数えてその結果を fluentd で扱うことができるようになる。

ツイート数をリアルタイムにカウントする

今回はこの二つを使って、あるアカウントのホームタイムラインのツイートをカウントして mongodb に保存してみたい。

fluentd.conf
## fluentd conf

# fluent-plugin-twitter の設定
<source>
  type twitter
  consumer_key        ***
  consumer_secret     ***
  oauth_token         ***
  oauth_token_secret  ***
  tag                 input.twitter.test
  timeline            userstream
  output_format       nest
</source>

# fluent-plugin-datacounter の設定
<match datacount.**>
  type copy
  <store>
    type mongo
    host        localhost
    database    fluentd-test
    collection  datacountsample
  </store>
  <store>
    type stdout
  </store>
</match>

# 受信したツイートを処理する設定
<match input.twitter.**>
  type copy
  <store>
    type datacounter
    tag  datacount.twitter.5m
    count_interval 5m
    aggregate all 
    input_tag_remove_prefix input.twitter.test
    output_messages  true

    # ここの設定は変える必要ある
    count_key id_str
    pattern1 tweet ^\d*
  </store>
  <store>
    type mongo
    host        localhost
    database    fluentd-test
    collection  twittersample
  </store>
</match>

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
10