How to create empty measurement in influx - influxdb

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.

Related

Rails cross cluster join with dynamic join condition

So, I have multiple tables in multiple databases.
The user sends me database details, table names, columns to be selected and which column to use as condition for join. The structure is similar to:
[{ database, table_name, join_column_name }]
My current implementation is like this,
Connect to the first DB
Fetch all data from the table
Store the data in a result variable (PG::Result instance)
Extract all unique values in current join_column_name from result to a filter_values array
Connect to next database
Fetch all data where value of current join_column_name is in filter_values
Store the data to a local_result variable (PG::Result instance)
Simulate inner join on result and local_result objects, and store in result
Repeat from step 4
Also, The join_column_name may or may not be an indexed column
In step 8, I have to create a new PG::Result object, and store mapped data from result and local_result objects. How do I attain this?
Is there a better way to do this, without all these custom logic?
I've looked into disable_joins: true, but don't know if it is applicable in this case.

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 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.

grafana plotting with multiple fields

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.

Resources