grafana plotting with multiple fields - influxdb

I have some data like this which I am putting in influx DB.
measurement userA=10,userB=20,userC=30 1475777099000000000
measurement userZ=11,userA=12,userB=31 1475777199000000000
is it possible to dynamically pick up userA,B,C,Z for a grafana plot? or shall I change my schema?

I'd probably consider changing your schema so that userA, userB, userC, userZ are tags with a single field called value.
For example:
measurement,user=A value=10 1475777099000000000
measurement,user=B value=20 1475777099000000000
measurement,user=C value=30 1475777099000000000
measurement,user=Z value=11 1475777199000000000
measurement,user=A value=12 1475777199000000000
measurement,user=B value=31 1475777199000000000
This way you can GROUP BY user and dynamically pick up on each of the users.

Related

Do all measurements (tables) in an influx database share field keys (columns)

I am used to Microsoft SQL server, but I have a task requiring use of a clients Influx server
From what I understand of the schema, and what I've been able to explore with the CLI, once you select a database, you can view all the field keys in that database, but there are not field keys that are exclusive to each measurement.
Is this true? If not, I will make a second question regarding how to access the field keys that ARE exclusive to a measurement and I will link it immediately following an answer.
Relevant links are
https://docs.influxdata.com/influxdb/v1.7/concepts/crosswalk/
https://docs.influxdata.com/influxdb/v1.8/query_language/explore-schema/
I have tried using client.query("SHOW FIELD KEYS").get_points() and it returns all field keys in all measurements in the database, since the client is only connected at the database level. But there does not seem to be a "use " options, like exists for "use "
Yes, each measurement has its own columns or field keys.
You can get the columns that are relevant to a single measurement by using
columns = client.query("SHOW FIELD KEYS").get_points(measurement = measurement_selection)
where measurement_selection is a string that matches the name of the measurement you wish to observe

How to create empty measurement in influx

Insert cpu,host=tools value=10
This creates a measurement with field and tag but how to create empty measurement
In INFLUX DB , you cant create empty measurements. You need to add some data since influx db work on dynamically creating the columns therefore you have define the values.

InfluxDB: Group rows with same timestamp

Assume a DB with the following data records:
2018-04-12T00:00:00Z value=1000 [series=distance]
2018-04-12T00:00:00Z value=10 [series=signal_quality]
2018-04-12T00:01:00Z value=1100 [series=distance]
2018-04-12T00:01:00Z value=0 [series=signal_quality]
There is one field called value. Square brackets denote the tags (further tags omitted). As you can see, the data is captured in different data records instead of using multiple fields on the same record.
Given the above structure, how can I query the time series of distances, filtered by signal quality? The goal is to only get distance data points back when the signal quality is above a fixed threshold (e.g. 5).
"Given the above structure", there's no way to do it in plain InfluxDB.
Please keep in mind - Influx is NONE of a relational DB, it's different, despite query language looks familiar.
Again, given that structure - you can proceed with Kapacitor, as it was already mentioned.
But I strongly suggest you to rethink the structure, if it is possible, if you're able to control the way the metrics are collected.
If that is not an option - here's the way: spin a simple job in Kapacitor that will just join the two points into one basing on time (check this out for how), and then drop it into new measurement.
The data point would look like this, then:
DistanceQualityTogether,tag1=if,tag2=you,tag2=need,tag4=em distance=1000,signal_quality=10 2018-04-12T00:00:00Z
The rest is oblivious with such a measurement.
But again, if you can configure your metrics to be sent like this - better do it.

How to SELECT, modify and INSERT data in Influx DB?

I'm new to InfluxDB. I currently have two databases in influx. I now want to copy certain data points from a measurement in the database1, then I want to introduce a couple field sets manually and modify the few field values that I copied and finally insert the changed data points in database2 under a different measurement.
I can use the select into statement however that will not allow me to make changes to the datapoint.
If I use the Insert command I will have to type all the field sets and tag sets individually.
I have a solution that I can use python and query the data points and manipulate the data then insert it back. However that will be a lengthy process.
Is there any easy way to accomplish this task?
Thanks.

Add tag to existing data point in InfluxDB

Is there a way to add a tag to an existing entry in InfluxDB measurement? If not in the existing db measurement, is there a way to insert the records with a new tag into a new influx measurement?
Currently I have a set of measurements that should probably be entries in a single measurement where their current measurement names should be tag-keys in the superset of the merged measurements.
e.g.
show measurements
measurement1
measurement2
measurement3
measurement4
should instead be tags on the data included in each measurement and union to form a single measurement joinedmeasurement with indexed tags measurment1, measurement2,...
It would have to be done manually via queries.
For example, in python using the official client:
from influxdb import InfluxDBClient
client = InfluxDBClient('localhost', database='my_db')
measurement = 'measurement1'
db_data = client.query('select value from %s' % (measurement))
data_to_write = [{'measurement': 'joinedmeasurement',
'tags': ['measurement1'],
'time': d['time'],
'fields': {'value': d['value']},
}
for d in db_data.get_points()]
client.write_points(data_to_write)
And so on for the rest of the measurements. Can run the above in a loop to do all of them in one go.
Consider using named fields though in addition to tags. The above example only uses one field - can have as many as you want.
This improves performance further, though obviously fields are not indexed so do not use them for data that queries are to run on.

Resources