-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to query Metrics (Counters, Histogram, Gauge) with ClickHouse exporter? #26494
Comments
Pinging code owners:
See Adding Labels via Comments if you do not have permissions to add labels yourself. |
🚶🏻 |
@Frapschen is the author of metrics exporter. Could you help such as add more example of query metrics sql? |
@Frapschen friendly ping. Short feedback would be enough to understand its limitations. |
Sorry, I also lack relevant experience, but https://grafana.com/grafana/plugins/vertamedia-clickhouse-datasource/ provides some functions to help query time series data, hope that can help you. |
Hi @Frapschen unfortunately not. The examples are very minimal and don't explain much. Gauge and Histogramm are missing. Thank you anyway. We will continue to use the Clickhouse exporter for logs and traces only. |
@StarpTech I try to write a Histogram metrics query demo
table schema && mocked data
It's looks lile:
create help functions:
P95
|
Hi @Frapschen thanks for the additional effort. I took another look. We will start to collect metrics with delta temporality. In that way, we can deal with metrics much simpler. We don't have to handle counter resets. We can sum it up or use |
@Frapschen how would you use your approach in a materialized view where you need to aggregate to get the correct result? It would be great if we could somehow use clickhouse -State function for that. I found SELECT quantilesExactWeighted(0.5, 0.95, 0.99)(Bin, DCount) as DurationQuantiles FROM otel_metrics_histogram
ARRAY JOIN BucketCounts AS DCount, arrayMap(x -> if(x = length(ExplicitBounds)-1, ExplicitBounds[length(ExplicitBounds)-1], ExplicitBounds[x]), arrayEnumerate(BucketCounts)) AS Bin
WHERE DCount > 0 AND MetricName = 'router.http.request.duration_milliseconds' Result:
|
@Frapschen your percentile calculation pre-work is great. I modified it a bit to make it work like https://github.com/prometheus/prometheus/blob/main/promql/quantile.go#L111 CREATE FUNCTION func_rank as (q,buckets) -> q*arraySum(buckets);
CREATE FUNCTION func_rank_bucket_lower_index as (rank,buckets) -> arrayFirstIndex(x -> if(x >= rank, 1, 0),arrayCumSum(buckets));
CREATE FUNCTION func_histogram_v2 as (rank,b,buckets,bounds) ->
-- When +inf is matched, we return the last bucket's upper bound
if(b = length(buckets), bounds[length(bounds)],
if(b > 1,
-- if the bucketLowerIndex is greater than 1, we interpolate between the lower and upper bounds of the bucket
bounds[b] + (bounds[b+1] - bounds[b]) *
(minus(rank,arrayElement(arrayCumSum(buckets),minus(b,1))) /
minus(arrayElement(arrayCumSum(buckets),b), arrayElement(arrayCumSum(buckets), minus(b,1)))),
-- else
bounds[b+1] * (rank / arrayElement(arrayCumSum(buckets),b))
)
); Usage select
toStartOfFiveMinute(TimeUnix) as Timestamp,
-- Begin P95
func_rank(0.95, BucketCounts) as rank95,
func_rank_bucket_lower_index(rank95, BucketCounts) as b,
func_histogram_v2(
rank95,
b,
BucketCounts,
ExplicitBounds
) as P95,
-- P95 end
-- Histogram aggregations
sumForEach(BucketCounts) as BucketCounts,
sum(Sum) AS Sum,
sum(Count) AS Count,
min(Min) AS Min,
max(Max) AS Max
from otel_metrics_histogram
GROUP BY Timestamp, ExplicitBounds
ORDER BY Timestamp |
This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping Pinging code owners:
See Adding Labels via Comments if you do not have permissions to add labels yourself. |
This issue has been closed as inactive because it has been stale for 120 days with no activity. |
Component(s)
exporter/clickhouse
Describe the issue you're reporting
Hello, we would like to utilize the ClickHouse exporter for metrics. Regrettably, we have been unable to locate any examples demonstrating how metrics are queried within the intended schema. If you conduct some research on how ClickHouse handles time-series data, you will discover only a limited number of resources available. Furthermore, the documentation on functions is quite minimal. There is no article or function that covers counter resets. It would be immensely helpful if the author of the exporter could offer some insights into the querying of data. For instance, a single example for counters (rate, latest), gauges (avg_over_time), and histograms (p95) would suffice. Thank you in advance.
Maybe @hanjm you can provide help here.
The text was updated successfully, but these errors were encountered: