> For the complete documentation index, see [llms.txt](https://docs.upriverdata.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.upriverdata.com/monitoring/custom-metrics.md).

# Custom Metrics

Define and monitor custom metrics tailored to your needs so you can create expectations and monitor anything in your data. Simply define SQL query for the metric, and Upriver will handle the rest -profiling the metric and setting up real-time monitoring to track adherence to expectations.

<figure><img src="https://875415170-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLE0zsJmUpeLjYw085cnO%2Fuploads%2Fd8wnVXUCW96MZMp09zxK%2Fimage.png?alt=media&amp;token=03128671-e4a5-4f5d-8fec-4076ad6cede9" alt=""><figcaption><p>Custom defined user metric calculated based on fields in the data source</p></figcaption></figure>

### Metric Tracking

For each custom metric, Upriver applies all the automated monitors as they would be for any other field. See [Field Behavior Monitoring](/monitoring/field-behavior-monitoring.md).

### Metric Status

* <mark style="color:green;background-color:green;">Running</mark> - The metric was successfully retried in the last contract update run.
* <mark style="color:red;background-color:red;">Failed</mark> - The metric was not updated in the last contract update run due to an error.
* <mark style="color:yellow;background-color:yellow;">Pending</mark> - There has been no contract update since the metric was last defined.

### Defining a Custom Metric

From the [datasource details page](/product-usage/data-assets/data-source.md), clicking on the tab Custom Metrics. This should open a list of all the custom metrics currently defined for the given data source.

<figure><img src="https://875415170-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLE0zsJmUpeLjYw085cnO%2Fuploads%2Fif34DSEC3uOeWNmD1rVs%2Fimage.png?alt=media&amp;token=b1b17504-3707-47f5-bbae-d9bdf9829b53" alt=""><figcaption><p>List of defined custom metrics for a data source</p></figcaption></figure>

In this tab, click on the `Add Custom Metric` button and a dialog will open.

<figure><img src="https://875415170-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLE0zsJmUpeLjYw085cnO%2Fuploads%2FMnVUIbvuEd5w6hTseRaZ%2Fimage.png?alt=media&amp;token=f0ab9def-bf1b-4689-993f-24064820bae1" alt=""><figcaption><p>New metric dialog</p></figcaption></figure>

In the new dialog, enter the name of the metric and the custom SQL query that will be used to define the metric.

Users can decide to select the `Validate query` checkbox. This will ensure that the query is valid by checking both the syntax and validating that the fields used in the query exist and are of the relevant type according to the existing data contract for the data sourcee.

### Updating an existing metric

To update an existing metric, expand the metric row in the list and select the metric definition tab. Within the sql editor presenting the query definition, click on the edit button. This opens the `Edit Custom Metric` dialog and allows you to change the metric.

{% hint style="info" %}
If the metric has been updated, the existing profiles for the metrics will be continue to be update. If you want to reset them, please delete the current metric and create a new one.
{% endhint %}

### Deleting a Custom Metric

From the custom metric list, select the rows you want to select using the select box. Once metrics are selected, a trash icon (:wastebasket:) will appear next to the `Add Custom Metric` button. Clicking on it will delete the defined metric.
