# Extracting metrics from logs

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

Manage your metrics in [Sources](https://telemetry.betterstack.com/team/0/sources ";_blank") → **your source** → **Configure** → **Extract 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](https://clickhouse.com/docs/en/sql-reference/functions). 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](https://clickhouse.com/docs/en/sql-reference/data-types) and [built-in functions](https://clickhouse.com/docs/sql-reference/functions/regular-functions).

-   **Aggregations**: Choose [aggregations](https://clickhouse.com/docs/en/sql-reference/aggregate-functions) 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.

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

## 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:

<div style="position: relative; padding-bottom: 56.25%; height: 0;"><iframe src="https://www.loom.com/embed/eb9015eb79af4bfeba5997b81b4d4b71?sid=50adffb2-fa74-4a9b-929d-1f4825283cb3" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div>
