Browse Source

influxdb: use tags instead of multiple measurements

Francois Deppierraz 1 year ago
parent
commit
688c305e3f
2 changed files with 5 additions and 2 deletions
  1. 1 1
      csv-to-influxdb.py
  2. 4 1
      logger.py

+ 1 - 1
csv-to-influxdb.py

@@ -16,4 +16,4 @@ client = DataFrameClient(database='power')
 
 for key, df in d.groupby('sensor'):
   print(key)
-  client.write_points(df, key, batch_size=100000)
+  client.write_points(df, 'flukso', {'sensor': key}, batch_size=100000)

+ 4 - 1
logger.py

@@ -43,8 +43,11 @@ while True:
         results.append((",".join((str(timestamp), sensor, str(value)))))
 
       db.write_points([{
-                 "measurement": sensor,
+                 "measurement": "flukso",
                  "time": datetime.fromtimestamp(timestamp).isoformat(),
+                 "tags": {
+                    "sensor": sensor,
+                 },
                  "fields": { "watts": float(value) }
                } for timestamp, value in flukso])
     except Exception as e: