raspberryPi3にinfluxdb v1.3をインストールする
以前ラズベリーパイにv1.2のinfluxdbをインストールしましたが、今回はv1.3です
portaltan.hatenablog.com
Install InfluxDB
# ライブラリ設定 $ curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - OK $ source /etc/os-release $ test $VERSION_ID = "7" && echo "deb https://repos.influxdata.com/debian wheezy stable" | sudo tee /etc/apt/sources.list.d/influxdb.list $ test $VERSION_ID = "8" && echo "deb https://repos.influxdata.com/debian jessie stable" | sudo tee /etc/apt/sources.list.d/influxdb.list deb https://repos.influxdata.com/debian jessie stable $ sudo apt-get update # インストール $ sudo apt-get install influxdb $ sudo service influxdb start # 確認 $ ps aux | grep influx nouziru 8210 0.0 0.2 4276 2012 pts/1 S+ 12:59 0:00 grep influx influxdb 29797 13.1 4.3 800484 38508 ? Ssl 11:15 13:40 /usr/bin/influxd -config /etc/influxdb/influxdb.conf $ ss -lntp | grep 808 LISTEN 0 128 127.0.0.1:8088 *:* LISTEN 0 128 :::8086 :::* $ influxd config ### 各種項目が表示される
influxコマンド確認
$ influx Connected to http://localhost:8086 version 1.3.7 InfluxDB shell version: 1.3.7 > show databases name: databases name ---- _internal > create database debug > show databases name: databases name ---- _internal debug > use debug Using database debug > show measurements
ちなみにssl化しているときやport番号を変更しているときはssl, unsafeSsl, portオプションが必要
> influx -ssl -unsafeSsl -port 10443
API確認
# pingチェック $ curl -sl -I http://localhost:8086/ping HTTP/1.1 204 No Content Content-Type: application/json Request-Id: 0c85b3cf-d3f2-11e7-8003-000000000000 X-Influxdb-Version: 1.3.7 Date: Tue, 28 Nov 2017 04:10:20 GMT # database確認 $ curl http://localhost:8086/query --data-urlencode "q=SHOW DATABASES" {"results":[{"statement_id":0,"series":[{"name":"databases","columns":["name"],"values":[["_internal"],["debug"]]}]}]} # テストデータ投入(measurement: test_measurement / field: record1, 2) $ curl -i -XPOST "http://localhost:8086/write?db=debug" --data-binary 'test_measurement record1=100' $ curl -i -XPOST "http://localhost:8086/write?db=debug" --data-binary 'test_measurement record2=200' $ curl -i -XPOST "http://localhost:8086/write?db=debug" --data-binary 'test_measurement record1=300,record2=400' # テストデータ確認 $ curl -G 'http://localhost:8086/query?db=debug' --data-urlencode 'q=SELECT * FROM test_measurement' {"results":[{"statement_id":0,"series":[{"name":"test_measurement","columns":["time","record1","record2"],"values":[["2017-11-28T04:16:19.266486831Z",100,null],["2017-11-28T04:16:28.640633831Z",null,200],["2017-11-28T04:16:44.255827602Z",300,400]]}]}]} # テストデータ確認(pretty=trueをつけると改行されて表示される) $ curl -G 'http://localhost:8086/query?db=debug&pretty=true' --data-urlencode 'q=SELECT * FROM test_measurement' { "results": [ { "statement_id": 0, "series": [ { "name": "test_measurement", "columns": [ "time", "record1", "record2" ], "values": [ [ "2017-11-28T04:16:19.266486831Z", 100, null ], [ "2017-11-28T04:16:28.640633831Z", null, 200 ], [ "2017-11-28T04:16:44.255827602Z", 300, 400 ] ] } ] } ] } # influxコマンドで確認すると $ influx Connected to http://localhost:8086 version 1.3.7 InfluxDB shell version: 1.3.7 > use debug Using database debug > select * from test_measurement name: test_measurement time record1 record2 ---- ------- ------- 1511842579266486831 100 1511842588640633831 200 1511842604255827602 300 400
tips
status確認スクリプト
#!/bin/sh HOST="https://localhost" PORT=443 echo "**********************************************************************************************************************" echo "[ping]" ping=`curl -ksI ${HOST}:${PORT}/ping` echo "$ping" echo "************************************************************************************************************************" echo "[db]" db=`curl -sk ${HOST}:${PORT}/query --data-urlencode "q=SHOW DATABASES"` echo "$db" echo "************************************************************************************************************************" echo "[latest records]" desc=`curl -skG "${HOST}:${PORT}/query?db=DEBUG&pretty=true" --data-urlencode "q=SELECT * FROM test_measurement ORDER BY time DESC LIMIT 1"` echo "$desc"
追記
csvでデータをexportする方法
$ curl -H "Accept: application/csv" -skG "${HOST}:${PORT}/query?db=${DB_NAME}" --data-urlencode "q=SELECT * FROM ${measurement_name}" > test.csv