influxDB -writing
Write data
Load data source in UI
Load data source in UI
InfluxDB UI에서 각종 Sources의 데이터를 load한다.
- Annotatied CSV , Line Protocol
- [Client 라이브러리]를 선택하거나,
(such as Python, Ruby, Scala, and more!) - [Telegraf 플러그인] 사용하여 데이터를 로드한다
(like MQTT Consumer, MySQL, File, and many more!).
No-code solutions
Telegraf
input plugins – (Messaging, IoT) – MQTT
https://github.com/influxdata/telegraf/blob/release-1.20/plugins/inputs/mqtt_consumer/README.md
Scrape data
Code solution (Developer tools)
3rd party developer tools
Write raw query results back to InfluxDB
Write raw query results back to InfluxDB
https://docs.influxdata.com/influxdb/v2.1/write-data/developer-tools/csv/
https://docs.influxdata.com/influxdb/v2.1/reference/syntax/annotated-csv/#annotated-csv-in-flux
InfluxDB에 csv파일은 주입하려면, Cli의 influx write 명령사용.
CSV annotations은 맨 위줄에 추가된 정보. (어떤 컬럼이 measurement 이거나, field이거나, timestamp, 또는 tag set인지)
- csv 파일 맨 위에 annotation
- 명령어 뒤어 옵션으로 –header
- 따로 파일로 -f header.csv를 만들어서
헤더 있는 Excel 파일
#datatype
- measurement
- tag
- field
- dateTime
- ignored
필드 타입
- string
- boolean y => true, Y => true, 1 => true
- double
- long
- unsignedLong 1,200,000.00 => 1200000u
#datatype measurement,tag,double,dateTime:RFC3339 m,host,used_percent,time mem,host1,64.23,2020-01-01T00:00:00Z mem,host2,72.01,2020-01-01T00:00:00Z mem,host1,62.61,2020-01-01T00:00:10Z mem,host2,72.98,2020-01-01T00:00:10Z mem,host1,63.40,2020-01-01T00:00:20Z mem,host2,73.77,2020-01-01T00:00:20Z
$ influx write dryrun -b Firstbucket \\ -f /var/lib/influxdb2/importing_files/ex.csv \\ --header "#datatype measurement,tag,double,dateTime:RFC3339" mem,host=host1 used_percent=64.23 1577836800000000000 mem,host=host2 used_percent=72.01 1577836800000000000 mem,host=host1 used_percent=62.61 1577836810000000000 mem,host=host2 used_percent=72.98 1577836810000000000 mem,host=host1 used_percent=63.4 1577836820000000000 mem,host=host2 used_percent=73.77 1577836820000000000
result,table,start,_stop,_time,region,host,_value my-result,0,2018-05-08T20:50:01Z,2018-05-08T20:51:00Z,2018-05-08T20:50:00Z,east,A,15.43 my-result,0,2018-05-08T20:50:02Z,2018-05-08T20:52:00Z,2018-05-08T20:50:20Z,east,B,59.25 my-result,0,2018-05-08T20:50:03Z,2018-05-08T20:53:00Z,2018-05-08T20:50:40Z,east,C,52.62
$ influx write dryrun -b Firstbucket \\ -f /var/lib/influxdb2/importing_files/ex.csv \\ --header "#datatype measurement,tag,dateTime,dateTime,time:RFC3339,string,string,double" 2021/11/15 11:28:10 WARNING: at most one dateTime column is expected, 'start' column is ignored my-result,table=0 region="east",host="A" 1525812600000000000 my-result,table=0 region="east",host="B" 1525812620000000000 my-result,table=0 region="east",host="C" 1525812640000000000 $ influx write -b Firstbucket \\ -f /var/lib/influxdb2/importing_files/ex.csv \\ --header "#datatype measurement,tag,dateTime,dateTime,time:RFC3339,string,string,double"
Measuerment명 상수로 추가, 시간없는 날짜 필드
- datatype dateTime:RFC3339 2020-01-01T00:00:00Z
- datatype dateTime:RFC3339Nano 2020-01-01T00:00:00.000000000Z
- datatype dateTime:number 1577836800000000000
- datatype dateTime:2006-01-02 2020-01-01
- constant measurement,m
- constant tag,dataSource,csv
#constant measurement,m #constant tag,dataSource,csv
date,sighted,loc 2020-01-01,12,Boise 2020-06-01,78,Boise 2020-01-01,54,Seattle 2020-06-01,112,Seattle 2020-01-01,9,Detroit 2020-06-01,135,Detroit
influx write dryrun -b Firstbucket \\ -f /var/lib/influxdb2/importing_files/ex.csv \\ --header "#constant measurement,birds" \\ --header "#datatype dateTime:2006-01-02,long,tag" influx write dryrun -b Firstbucket \\ -f /var/lib/influxdb2/importing_files/ex.csv \\ --header "#constant measurement,birds" \\ --header "#datatype dateTime:2006-01-02,long,tag" Resulting line protocol birds,loc=Boise sighted=12i 1577836800000000000 birds,loc=Boise sighted=78i 1590969600000000000 birds,loc=Seattle sighted=54i 1577836800000000000 birds,loc=Seattle sighted=112i 1590969600000000000 birds,loc=Detroit sighted=9i 1577836800000000000 birds,loc=Detroit sighted=135i 1590969600000000000 influx write dryrun -b Firstbucket \\ -f /var/lib/influxdb2/importing_files/ex.csv \\ --header "#constant measurement,birds" \\ --header "#constant tag,dataSource,csv" \\ --header "#datatype dateTime:2006-01-06,long,tag" birds,dataSource=csv,loc=Boise sighted=12i 978307200000000000 birds,dataSource=csv,loc=Boise sighted=23i 991353600000000000 birds,dataSource=csv,loc=Seattle sighted=54i 978307200000000000 birds,dataSource=csv,loc=Seattle sighted=112i 991353600000000000 birds,dataSource=csv,loc=Detroit sighted=9i 978307200000000000 birds,dataSource=csv,loc=Detroit sighted=135i 991353600000000000