-database name | |||||||||||||||||||||||||||||||||||||||||||||||||||||
auth | |||||||||||||||||||||||||||||
SQL-like query language named InfluxQL
Command line editing on InfluxDB shell version: 1.8.4.
Control characters:
^a goes to beginning of line, ^← back a work, ^b back a character, ^→ forward a word, ^e end of line,
^u erase to beginning of line, ^w erase previous word, ^d delete under cursor, ^k erase to end. of line,
^L clearScreen, ^r reverse_Incremental_search, ^y yank from delete buffer.
Measurement names, tag keys, tag values, field keys, and field values are case sensitive.
Numerical field values are floats unless they include a trailing i
Use " (quotes) not ' (apostrophes)
(don't use tz('EST')
use America/New_York or something from this list.
Not timestamps nor boolean (true, false)
influx Command Line Intrepreter queries the database.
Keywords
ALTER
|
It an be run from another system using
influx -host dbhosst
ERR: no data received The database is not running.
influx -database ruuvi Connected to http://localhost:8086 version 1.7.4 InfluxDB shell version: 1.7.6 as of 4/25/19 Raspberry Pi >use ruuvi
| >show FIELD KEYS
name: ruuvi_measurements
fieldKey fieldType
-------- ---------
These (gray) keys are calculated values included by default with
ruuvi-collector.properties:storage.values=extended
They can be excluded with =raw
More info is at Packet Formats absoluteHumidity float accelerationAngleFromX float accelerationAngleFromY float accelerationAngleFromZ float accelerationTotal float accelerationX float accelerationY float accelerationZ float batteryVoltage float airDensity float dewPoint float equilibriumVaporPressure float humidity float measurementSequenceNumber integer movementCounter integer pressure float rssi integer temperature float txPower integer >show tag keys name: ruuvi_measurements tagKey ------ dataFormat mac | >show measurements name: measurements name ---- ruuvi_measurements > show series key --- ruuvi_measurements,dataFormat=3,mac=C7103C6824C2 ruuvi_measurements,dataFormat=3,mac=D2503AFE1A96 ruuvi_measurements,dataFormat=3,mac=DC4B596ED18B ruuvi_measurements,dataFormat=3,mac=E4D56DEC6E29 ruuvi_measurements,dataFormat=4,mac=C7103C6824C2 ruuvi_measurements,dataFormat=5,mac=C3F5C373450A ruuvi_measurements,dataFormat=5,mac=C4D8A4A90981 ruuvi_measurements,dataFormat=5,mac=C876E596B2C3 ruuvi_measurements,dataFormat=5,mac=D0FD6D6506DC ruuvi_measurements,dataFormat=5,mac=D2503AFE1A96 ruuvi_measurements,dataFormat=5,mac=D3517872EC0F ruuvi_measurements,dataFormat=5,mac=D6F3DADAC85E ruuvi_measurements,dataFormat=5,mac=DC4B596ED18B ruuvi_measurements,dataFormat=5,mac=DCDF6E338D04 ruuvi_measurements,dataFormat=5,mac=E49ED586E4CE ruuvi_measurements,dataFormat=5,mac=E4D56DEC6E29 ruuvi_measurements,dataFormat=5,mac=E9383FDD20BC ruuvi_measurements,dataFormat=5,mac=F2C0C643AD03 ruuvi_measurements,dataFormat=5,mac=F7B7744722AB ruuvi_measurements,dataFormat=5,mac=F7FA744A1E1A |
SELECT COUNT( * | field_key | field_key,tag_key | /regular_expression/ )
[INTO ]
FROM
[ WHERE† ]
[ GROUP BY [* | tag_key[,tag_key]]]
[ ORDER BY TIME ] ( Maybe GROUP BY will do what you want.)
[ LIMIT† ]
[ OFFSET]
[ SLIMIT ]
[ SOFFSET ]
[ tz('time_zone') ]
For field_keys and tag_key with the same name use: _key ::[field|tag ]
time = , <> ,
!= , > , >= , < or <= >
now() -duration_unit : w d h m s ms u ns (No month code.)
tz('America/New_York)
It is not necessary to include tz(…) if influx is invokled with -precision rfc3339
Example if tz is specified:
'yyyy-mm-dd[Thh:mm:ss-hh:00'
'2021-03-23T00:10:00-04:00' '2021-03-23'
'yyyy-mm-dd[ hh:mm:ss[.thmuuunnn †]'
'yyyy-mm-dd[Thh:mm:ss[.thmuuunnnZ']
… time > '2019-03-26' and time <='2019-03-26 17:01:00' … time > '2019-03-26T17:00:08.960Z' limit 1 time floor ---- ----- 2019-03-26T17:00:08.964Z 44 … time > '2019-03-26T17:00:08.965Z' limit 1 time floor ---- ----- 2019-03-26T17:00:19.062Z 44MEAN( ) from ruuvi_measurements GROUP By time … for each time(12m) interval : faster too!… time >= now()-2h GROUP BY time(10m) requires at least one aggregate function.
SELECT MEAN(batteryVoltage) FROM ruuvi_measurements WHERE … GROUP BY *† ,time(12m) LIMIT 2 ;
SELECT round( (32+( (9/5)*(temperature)) )*10 )/10 , mean(batteryVoltage)*100 as volts FROM ruuvi_measurements
WHERE time > :dashboardTime: AND time < :upperDashboardTime: AND
"mac"='E4D56DEC6E29'
group by *,time(6h)
now() - 7d
where does not support or for multiple time ranges.
Eastern Standard Time zone) of the most recent (last) temperature , etc:
influx -precision rfc3339 -database ruuviFrom a specfic ruuvi tag.
select mac, round( (32+( (9/5)*(temperature)) )*10 )/10 from ruuvi_measurements where time > now() -2m group by mac
select temperature from ruuvi_measurements where time > now() - 15m AND mac='D3517872EC0F' limit 10 select temperature from ruuvi_measurements where time > '2019-02-19' AND mac='D3517872EC0F' limit 10 select temperature from ruuvi_measurements where time > '2019-02-19T04:08:00Z' AND mac='D3517872EC0F' limit 10All
macs with temperature converted to fahrenheit select mac,ceil(temperature*9/5)+32
from ruuvi_measurements where time > now()-1h group_by mac
From Command Line
influx -precision rfc3339 -database ruuvi -execute "select round( (32+( (9/5)*(temperature)) )*10 )/10
from ruuvi_measurements where mac='DC4B596ED18B'
Non-interactive query database "metrics" and pretty print json:
influx -database 'metrics' -execute 'select * from cpu' -format 'json' -pretty
Connect to a specific database and set database context(to defaults)
influx -database 'metrics' -host 'localhost' -port '8086'
cURL connects to a running database engine>
Either can be run from a remote system
curl --silent --show-error --get 'http://pi93graf:8086/query?' --data-urlencode "db=ruuvi" --data-urlencode \
"q=SELECT mac,last(temperature) FROM ruuvi_measurements where mac='DC4B596ED18B' limit 3 tz('America/New_York') "
{"results":[{"statement_id":0,"series":[{"name":"ruuvi_measurements",
"columns":["time","mac","last"],
"values":[["2019-05-22T01:43:53.159467957-04:00","DC4B596ED18B",16.18]]}]}]}
curl --silent --show-error --connect-timeout 6 --get 'http://pi93graf:8086/query?' \ --data-urlencode "db=ruuvi" \ --data-urlencode \ "q=SELECT mac,round( (32+( (9/5)*(temperature)) )*10 )/10 FROM ruuvi_measurements group by mac " |\ sed "s/name.:.ruuvi_measurements/ \\n/g; s/.columns.:..time.,.mac.,.//g; s/.......-..:..//g" |\ sed "s/0000000001//g; s/99999999999//g ; s/\[/\n[/g" # to get it to be more human readable.
curl --silent --show-error --get 'http://localhost:8086/query?pretty=true' \
--data-urlencode "db=ruuvi" --data-urlencode \
"q=SELECT rssi FROM ruuvi_measurements limit 3"
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "ruuvi_measurements",
"columns": [
"time",
"rssi"
],
"values": [
[
"2018-03-25T00:23:19.564Z",
-54
],
[
"2018-03-25T00:23:23.63Z",
-59
],
[
"2018-03-25T00:23:28.299Z",
-50
]
]
}
]
}
]
}
To make this more human readable :
| sed 's/},{/\n/g; s/"//g; s/\[//g ; s/]/\n/g; s/name:ruuvi_measurements,//g; s/columns://g; '\
's/values://g ; s/{mac://g; s/-0.:00//g'
curl --get 'http://localhost:8086/query?' --data-urlencode "db=ruuvi" --data-urlencode \
"q=SELECT rssi FROM ruuvi_measurements limit 3"
{"results":[{"statement_id":0,"series":[{"name":"ruuvi_measurements",
"columns":["time","rssi"],
"values":[["2018-03-25T00:23:19.564Z",-54],["2018-03-25T00:23:23.63Z",-59],
["2018-03-25T00:23:28.299Z",-50]]}]}]}
Additional examples:
influx -precision rfc3339 -database ruuvi # ccyy-mm-ddThh:mm:ssZ select mac,ceil(temperature*9/5)+32 from ruuvi_measurements where time > now()-15m \ group by mac limit 10name: ruuvi_measurements tags: mac=D3517872EC0F time mac ceil ---- --- ---- 2018-12-28T13:34:11.836-05:00 D3517872EC0F 56 2018-12-28T13:34:21.946-05:00 D3517872EC0F 56 2018-12-28T13:34:32.029-05:00 D3517872EC0F 56 name: ruuvi_measurements tags: mac=E9383FDD20BC time mac ceil ---- --- ---- 2018-12-28T13:34:20.964-05:00 E9383FDD20BC 75 2018-12-28T13:34:31.116-05:00 E9383FDD20BC 75 2018-12-28T13:34:41.268-05:00 E9383FDD20BC 75 select LAST(temperature) from ruuvi_measurements where mac='DC4B596ED18B' tz('America/New_York')
(Not ET, not EDT )name: ruuvi_measurements time last ---- ---- 2018-12-03T20:40:28.217-05:00 24.41 select ceil((temperature*9/5)+32) from ruuvi_measurements where \ time > 1545583683677000000 2018-12-23T11:48:13.764-05:00 41 2018-12-23T11:48:23.838-05:00 41 2018-12-23T11:48:33.939-05:00 41 … 2018-12-23T12:11:50.314-05:00 42 2018-12-23T12:12:00.42-05:00 42 note ugly time when ms is nn0 2018-12-23T12:12:11.032-05:00 42 select min(rssi), mean(rssi), max(rssi), STDDEV(rssi ),max( movementCounter) FROM ruuvi_measurements where time > now()-7d and mac='D3517872EC0F' name: ruuvi_measurements time min mean max stddev max_1 ---- --- ---- --- ------ ----- 2023-06-19T11:59:58.524301933-04:00 -104 -96.18324607329843 -86 4.5564219500061265 157 select min(rssi), mean(rssi), max(rssi), STDDEV(rssi ),max( movementCounter) FROM ruuvi_measurements where time > '2023-06-10' and mac='D3517872EC0F' name: ruuvi_measurements time min mean max stddev max_1 ---- --- ---- --- ------ ----- 2023-06-10T00:00:00.000000001-04:00 -105 -96.39492753623189 -59 5.017194716767061 157 select min(rssi), mean(rssi), max(rssi), STDDEV(rssi ),max( movementCounter) FROM ruuvi_measurements where time > '2023-06-02T10:27:00-04:00' and mac='D3517872EC0F' time is oldest in range time min mean max stddev max_1 ---- --- ---- --- ------ ----- 2023-06-02T10:27:00.000000001-04:00 -105 -96.39492753623189 -59 5.017194716767061 157 select temperature, absoluteHumidity, pressure FROM ruuvi_measurements where mac='D3517872EC0F' and time > now()-2d and rssi> -70 limit 2; name: ruuvi_measurements time temperature absoluteHumidity pressure ---- ----------- ---------------- --------------- 2018-03-22T17:05:14.741Z 6 4.064597097450367 99300 2018-03-22T17:06:15.745Z 6 4.064597097450367 99300 select temperature, absoluteHumidity,batteryVoltage, pressure from ruuvi_measurements where mac='D3517872EC0F' and batteryVoltage>0 limit 2 time temperature absoluteHumidity batteryVoltage pressure ---- ----------- ---------------- -------------- -------- 2018-06-06T17:53:25.336Z 49.86 40.90683320213987 3.001 99442 ## last entry as of 11/30/18 2018-06-06T17:53:36.438Z 49.83 40.84931173861518 3.019 99454 ## notice no txPower values Other MACs : E511D11ECBB8, E6C3BE6F656C , FB0ECBEF7354, F7FA744A1E1A, DFC8B0FE5CC0 D3517872EC0F lines wrapped and precision edited for breivity (ed) select * from ruuvi_measurements where mac='D3517872EC0F' and time > 154079 and rssi> -70 limit `; name: ruuvi_measurements time absoluteHumidity accelerationAngleFromX accelerationAngleFromY accelerationAngleFromZ ---- ---------------- ---------------------- ---------------------- ---------------------- 1540249289169000000 8.624138716002781 76.08684542427619 14.79288467670658 85.07363877795116 accelerationTotal accelerationX accelerationY accelerationZ airDensity batteryVoltage ----------------- ------------- ------------- ------------- ---------- -------------- 0.9898070519045619 0.238 0.957 0.085 1.2378516828652366 2.929 dataFormat dewPoint equilibriumVaporPressure humidity mac measurementSequenceNumber ---------- -------- ------------------------ -------- --- ------------------------- 3 8.66 1121.3290262788335 100 D3517872EC0F 1004 movementCounter rssi temperature txPower --------------- ---- ----------- ------- 86 -61 8.66 4 select temperature,humidity,batteryVoltage, rssi from ruuvi_measurements where mac='D3517872EC0F' order by time limit 4 name: ruuvi_measurements time temperature humidity batteryVoltage rssi ---- ----------- -------- -------------- ---- 1540249341135000000 8.65 100 2.929 -76 1540249351743000000 8.65 100 2.929 -62 1540249361841000000 8.66 100 2.923 -64 1540249371940000000 8.64 100 2.923 -78 select mac, temperature, rssi from ruuvi_measurements order by time limit 6 name: ruuvi_measurements time mac temperature rssi ---- --- ----------- ---- 1540249289169000000 D3517872EC0F 8.66 -61 1540249290475000000 F2C0C643AD03 21 -92 1540249299762000000 D3517872EC0F 8.65 -76 1540249301098000000 F2C0C643AD03 21 -93 1540249309853000000 D3517872EC0F 8.65 -64
SELECT_clause
INTO
- measurement_name
- database_name..measurement_name
- database_name.retention_policy_name.measurement_name
- database_name.retention_policy_name.:MEASUREMENT FROM /regular_expression/
FROM_clause [WHERE_clause] [GROUP_BY_clause]
Copy data from one database to another.
The backreference syntax (:MEASUREMENT) maintains the source measurement names in the destination .
When copying large amounts of data, avoid running out of memory by running INTO
queries with different measurements or time boundaries with the WHERE.
Example:
SELECT "water_level" INTO "h2o_feet_copy_1" FROM "h2o_feet" WHERE "location" = 'coyote_creek'.
h2o_feet_copy_1 is a new new measurement
Result displays number of points and a meaningless timestamp.
SELECT MEAN("water_level") INTO "all_my_averages" FROM "h2o_feet"
WHERE "location" = 'coyote_creek'
AND time >= '2015-08-18' AND time <= '2015-08-18'
GROUP BY time(12m)
AggregationsWith text fields (likeMAC) returns null
| ||||||||||||
COUNT( Don't use * select count(batteryVoltage) from ruuvi_measurements where time >= now()-3h
name: ruuvi_measurements
------------------------
time count
2018-12-08T20:50:15.11-05:00 6125
| ||||||||||||
DISTINCT( Cannot be combined with other functions or fields, not even another DISTINCT . count(distinct( field)) is OKWill report the earliest time if a range is specified. select distinct(batteryVoltage) from ruuvi_measurements where
mac = 'E49ED586E4CE' and time < '2024-08-01' and time > '2024-05-01'
name: ruuvi_measurements
time distinct
---- --------
2024-08-01T00:00:00.000000001Z 2.929
202.-08-01T00:00:00.000000001Z 2.935
2024-08-01T00:00:00.000000001Z 2.917
2024-08-01T00:00:00.000000001Z 2.911
| ||||||||||||
INTEGRAL( [ * | | * average | |||||||||||
INTEGRAL( field_key | | ||||||||||||
SelectorsSelecting a field and a selected field, value for both fields will be from the row of the selected field. For example:
2023-01-13T16:48:17.121272389-05:00 21.79 3.091
2023-01-13T16:49:24.152548228-05:00 21.78 3.067
2023-01-13T16:50:27.597212999-05:00 21.8 3.079
2023-01-13T16:51:29.770300218-05:00 21.82 3.074
2023-01-13T16:52:34.458392959-05:00 21.84 3.0730000000000004
select temperature,min(batteryVoltage) from ruuvi_measurements
time temperature min
2023-01-13T07:52:16.446954713-05:00 21.38 3.0730000000000004
select round(batteryVoltage*100)/100 from ruuvi_measurements where mac='D5413D44ADCE' and time > '2025-05-06 10:00:01' limit 50 tz('America/New_York')
When selection returns values from different rows for the different fields 1969-12-31T19:00:00-05:00 is returned as the time.
select first(temperature),last(batteryVoltage) from ruuvi_measurements time first last 1969-12-31T19:00:00-05:00 26.49 2.486 | |||||||||||||||||||||||
Influx Data | |||||||||||||||||||||||
String Functions | |||||||||||||||||||||||
SAMPLE( field,n | |||||||||||||||||||||||
select count(batteryVoltage),percentile(batteryVoltage,10), min(batteryVoltage),mean(batteryVoltage),max(batteryVoltage),stddev(batteryVoltage)
from ruuvi_measurements where batteryVoltage<1.78 and time > '2021-01-01' and mac='E9383FDD20BC'
name: ruuvi_measurements
time count percentile min mean max stddev
---- ----- ---------- --- ---- --- ------
2021-01-01T00:00:00.000000001-05:00 16 1.743 1.729 1.76225 1.778 0.013542525613784159
select mac,ceil(pressure/100),ceil(batteryVoltage*100)/100,ceil(temperature*9/5)+32,ceil(humidity)
from ruuvi_measurements
where time > NOW()-1m group by mac limit 5
Transformations | |||||||||||||||||||||||||||||
CEILING( rounded up | ROUND( | ||||||||||||||||||||||||||||
| Predictors | ||||||||
HOLT_WINTERS(
| ||||||||
sigQUIT (usually ^\) while a query is running causes influx to output partial results like: ERR: -12-31T00:31:48.091-05:00","D3517872EC0F",33],
["2018-12-31T00:31:58.171-05:00","D3517872EC0F",33],["2018-12-31T00:32:08.251-05:00","D3517872EC0F",33],
["2018-12-31T00:32:18.359-05:00","D3517872EC0F",33],["2018-12-31T00:32:28.463-05:00","D3517872EC0F",33],
["2018-12-31T00:32:38.566-05:00","D3517872EC0F",33],["2018-12-31T00:32:48.679-05:00","D3517872EC0F",33],
["2018-12-31T00:34:39.727-05:00","D3517872EC0F",33],["2018-12-31T00:34:49.818-05:00","D3517872EC0F",33],
["2018-12-31T00:35:00.396-05:00"…
Retention Policyduration: how long data is kept, example 4320h0m0s (180 days) must be greater than 1h
replication factor: how many copies of this data is stored in the cluster and the
shard group duration: time range covered by shard groups.
sduration must be greater than 1h,
defaults to 1h if duration < 2d; 7d if duration > 6m and 1d otherwise.
autogen with infinite duration, replication factor of 1, and shard group duration of 7 days (7*24=168h).
ALTER [CREATE] RETENTION POLICY retention_policy_name ON database_name
DURATION duration
REPLICATION n
[SHARD DURATION sduration] [DEFAULT]
GornellVT SHOW RETENTION POLICIES on ruuvi name duration shardGroupDuration replicaN default ---- -------- ------------------ -------- ------- autogen 0s† 168h0m0s 1 true > alter retention policy autogen on ruuvi DURATION 18240h > SHOW RETENTION POLICIES on ruuvi name duration shardGroupDuration replicaN default ---- -------- ------------------ -------- ------- autogen 18240h0m0s 168h0m0s 1 true > SHOW RETENTION POLICIES on ruuvi name duration shardGroupDuration replican default ---- -------- ------------------ -------- ------- autogen 0s 168h0m0s 1 true alter retention policy autogen on ruuvi DURATION 4320h# 180 days 1/2 year, (365+25)= 9360h (365*2+30)= 18240hautogen 4320h0m0s 168h0m0s 1 true aka 500d (((365+132))
SHOW MEASUREMENTS [ON database_name] [WITH MEASUREMENT regular_expression]
SHOW TAG KEYS [ON database_name] [FROM_clause]
SHOW TAG VALUES [ON database_name][FROM_clause] WITH KEY [ [operator "tag_key" | regular_expression] | [IN ("tag_key1","tag_key2")]]
SHOW FIELD KEYS [ON database_name] [FROM measurement_name]
SHOW DATABASES
SHOW RETENTION POLICIES on ruuvi;
SHOW FIELD KEYS
SHOW SERIES [ON database_name] [FROM_clause]
[WHERE tag_key operator [ 'tag_value' | regular_expression]] [LIMIT_clause] [OFFSET_clause]
[WHERE tag_key operator ['tag_value' | regular_expression]] [LIMIT_clause] [OFFSET_clause
[WHERE tag_key operator ['tag_value' | regular_expression]] [LIMIT_clause] [OFFSET_clause]
[WHERE tag_key operator ['tag_value' | regular_expression]] [LIMIT_clause] [OFFSET_clause]
name duration shardGroupDuration replicaN default ---- -------- ------------------ -------- ------- autogen 18240h0m0s 168h0m0s 1 true
from pi zero 3/27/19 InfluxDB shell version: 1.7.4 , ` influx_inspect, chronograf