Extracting metrics from logs

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

Manage your metrics in Sourcesyour sourceConfigureExtract Metrics tab.

Creating metrics and labels

Add a new metric by clicking the + Metric button. Similarly, add a new label by clicking the + Label buton. Then, 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:

    • Extract a numeric field from your logs such as request.duration_ms, use JSONExtract(raw, 'request', 'duration_ms', 'Nullable(Float64)').
    • Extract number from message texts such as in 12.34ms, you can use toFloat32OrNull(extract(JSONExtractString(raw, 'message'), 'in (\d+(\.\d+)?)ms')).
    • Calculate approximate size of the log using LENGTH(raw).
    • See all ClickHouse data types and built-in functions.
  • 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.

Label values have a maximum length of 4096 characters; any values longer than this will be truncated.

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: