This is an old revision of the document!


InfluxDb

cheat sheet / examples https://www.sqlpac.com/en/documents/influxdb-flux-language-advanced-features.html#influxdb-v2-quick-reminders

influxdb 3

from(bucket: "bucket")
  |> range(start: -2h)
  |> filter(fn: (r) =>  exists r.nas_name)
//   |> group(columns: ["nas_name","_measurment"])
  |>last()
  |> yield(name: "unique")
import "influxdata/influxdb/schema"
 
FROM(bucket: "sensors")
//   |> range(START: v.timeRangeStart, stop: v.timeRangeStop)
  |> range(START: 2024-02-20T01:00:00Z, stop: 2024-02-20T02:00:00Z)
  |> FILTER(fn: (r) => r["_measurement"] == "netflow")
  |> FILTER(fn: (r) => r["host"] == "gorkii21")
  |> FILTER(fn: (r) => r._field == "direction" OR r._field == "dst" OR r._field == "in_bytes")
  |> schema.fieldsAsCols()
  |> FILTER(fn: (r) => r["direction"] == "ingress")  
  |> FILTER(fn: (r) => r["dst"] == "192.168.114.109")   
  |> duplicate(COLUMN: "in_bytes", AS: "_value")
  |> duplicate(COLUMN: "dst", AS: "_measurement")
  |> GROUP(COLUMNS: ["_measurement","_start"])
  |> aggregateWindow(every: 5m,  fn: SUM, createEmpty: FALSE)
// //   |> GROUP(COLUMNS: ["dst"])
// //   |>SUM()
//        
//   |> SUM()
//   |> yield()
//   
//   |> DROP(COLUMNS: ["host"])  
//   |> aggregateWindow(every: v.windowPeriod, fn: LAST, createEmpty: FALSE)
 
++++ FIELDS|
_measurement
direction
dst
dst_port
first_switched
flow_end_reason
host
icmp_code
icmp_type
in_bytes
in_packets
in_snmp
ip_version
last_switched
out_snmp
protocol
SOURCE
src
src_port
src_tos
tcp_flags
version
++++
  • linux/influxdb.1708567644.txt.gz
  • Last modified: 2024/02/22 02:07
  • by admin