LoginSignup
9
9

More than 5 years have passed since last update.

Raspberry Pi の温度センサーデータを fluentd で Treasure Data に集める

Posted at

温度データがとれたので fluentd で Treasure Data に入れてみたときのメモ。

fluent-plugin-td インストール

以前インストールした fluentd は gem 版なので、Treasure Data のプラグインをインストールする。

Console
$ sudo fluent-gem install fluent-plugin-td

Treasure Data の API キーを確認する

アカウント作成

ここからサインアップしてアカウントを作成する。

API キー確認

Treasure Data のコンソールMy profile にいってパスワードを入れて API キーを確認する。

fluentd 設定

以前 Raspberry Pi につけた温度センサー(DS18B20)は 1 エントリ 2 行出力される。
今回は in-exec でやってみた。

/etc/fluent/fluentd.conf
<source>
  type exec
  command tail -1 /sys/bus/w1/devices/28-00000xxxxxxx/w1_slave | awk '{print substr($10,3)}'
  tag td.myapp.temp
  format tsv
  keys temp
  run_interval 10s
</source>

<match td.*.*>
  type tdlog
  apikey YOUR_API_KEY
  auto_create_table
  buffer_type file
  buffer_path /var/log/td-agent/buffer/td
  flush_interval 1m
  use_ssl true
</match>
  • in-exec で {"temp":"24500"} といったデータを取り込む。
  • 温度計測タイミングは run_interval で、Treasure Data への送信は flush_interval でコントロールする。
  • auto_create_table によりタグ名から Treasure Data 上にデータベースとテーブルを自動的に作成してくれる。上記の場合、データベースは myapp、テーブルは temp となる。

反映には fluentd を再起動する。

buffer 出力先のディレクトリを作成する。また、オーナを fluentd 実行ユーザにする。

Pi
$ sudo mkdir /var/log/td-agent/buffer
$ sudo chown -R fluentd:fluentd /var/log/td-agent

動作確認

しばらくすると(flush_intervalの設定時間) Treasure Data コンソールの Databases にデータベースが追加されている。
テーブルの中にデータが書き込まれていればOK。

参考

9
9
0

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
9
9