0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

InfluxDB v2: API の使い方

Last updated at Posted at 2021-07-07

InfluxDB 2.0 の API の使い方です。

organization: ekzemplaro
bucket: tochigi
としたサンプルです。

トークンは次のコマンドで得られます。

influx auth list

データの書き込み

参考ページ
Write data with the InfluxDB API

write_data.sh
#
URL="http://localhost:8086/api/v2/write?org=ekzemplaro&bucket=tochigi&precision=s"
TOKEN='1zIYs1taCm3pWQOBUNk0ssYccOF7YgJcdGyJDbiFYTBf7hcPvyl5nGyt71rNVkYtg2rBceUwQ1r5Xzm7Mabcde=='
#
#
curl --request POST $URL \
  --header "Authorization: Token $TOKEN" \
  --data-raw '
t0921 name="宇都宮",population=93215,date_mod="2006-5-29"
t0922 name="小山",population=23719,date_mod="2006-7-6"
t0923 name="佐野",population=43817,date_mod="2006-8-12"
'

データの読み込み

参考ページ
Query with the InfluxDB API

query_data.sh
#
URL='http://localhost:8086/api/v2/query?org=ekzemplaro'
TOKEN='1zIYs1taCm3pWQOBUNk0ssYccOF7YgJcdGyJDbiFYTBf7hcPvyl5nGyt71rNVkYtg2rBceUwQ1r5Xzm7Mabcde=='
#
#
curl --request POST $URL \	
	--header "Authorization: Token $TOKEN" \
	--header 'Accept: application/csv' \
  --header 'Content-type: application/vnd.flux' \
  --data 'from(bucket:"tochigi") |> range(start: -12h)'

実行結果

$ ./query_data.sh 
,result,table,_start,_stop,_time,_value,_field,_measurement
,_result,0,2021-07-06T20:50:36.122730369Z,2021-07-07T08:50:36.122730369Z,2021-07-07T08:46:23Z,2006-5-29,date_mod,t0921
,_result,1,2021-07-06T20:50:36.122730369Z,2021-07-07T08:50:36.122730369Z,2021-07-07T08:46:23Z,宇都宮,name,t0921

,result,table,_start,_stop,_time,_value,_field,_measurement
,_result,2,2021-07-06T20:50:36.122730369Z,2021-07-07T08:50:36.122730369Z,2021-07-07T08:46:23Z,93215,population,t0921

,result,table,_start,_stop,_time,_value,_field,_measurement
,_result,3,2021-07-06T20:50:36.122730369Z,2021-07-07T08:50:36.122730369Z,2021-07-07T08:46:23Z,2006-7-6,date_mod,t0922
,_result,4,2021-07-06T20:50:36.122730369Z,2021-07-07T08:50:36.122730369Z,2021-07-07T08:46:23Z,小山,name,t0922

,result,table,_start,_stop,_time,_value,_field,_measurement
,_result,5,2021-07-06T20:50:36.122730369Z,2021-07-07T08:50:36.122730369Z,2021-07-07T08:46:23Z,23719,population,t0922

,result,table,_start,_stop,_time,_value,_field,_measurement
,_result,6,2021-07-06T20:50:36.122730369Z,2021-07-07T08:50:36.122730369Z,2021-07-07T08:46:23Z,2006-8-12,date_mod,t0923
,_result,7,2021-07-06T20:50:36.122730369Z,2021-07-07T08:50:36.122730369Z,2021-07-07T08:46:23Z,佐野,name,t0923

,result,table,_start,_stop,_time,_value,_field,_measurement
,_result,8,2021-07-06T20:50:36.122730369Z,2021-07-07T08:50:36.122730369Z,2021-07-07T08:46:23Z,43817,population,t0923

関連情報

InfluxDB v2: cli の使い方

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?