Armadillo
Armadillo-Box WS1
Armadillo-Box WS1 はカーネルもユーザーランドも Armadillo-IoT と共通点が多く、
ROM イメージのサイズに注意すれば Armadillo-IoT で動作するアプリケーションは
ほとんど動作させることができます。
Armadillo-Box WS1/BLE対応 と Armadillo-Box WS1/Wifi対応 を加えた Armadillo-Box WS1 で
flunetd を動作させ、BLE 経由で集めたデータをログ収集用のサーバーへ送信するための変更手順を
以下に記します。
fluentd でサーバへ送信するデータは、Bluetooth Low Energy で専用アプリケーションが収集し、
以下のようなフォーマットで atmark dist の syslog が出力される /var/log/messages へ定期的に書き込まれるものとします。
tempgw が syslog へ出力するデータ収集アプリ名、ADV は BLE デバイスの MACアドレス、serial は複数から受信している場合の識別ID、
temp は温度、rssi は受信強度です。
Nov 30 15:00:43 (none) user.info tempgw: ADV: E0:40:56:7E:2A:DC serial:3 temp:25.125000 rssi:-79
これを fluentd の tail plugin で読み込み、適切にフォーマットしてサーバーの受信用 fluentd に送信します。
syslog plugin を使ってしまうと format せず message: に全体がそのまま入ってしまい、
データ利用のための検索がしにくいなどの問題があるため tail plugin を使用します。
atmark dist の make menuconfig で fluentd 関連ファイルを追加します。
vendor/Product を指定します。
(AtmarkTechno) Vendor (Armadillo-Box WS1) AtmarkTechno Products
ユーザーランドのコンフィギュレーションを行い、 flunetd と fluentd に必要なものを有効にします。
[*] Customize Vendor/User Settings (NEW)
Miscellaneous Applications --->
:
:
--- extension
:
:
[*] ruby <-- チェックをいれ有効にする
(2.1.2) Version <-- 2.1.2 にする。2.0.0-p451 だと flunetd 他のビルドがエラーになる。
[*] fluentd <-- ruby にチェックをいれると表示されるので、チェックをいれ有効にする
:
[*] http_parser.rb <-- ruby にチェックをいれると表示されるので、チェックをいれ有効にする
[*] ruby-cool.io <-- ruby にチェックをいれると表示されるので、チェックをいれ有効にする
:
[*] ruby-macaddr <-- ruby にチェックをいれると表示されるので、チェックをいれ有効にする
:
[*] ruby-sigdump <-- ruby にチェックをいれると表示されるので、チェックをいれ有効にする
[*] ruby-systemu <-- ruby にチェックをいれると表示されるので、チェックをいれ有効にする
[*] ruby-string-scrub <-- ruby にチェックをいれると表示されるので、チェックをいれ有効にする
[*] ruby-thread_safe <-- ruby にチェックをいれると表示されるので、チェックをいれ有効にする
[*] ruby-tzinfo <-- ruby にチェックをいれると表示されるので、チェックをいれ有効にする
[*] ruby-tzinfo-data <-- ruby にチェックをいれると表示されるので、チェックをいれ有効にする
:
[*] msgpack-ruby <-- ruby にチェックをいれると表示されるので、チェックをいれ有効にする
:
[*] yajl-ruby <-- ruby にチェックをいれると表示されるので、チェックをいれ有効にする
:
:
:
上記の変更を反映したカーネルとユーザーランドを一旦ビルドします。
atmark@atde5:~/atmark-dist$ make clean atmark@atde5:~/atmark-dist$ make
ROM イメージディレクトリの /etc に fluentディレクトリを作成し、そこに fluent.conf を配置します。
ただし、 ramfs で起動する atmark dist の特徴として /etc/config/ 以下か microSD や USBメモリなどの外部ストレージにしか
起動後の変更内容を保存できないので、設定ファイルへの変更修正を保存できるよう
/etc/fluent/fluent.conf は /etc/config/fluent.conf への symlink として作成します。
atmark@atde5:~/atmark-dist$ cd romfs/etc atmark@atde5:~/atmark-dist/romfs/etc$ mkdir fluent atmark@atde5:~/atmark-dist/romfs/etc$ cd fluent atmark@atde5:~/atmark-dist/romfs/etc/fluent$ ln -s /etc/config/fluent.conf fluent.conf
また、/etc/config/ 以下の設定ファイルは初回起動時に /etc/default/ 以下のものがコピーされて
Armadillo-Box 本体内フラッシュメモリの config 保存領域に保存されるので、
fluent.conf の実体は /etc/default/ の下に保存しておきます。
atmark@atde5:~/atmark-dist/romfs/etc/fluent$ cd ../default/ atmark@atde5:~/atmark-dist/romfs/etc/default$ cp ~/atmark-dist/user/fluentd/fluent.conf .
fluent.conf の配置が完了したら、上記の設定ファイル配置変更を含むユーザーランドのイメージを再度作成します。
atmark@atde5:~$ cd atmark-dist atmark@atde5:~/atmark-dist$ make image
Armadillo-Box WS1 がネットワークに接続してある場合に一番速い書き換え方法である
12.4. TFTPを使用してフラッシュメモリを書き換える
http://manual.atmark-techno.com/armadillo-box-ws1/armadillo-box-ws1_product_manual_ja-1.0.0/ch12.html#sct.update_image-with-tftpdl
でカーネルとユーザーランドを再作成したものに書き換えます。
hermit> tftpdl 192.168.0.90 192.168.0.164 --blksize=1024 --kernel=linux.bin.gz hermit> tftpdl 192.168.0.90 192.168.0.164 --blksize=1024 --userland=romfs.img.gz
新しいカーネルとユーザーランドで起動しネットワークに正常に接続できることを確認したら、
まず時間を合わせます。
[root@abws1-0 (pts/0) ~]# ntpclient -h ntp.nict.jp -s 25567 00180.848 8769.0 0.8 1448951602547493.0 0.0 0 [root@abws1-0 (pts/0) ~]# date Tue Nov 25 15:36:24 JST 2015
fluent.conf を以下の内容にします。
<source>
@type tail
format /^(?<time>[^ ]* [^ ]* [^ ]*) (?<host>[^ ]*) (?<class>[^ ]*) (?<ident>[^ ]*): .*: (?<ADV>([A-Z0-9]{2}[:]){5}([A-Z0-9]{2})) .*:(?<temp>[0-9]{2}[\.][0-9]{6}) (?<message>.*)$/
time_format %b %d %H:%M:%S
path /var/log/messages
pos_file /var/tmp/mesagges.pos
types temp:float
tag syslog.ble
</source>
<match syslog.**>
@type copy
<store>
@type forward
heartbeat_interval 60s
heartbeat_type tcp
flush_interval 60s ##600s at realuse
buffer_type file
buffer_path /var/tmp/in_ble_app.syslog.*.buffer
buffer_chunk_limit 3072k
buffer_queue_limit 425
retry_wait 2s
max_retry_wait 1h
retry_limit 72 # retry count
<server>
host 192.168.0.80
port 24224
</server>
</store>
<store>
type stdout
</store>
</match>
fluentd をデバッグオプション付きでフォアグラウンド実行してみます。
[root@abws1-0 (pts/0) ~]# fluentd -c /etc/fluent/fluent.conf -vv
2015-11-25 16:09:28 +0900 [info]: fluent/supervisor.rb:341:read_config: reading config file path="/etc/fluent/fluent.conf"
2015-11-25 16:09:29 +0900 [info]: fluent/supervisor.rb:239:supervise: starting fluentd-0.12.2
2015-11-25 16:09:30 +0900 [trace]: fluent/plugin.rb:98:register_impl: registered buffer plugin 'file'
2015-11-25 16:09:30 +0900 [trace]: fluent/plugin.rb:98:register_impl: registered buffer plugin 'memory'
〜〜 中略 〜〜
2015-12-01 16:09:37 +0900 [info]: fluent/agent.rb:123:add_match: adding match pattern="syslog.**" type="stdout"
2015-12-01 16:09:37 +0900 [info]: fluent/root_agent.rb:142:add_source: adding source type="tail"
2015-12-01 16:09:37 +0900 [info]: plugin/in_tail.rb:474:initialize: following tail of /var/log/messages
2015-12-01 16:09:56 +0900 syslog.ble: {"host":"(none)","class":"user.info","ident":"tempgw","ADV":"ED:B2:9F:B5:70:CD","serial":"1","temp":27.375,"message":"rssi:-57"}
2015-12-01 16:10:56 +0900 syslog.ble: {"host":"(none)","class":"user.info","ident":"tempgw","ADV":"ED:B2:9F:B5:70:CD","serial":"1","temp":27.25,"message":"rssi:-59"}
2015-12-01 16:11:56 +0900 syslog.ble: {"host":"(none)","class":"user.info","ident":"tempgw","ADV":"ED:B2:9F:B5:70:CD","serial":"1","temp":27.25,"message":"rssi:-59"}
stdout への出力を確認し、 tail plugin の format の正規表現で syslog に書かれた message が
key ごとに正しく分割できていたら fluentd を停止、
flatfsd -s で fluent.conf の変更内容を保存します。
Armadillo-Box WS1 起動時に fluentd 関連のアプリケーションが動作する設定を追加します。
http://manual.atmark-techno.com/armadillo-box-ws1/armadillo-box-ws1_product_manual_ja-1.1.0/ch09.html#sct.userland_spec.rc_local
/etc/config.rc.local に以下の内容を追加し、flatfsd -s で保存します。
#!/bin/sh . /etc/init.d/functions PATH=/bin:/sbin:/usr/bin:/usr/sbin # ntp ntpclient -h ntp.nict.jp -s # BLE temperature log application tempgw & # fleuntd fluentd -c /etc/fluent/fluent.conf -o /var/log/fluent.log &
ここでは fluentd は直接 rc.local の中で実行していますが、
/etc/init.d/ に fluentd 専用の起動スクリプトを置いたり
Armadillo-IoTでfluentdを利用してTreasureDataにデータを溜める
https://users.atmark-techno.com/blog/46/1219
にあるように start-stop-daemon で管理して起動してもいいでしょう。
fluentd を rc.local から起動すると、root の shell 上で実行するのと異なり timezone が反映されません。
この点は fluentd で送信する log の日付に影響するので注意が必要です。
上記の設定で Bluetooth Low Energy Gateway に設定した Armadillo-Box WS1 の fluentd で送信したログは
ログ集約サーバーの fluentd で受信します。
ログ集約サーバーのソフトウェア設定は BC-IoT-Kit/ログ集約サーバー をご覧ください。