InfluxDB 2.0 之Flux语法篇
生活随笔
收集整理的這篇文章主要介紹了
InfluxDB 2.0 之Flux语法篇
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
由于項目?IoTSharp 需要支持?InfluxDB??, 因此進行了初步嘗試, 雖然?Flux 語法初次學習, 但查詢語句卻似曾相識, 如果改一下 標點符號, 你會完全認為他是 C#的拉姆達表達式,?
首先看一下寫入數據:
using (var writeApi = influxDBClient.GetWriteApi()){//// Write by Point//var point = PointData.Measurement("temperature").Tag("location", "west").Field("value", 55D).Timestamp(DateTime.UtcNow.AddSeconds(-10), WritePrecision.Ns);writeApi.WritePoint("bucket_name", "org_id", point);//// Write by LineProtocol//writeApi.WriteRecord("bucket_name", "org_id", WritePrecision.Ns, "temperature,location=north value=60.0");//// Write by POCO//var temperature = new Temperature {Location = "south", Value = 62D, Time = DateTime.UtcNow};writeApi.WriteMeasurement("bucket_name", "org_id", WritePrecision.Ns, temperature);}寫入數據看起來類似于 1.0 但是 增加了 bucket 和org這些信息。?
新版本的查詢則更有意思:
from(bucket: "iotsharp-bucket")|> range(start: v.timeRangeStart, stop: v.timeRangeStop)|> filter(fn: (r) => r["_measurement"] == "TelemetryData")|> filter(fn: (r) => r["DeviceId"] == "a649a429-e82c-406b-8b8e-a3ba48c868fb")|> yield()_measurement 相當于表名 ?
DeviceId 其實類似 濤思時序數據庫中的 tags 字段,?
同時 , 也有類似group之類的語句, 比如
如果你想只要 年齡或者 用戶名之類的字段 可以使用 類似下面的用法
欲了解更多C#中訪問?InfluxDB 2.0 的方法, 可以參考我們的代碼:
https://gitee.com/IoTSharp/IoTSharp/blob/master/IoTSharp/Storage/InfluxDBStorage.cs?
總結
以上是生活随笔為你收集整理的InfluxDB 2.0 之Flux语法篇的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 程序员过关斩将--真的可以用版本号的方式
- 下一篇: 在IIS中部署SPA应用,多么痛的领悟!