I'm new to InfluxDB. I have an existing database with a table language. When I run select * from language I get the following table:
name: language
time application_guid application_name application_type instance_index lang metric_type stream_name value
---- ---------------- ---------------- ---------------- -------------- ---- ----------- ----------- -----
2019-03-07T07:46:49.225Z 31429 counter sink 0 ar counter tweetlang 0
2019-03-07T07:46:49.225Z 31429 counter sink 0 ca counter tweetlang 0
2019-03-07T07:46:49.225Z 31429 counter sink 0 de counter tweetlang 0
2019-03-07T07:46:49.225Z 31429 counter sink 0 el counter tweetlang 0
When I run select "lang" from language I get an empty result. What is the problem here?
Found the solution here:
The SELECT clause must specify at least one field when it includes a
tag.
According to documentation Select Clause can be given to field key and possible to give query with field name and tag key together where tag key is for indexing and field is what you defined as a column in the measurement.
If a select query will be given by a tag name, it won't return any result.
According to your measurement named language has lang key as a tag key.
if we consider your field names as follows:
application_guid application_name application_type instance_index
And tags as given below:
lang metric_type stream_name value
The select query can be given like these ways:
select * from language
select application_guid,lang from language
if multiple field and tags you want to give in the statement then:
select application_guid,application_type::field, metric_type,stream_name::tag from language
In addition, InfluxDb uses Line protocol, where line protocol informs InfluxDB of the data’s measurement, tag set, field set, and timestamp.
Related
I am able to make a query to an influxdb and select all the fields/tags:
select * from http_reqs where time > now() - 4d and "status" =~ /^4/
which returns a list of matching values. The first row looks like this:
time error error_code method name proto scenario status tls_version type url value
But when I try to select only a subset of these fields/tags (according to the documentation), I get no result at all:
select "time","name" from http_reqs where time > now() - 4d and "status" =~ /^4
No matter what I try to select. The documentation seems to be wrong or incorrect!
How am I be able to select the fields/tags I want?
It seems you have to first figure out what are "fields" and what are "tags". So you need to do:
show field keys from http_reqs;
in my case this returns
name: http_reqs
fieldKey fieldType
-------- ---------
url string
value float
As per documentation, you have to use at least one field key (for whatever reason).
Then you can query what you need (in addition to the field key, if you need that or not):
select "url","error" from http_reqs where time > now() - 4d and "status" =~ /^4/
I'm trying to construct a influxDB select query that returns feild and tag values but also the name of the measurement the data came from. This is because the query needs to evaluate over multiple measurements. eg:
select "foo" from /^(A|B|C)$/ where time > now() - 1h;
With the measurements being A B and C. How can i added another select column (say name) being the associated measurement name the data came from? eg:
foo name
---------------
bar A
cat B
dog C
mat A
I have some tag values that were unfortunately sent with quotes in them:
> SELECT count("count") FROM "railswebapp"
WHERE "auth_method" =~ /facebook/ GROUP BY "auth_method"
name: railswebapp
tags: auth_method=\"facebook\"
time count
---- -----
0 4
name: railswebapp
tags: auth_method=facebook
time count
---- -----
0 2632
>
Alas, querying for the "facebook" series is harder than I expect:
> SELECT "count" FROM "railswebapp"
WHERE "auth_method" = '\"facebook\"'
>
This work-around works but surely I can do better. Any suggestions?
> SELECT count("count") FROM "railswebapp"
WHERE "auth_method" =~ /facebook/
AND "auth_method" != 'facebook'
GROUP BY "auth_method"
name: railswebapp
tags: auth_method=\"facebook\"
time count
---- -----
0 4
> SELECT count FROM "railswebapp"
WHERE "auth_method" =~ /facebook/
AND "auth_method" != 'facebook'
GROUP BY "auth_method"
name: railswebapp
tags: auth_method=\"facebook\"
time count
---- -----
152412927875202308 1
152412927882740082 1
1524130761574200511 1
1524134859852346944 1
>
(Note: influx doesn't support line breaks in queries: they just make this question more readable.)
It is mentioned on influxdb documentation to not double or single quote measurement names, tag keys, tag values, and field keys.
Here is how quoting are handled,
Do not double or single quote measurement names, tag keys, tag values, and field keys. It is valid Line Protocol but InfluxDB assumes that the quotes are part of the name.
Never single quote field values (even if they’re strings!). It’s also not valid Line Protocol.
Do not double quote field values that are floats, integers, or Booleans. InfluxDB will assume that those values are strings.
It also mentioned ,
For string field values use a backslash character \ to escape:
Example,
Inserting data with tag-value containing double-quote,
INSERT cpu,host="x" value=10
Querying,
select * from cpu where host = '\"x\"'
Output,
name: cpu
time host value
---- ---- -----
1530754262442056777 "x" 10
I am a beginner with InfluxDB and I've read the intro documentation, but cannot find any details on how to create a new measurement. Am I missing something ?
As noted in the comments, to "create" a new measurement you simply insert data into that measurement.
For example
$ influx
> CREATE DATABASE mydb
> USE mydb
Using database mydb
> SHOW MEASUREMENTS
> INSERT cpu,host=serverA value=10
> SHOW MEASUREMENTS
name: measurements
name
----
cpu
> INSERT mem,host=serverA value=10
> SHOW MEASUREMENTS
name: measurements
name
----
cpu
mem
In INFLUX DB , you cant create empty measurements.
You need to add some data as well.
For Example,
INSERT xyz,name=serverA value=10,count=10
This will create a measurement name xyz where
tag keys : name
field keys : value & count
You can check Field and tag keys by executing show field keys or show tag keys.
In the INSERT command, the format is like :
measurement_name,tag keys + value separated by comma Field keys with value separated by comma
eg: INSERT xyz,name=serverA value=10,count=10
In this way, you can create measurement with specifying your required field and tag keys.
You cannot create an empty measurement, afaik.
Like they said above, if you want one you need to start writing to it and that should take care of creating one along with some data in it.
insert load,app_name=app3,groupname=second,performance=degraded uuid=003,loading=50,frequency=1
In the above, we are using "insert" to write new data into a new measurement called "load".
app_name,groupname,performance are 'tags' and uuid,loading,frequency are fields
create database <data base name of your choice>
create user "<username>" with password '<password>'
To see the all databases: SHOW DATABASES
Enter the Database: use <database name>
To see all tables inside the database: SHOW MEASUREMENTS
grant all on <data base name> to <username>
insert data (Here Motionsense is a Measurement which is similar to the table name of SQL): INSERT MotionSense,SensorType=Gyro roll=1.2,yaw=5,pitch=3
See the data of the Measurements: SELECT * FROM "MotionSense"
I am a newbie to influxdb. I just started to read the influx documentation.
I cant seem to get the equivalent of 'select count(*) from table' to work in influx db.
I have a measurement called cart:
time status cartid
1456116106077429261 0 A
1456116106090573178 0 B
1456116106095765618 0 C
1456116106101532429 0 D
but when I try to do
select count(cartid) from cart
I get the error
ERR: statement must have at least one field in select clause
I suppose cartId is a tag rather than a field value? count() currently can't be used on tag and time columns. So if your status is a non-tag column (a field), do the count on that.
EDIT:
Reference
This works as long as no field or tag exists with the name count:
SELECT SUM(count) FROM (SELECT *,count::INTEGER FROM MyMeasurement GROUP BY count FILL(1))
If it does use some other name for the count field. This works by first selecting all entries including an unpopulated field (count) then groups by the unpopulated field which does nothing but allows us to use the fill operator to assign 1 to each entry for count. Then we select the sum of the count fields in a super query. The result should look like this:
name: MyMeasurement
----------------
time sum
0 47799
It's a bit hacky but it's the only way to guarantee a count of all entries when no field exists that is always present in all entries.