Converting logs to metrics

You can extract any data from your logs, and use it as a metric in Dashboards.

Manage your metrics in Sources → your source → Configure → Logs to metrics tab.

Creating metrics

Add new metric by clicking the + Metric button and fill out the inputs:

  • Metric: Name your metric.

  • JSON dot notation: Extract nested fields using JSON path - e.g. context.user.email. For more complex metrics write your own SQL expression.

  • SQL expression: Use JSONExtract() or any valid ClickHouse SQL expression.

    • For example, use JSONExtract(json, 'request', 'duration_ms', 'Nullable(Float64)') to extract request.duration_ms field from your logs.
    • Using 'Nullable(Float64)' parses the value as float and prevents errors when the field is missing. See all ClickHouse data types.
  • Aggregations: Choose aggregations you want to use in your queries. You can select multiple aggregations. For example, use avg and p95 to get the average and 95th percentile values.

    • Choose No aggregation to get a metric without any aggregations you can use for grouping.

Screenshot of adding a new metric

Want to keep your bill low?

Keep in mind the number of aggregations and the number of unique values in non-aggregated metrics directly affect your bill.

Learn how we bill for metrics in detail.

Video tutorial on creating metrics

This short tutorial will show you how to process data from your application logs and create a custom dashboard with charts using Logs to metrics: