Influxdb - Count of measurement data - influxdb

I have the following query for a measurement:
select foo from myMeasurement
which returns something like this:
time foo
---- ----
123412341234123412 valOne
123412341234123413 valOne
123412341234123414 valOne
123412341234123415 valTwo
123412341234123416 valTwo
123412341234123417 valThree
123412341234123418 valThree
123412341234123419 valThree
123412341234123420 valThree
I would like to get the count of each one. In other words I would like to get the following
foo numResults
--- ----------
valOne 3
valTwo 2
valThree 4
I have tried using select count(*) and group by foo, but I can't seem to get the correct syntax/combination to generate the desired results.
Any help would be appreciated, thanks!

Is the foo field marked as a tag? The GROUP BY sentence doesn't work in any kind of field. It's not like in a relational database where you can easily GROUP BY by any field.
In this case the foo field should be marked as a tag field.
You can check the following documentation: GROUP BY tags
A little bit above you can see the following description:
Note: You cannot use GROUP BY to group fields.
Once you have it you can execute the same query and it will work.

Related

InfluxDB query with tag where clause not returning results

this looks like something really straightforward that I am messing up, but can't find what is wrong. I have a simple query where I am trying to retrieve measurements with a specific tag value. I am following the syntax of double quoting the tag_key and single quoting the tag value. E.g., select "score","i_unique"::tag from "events.flow" where "i_unique" = 'my-value'
If you see below:
> select "score","i_unique"::tag from "events.flow" limit 4
name: events.flow
time score i_unique
---- ----- --------
1563464912039000000 462 "42422440-41124048-155896-42266768-229624-233640"
1563464912042000000 462 "42422440-41124048-155896-42266768-42352808-42270864"
......
> select "score","i_unique"::tag from "events.flow" where "i_unique" = '42422440-41124048-155896-42266768-229624-233640'
>
The tag value I want to query for, is in the time series as can be seen by the first select query. But, when I want to pick up just that value by adding a where clause, I am not getting any results.
Any help would be wonderful, Thank You.
Turns out there was an error on my insert. I was inserting an additional double quote for my tag. It is obvious now, when I look at the result of the search query, but missed it completely. So this was a problem with my insert and not select. Once I removed the additional "s, everything is making sense again.

InfluxDB merge different Field Value to single printout

I want to get the one line printout by mix/merge different field value, like the following , (Mix or Merge is method what I assume)
select mix(value) from test group by “name”
name: test
tags: name=“case1”
time mix/merge
1970-01-01T00:00:00Z failed,passed,skipped
select * from test group by “name”
name: test
tags: name=“case1”
time caseAuthor caseName caseResult value
2018-07-20T03:51:42.599533888Z mike case1 pass 1
2018-07-20T03:51:42.690955475Z mike case1 failed 2
2018-07-20T03:51:42.723272883Z mike case1 skipped 3
thanks for any help
BRs
/Yijun
As for v1.6 there is no "join" or "concat" aggregation function in InfluxQL. All you can do is running
SELECT DISTINCT("caseResult")
FROM "test"
GROUP BY “name”
and then join values by "comma" separator in each group with some bash script or the programming language executing a query.
And actually, even though InfluxDB supports various data types (e.g. strings and booleans) InfluxQL support for processing data of types other then numeric is very-very poor in my opinion...

Using InfluxQL to count points (rows) with same value within an interval?

I'm trying to leverage my moderate SQL-knowledge for InfluxQL, but I'm missing something(s) about the nature of timeseries db.
Use case
I write a measurements from our issue tracker, when an issue is updated:
issue_updated,project=facebook,ticket=fb1,assignee=coolman status="todo"
Problem
Given this returns rows of issues statuses:
SELECT status
FROM "issue_updated"
If this was SQL (fiddle) I would use COUNT(and then add the WHERE time > NOW() - 1Y GROUP BY time(5m)). However the following gives me Mixing aggregate and non-aggregate queries is not supported
SELECT status, count(status) as 'Count'
FROM "issue_updated"
Can someone give some guidance here? ta
Sounds like what you're looking for is the ability to group by a field value which isn't currently supported.
From what I can tell, if you modify your schema a bit, it should be possible to do what you're looking. Instead of
issue_updated,project=facebook,ticket=fb1,assignee=coolman status="todo"
Do
issue_updated,project=facebook,ticket=fb1,assignee=coolman,status=todo value=1
then
SELECT count(value) FROM "issue_updated" WHERE time > now() - 52w GROUP BY status
name: issue_updated
tags: status=other
time count
---- -----
1449523659065350722 1
name: issue_updated
tags: status=todo
time count
---- -----
1449523659065350722 2
should work.

Query Influxdb based on tags?

I have started playing around with Influxdb v0.13 and I have some dummy values in my test db where id is a tag and value is a field:
> SELECT * FROM dummy
name: dummy
--------------
time id value
1468276508161069051 1234 12345
1468276539152853428 613 352
1468276543470535110 613 4899
1468276553853436191 1234 12
I get no results returned when I run this query:
> SELECT * FROM dummy WHERE id=1234
but I do get the following when querying with the field instead:
> SELECT * FROM dummy WHERE value=12
name: dummy
--------------
time id value
1468276553853436191 1234 12
Am I doing something wrong here? I thought the point of tags were to be queried (since they are indexed and fields are not), but they seem to break my queries.
It appears that Influx will treat every tag key and value we insert as string and this is evidently shown in their official documentation.
See: https://docs.influxdata.com/influxdb/v0.13/guides/writing_data/
When writing points, you must specify an existing database in the db
query parameter. See the HTTP section on the Write Syntax page for a
complete list of the available query parameters. The body of the POST
- we call this the Line Protocol - contains the time-series data that you wish to store. They consist of a measurement, tags, fields, and a
timestamp. InfluxDB requires a measurement name. Strictly speaking,
tags are optional but most series include tags to differentiate data
sources and to make querying both easy and efficient. Both tag keys
and tag values are strings.
Note: the text in bold.
Hence to filter by tag key value - the query must be enquoted.
Example:
SELECT * FROM dummy WHERE id='1234'

Multiple count in single statement (esper epl)

I am trying to create an epl statement using esper for monitoring response times, something like this:
SELECT QUEUENAME, count(latency>1000) AS NUMBER_OF_SLA_BREACHES, COUNT(latency) AS TOTALS FROM ResponseWindow GROUP BY QUEUENAME
.. however the two count() gives same results, which is incorrect.
Thanks for any help correcting this query!
You need to add the filter as a second parameter to the count aggregation function like this:
SELECT QUEUENAME, count(*,latency>1000) AS NUMBER_OF_SLA_BREACHES, COUNT(latency) AS TOTALS FROM ResponseWindow GROUP BY QUEUENAME

Resources