Skip to content

ClickHouse Metrics

Lorenzo Mangani edited this page Jan 13, 2021 · 28 revisions

ClickHouse Metrics

cLoki provides a simplified query model for generating metrics and tags dynamically out of clickhouse tables.

Query Options
parameter description
db clickhouse database name
table clickhouse table name
tag column(s) for tags, comma separated
metric function for metric values
where where condition (optional)
interval interval in seconds (optional)

Example

clickhouse({ 
  db="my_database", 
  table="my_table", 
  tag="source_ip", 
  metric="avg(mos)", 
  where="mos > 0", 
  interval="60" 
})
Clickhouse Query
SELECT source_ip, groupArray((t, c)) AS groupArr 
FROM (
  SELECT (intDiv(toUInt32(record_datetime), 60) * 60) * 1000 AS t, source_ip, avg(mos) c 
  FROM my_database.my_table 
  PREWHERE record_datetime BETWEEN 1610533076 AND 1610536677 AND mos > 0 
  GROUP BY t, source_ip ORDER BY t, source_ip
) 
GROUP BY source_ip ORDER BY source_ip

cloki

Clone this wiki locally