02_create_flows_table.sql 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. CREATE TABLE IF NOT EXISTS flows (
  2. -- Identity
  3. flow_id String,
  4. host_id String,
  5. host_name String,
  6. network_id String,
  7. -- Flow metadata
  8. protocol UInt16,
  9. src_port UInt16,
  10. dst_port UInt16,
  11. icmp_type UInt8,
  12. icmp_code UInt8,
  13. direction Enum8('ingress'=1, 'egress'=2),
  14. -- Participants
  15. src_ip String,
  16. src_type Enum8('node'=1,'user'=2,'extclient'=3,'egress_route'=4,'external'=5),
  17. src_entity_id String,
  18. src_entity_name String,
  19. dst_ip String,
  20. dst_type Enum8('node'=1,'user'=2,'extclient'=3,'egress_route'=4,'external'=5),
  21. dst_entity_id String,
  22. dst_entity_name String,
  23. -- Timestamps
  24. start_ts DateTime64(3),
  25. end_ts DateTime64(3),
  26. -- Metrics
  27. bytes_sent UInt64,
  28. bytes_recv UInt64,
  29. packets_sent UInt64,
  30. packets_recv UInt64,
  31. -- Conntrack status bitmask
  32. status UInt32,
  33. -- Logical version / event time (for merging)
  34. version DateTime64(3)
  35. )
  36. ENGINE = ReplacingMergeTree(version)
  37. PARTITION BY toYYYYMMDD(version)
  38. ORDER BY (network_id, host_id, flow_id, version);