Help us understand the problem. What is going on with this article?

Kibana Dashboard by using Logstash Twitter Module

1. 目的

LogStashのTwitter Moduleを活用してKibanaのダッシュボード画面を作成する。

2. 設定方法

TwitterのAPIの取得方法を参照して、自身のTwitterアカウントから以下情報を取得する。

・consumer_key
・consumer_secret 
・oauth_token
・oauth_token_secret

上記情報を用いて、/etc/logstash/conf.dに下記ファイル名で作成する。

input {
  twitter {
    # TwittrAPI Authentication infomation
    consumer_key => "XXXXX"
    consumer_secret => "XXXXX"
    oauth_token => "XXXXX"
    oauth_token_secret => "XXXXX"
    # indicate specific keyword 
    keywords => ["fiba"] #FIBAのWordをもつTweetを抽出
    full_tweet => true #公開対象の全てのTweetを参照
  }
}
output {
  elasticsearch {
    # ElasticSearchのHost Pass
    hosts => ["http://localhost:9200/"]
    # Index Name
    index => "fiba_tweet"
  }
}
  • Twitter input pluginを確認する限り、consumer_key、consumer_secret、oauth_token、oauth_token_secretは必須設定項目であり、それ以外はオプションの項目である。

  • オプション項目の設定の意味は以下の通り。full_tweetを有効化にすることで取得可能な全てのTweet情報を収集して、keywordsで必要となるキーワードを指定する。複数指定の場合はAND検索となり、ワイルドカードオプションなどは使用できない。

full_tweet:edit Value type is boolean Default value is false Record full tweet object as given to us by the Twitter Streaming API.```

keywords:Value type is arrayThere is no default value for this setting.
Any keywords to track in the Twitter stream. For multiple keywords, use the syntax ["foo", "bar"].
There’s a logical OR between each keyword string listed and a logical AND between words separated by spaces per keyword string.
The wildcard "*" option is not supported. To ingest a sample stream of all tweets, the use_samples option is recommended.

上記情報を用いて、/etc/logstash/conf.dに下記ファイル名で作成する。 multiple piplineを用いて/etc/logstash/conf.d/以下のconfファイルを全て読み込むように指定する。

# This file is where you define your pipelines. You can define multiple.
# For more information on multiple pipelines, see the documentation:
#   https://www.elastic.co/guide/en/logstash/current/multiple-pipelines.html

- pipeline.id: main
  path.config: "/etc/logstash/conf.d/*.conf" #ここで読み込みファイルを指定する。

下記引用によるとデフォルトで(引数なしで)logstashを実行すると、自動的にpipline.confを読み込んで実行する。

If you need to run more than one pipeline in the same process, Logstash provides a way to do this through a configuration file called pipelines.yml. This file must be placed in the path.settings.
When you start Logstash without arguments, it will read the pipelines.yml file and instantiate all pipelines specified in the file. On the other hand, when you use -e or -f, Logstash ignores the pipelines.yml file and logs a warning about it.

logstashを実行する。

systemctl start logstash

すると、指定したIndex(= fiba_tweet)でデータが蓄積されていく。

キャプチャ2.PNG

お試しでDashboard画面を作成した。2019年9月15日はFIBA Basket Ball World cup 2019の決勝戦(スペイン vs. アルゼンチン)の日であるため、「FIBA」というキーワードでどれだけ引っかかるかを検証した。
FIBAをみて盛り上がった時間帯(頻繁にTweetされた時間帯)や、Tweetした人の情報(国籍や仕様言語など)の情報を可視化することができた。

キャプチャ.PNG

3.その他パラメータ

keywordの選択によっては多くのデータ量がelasticsearchに格納されるため、sapmlesetは有効かもしれない。

full_tweetedit
Value type is boolean
Default value is false
Record full tweet object as given to us by the Twitter Streaming API.

ignore_retweetsedit
Value type is boolean
Default value is false
Lets you ignore the retweets coming out of the Twitter API. Default ⇒ false

keywordsedit
Value type is array
There is no default value for this setting.
Any keywords to track in the Twitter stream. For multiple keywords, use the syntax ["foo", "bar"]. There’s a logical OR between each keyword string listed and a logical AND between words separated by spaces per keyword string. See h
The wildcard "*" option is not supported. To ingest a sample stream of all tweets, the use_samples option is recommended.

languagesedit
Value type is array
There is no default value for this setting.
A list of BCP 47 language identifiers corresponding to any of the languages listed on Twitter’s advanced search page will only return tweets that have been detected as being written in the specified languages.

locationsedit
Value type is string
There is no default value for this setting.
A comma-separated list of longitude, latitude pairs specifying a set of bounding boxes to filter tweets

proxy_addressedit
Value type is string
Default value is "127.0.0.1"
Location of the proxy, by default the same machine as the one running this LS instance

proxy_portedit
Value type is number
Default value is 3128
Port where the proxy is listening, by default 3128 (squid)

use_samplesedit
Value type is boolean
Default value is false
Returns a small random sample of all public statuses. The tweets returned by the default access level are the same, so if two different clients connect to this endpoint, they will see the same tweets. If set to true, the keywords, follows, locations, and languages options will be ignored. Default ⇒ false

以上

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away