Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InfluxDB Correct Ways to Store Data (measurement, field, tag)

I've read some articles online about InfluxDB's measurement, field, and tag, but still confused about it.

I have the following data:

  • State (String, each state - CA, WA, MO, etc.)
  • Usage (numeric)

I am collecting the usage data of each state every hour. What should I put in measurement, fields, and tags when I am writing data to my InfluxDB? I've tried the following but not sure which one is the best.

  • measurement: "usage"
    field & fieldValue: "value" & actual usage data
    tag & tagValue: "state" & actual state abbreviation
  • measurement: "usage"
    field1 & fieldValue1: "value" & actual usage data
    field2 & fieldValue2: "state" & actual state abbreviation
  • measurement: "anotherMeasurementName"
    field & fieldValue: "usage" & actual usage data
    tag & tagValue: "state" & actual state abbreviation
  • measurement: "usage"
    field & fieldValue: actual state abbreviation & actual usage data

Thank you!

like image 395
kateeeeee Avatar asked Oct 17 '25 10:10

kateeeeee


1 Answers

Let me explain some about data structure in InfluxDB.

  1. Each InfluxDB node can have multiple databases and organizations. These should be used for dividing various project data and users (manage permissions).
  2. Measurement in database is like a "table" in SQL databases. So writing data into InfluxDB with static data types and data structure will be fine using only one measurement - this is your case.
  3. Under one measurement you can have multiple tags and value fields. Tags can only be a string type and they perform role as a data keys/indexes - ask yourself if you are going to filter/group values by a specific data - if yes: this data should be used as a tag. This will improve InfluxDB work and will provide you easy to filter data structure. What also I can say: tags can be treated as a meta data about your values.
  4. Value fields can have one of types: string, float, integer, boolean. They should contain raw data, they are indexed by tags and timestamps.

In your case I would use structure:

  • One measurement, i.e. "usages"

  • tag key: "state" (String, each state - CA, WA, MO, etc.) - you will be able to easily filter (where clause) and "group by" this tag your "usage" values

  • value fields: "usage" (float/integer)

like image 77
Crashtein Avatar answered Oct 19 '25 12:10

Crashtein