- Execute recurring Clickhouse
queries
- Exctract mapped
labels
andvalues
- Aggregate results using
metric buckets
- Publish as
prometheus
metrics
Clickheus acts according to the parameters configured in its config.js
file.
The following example illustrates mapping of clickhouse
query columns to metric labels and values.
Let's use the following fictional my_index
table as our datasource:
datetime | status | group |
---|---|---|
1631825843 | FINISHED | default |
1631825844 | FAILED | default |
1631825845 | FINISHED | default |
1631825846 | FAILED | custom |
1631825847 | FINISHED | default |
... | ... | ... |
Using the prom_metrics
array, define and name new bucket
and its definitions.
- Type can be
gauge
orhistogram
- LabelNames should match the target tag columns
"prom_metrics": [{
"name": "g",
"type": "gauge",
"settings": {
"name": "my_count",
"help": "My Counter",
"maxAgeSeconds": 60,
"labelNames":[
"status",
"group"
]
}
}]
Using the queries
array, define a clickhouse
query to execute and associate it with metrics bucket g
- Place your tags first in the query
- Place your metric value last, and mark its position using the
counter_position
parameter (count from 0). - Match the refresh rate in milliseconds to match the query range (ie: 60 seconds)
"queries":[{
"name": "my_status",
"query": "SELECT status, group, count(*) FROM my_index FINAL PREWHERE (datetime >= toDateTime(now()-60)) AND (datetime < toDateTime(now()) ) group by status, group",
"counter_position": 2,
"refresh": 60000,
"metrics":["g"]
}]
Connect to the configured /metrics
HTTP endpoint defined in your configuration and await data
# HELP my_count My Counter
# TYPE my_count gauge
my_count{status="FINISHED",group="default"} 10