# Set Up Freshness & Volume Monitors

Our Freshness monitors observe the time elapsed since the last update or insertion in a table, learning from the update frequency and alerting if delays arise. Similarly, Volume monitors gauge the number of rows added to a table. If the row count differs significantly from expected patterns based on past data, an incident is triggered.

The process to set up monitoring for Freshness and Volume monitors (both Scheduled and On Demand) is alike. To illustrate, let's walk through setting up monitoring using Freshness as our example.

Begin by selecting "Freshness" card from Create subtab on Config

{% hint style="info" %}
Set up monitoring pop up for **scheduled monitors** is the **same** for both Volume and Freshness Monitors.
{% endhint %}

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-49bdf06e3de0ef4166f7201fb666fef75e5d793b%2Fimage%20(507).png?alt=media" alt=""><figcaption><p>Overview of selecting monitor card</p></figcaption></figure>

Once selected, you’ll be redirected to the **“Create a New Monitor”** form.

* The **“Create a New Monitor”** form consists of two steps:
  1. **Set up**
  2. **Configure**

{% hint style="info" %}
The form fields will become available as you select the mandatory options.
{% endhint %}

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-02a0a995dbe160c466a8b4d0565c4fc146b23057%2Fimage.png?alt=media" alt=""><figcaption><p>Overview for different steps in the form</p></figcaption></figure>

### Step 1: Set up

* Select the `Source` and `Schema` selection is optional
* Select the `Dataset`
* Choose `Monitor mode`: Scheduled or On-Demand

{% hint style="info" %}
For a detailed understanding of monitor modes, check out [**Available Monitor Modes**](https://docs.decube.io/data-quality/available-monitor-modes)
{% endhint %}

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-015523674c3518feee774e697b2e16584787a0be%2Fimage.png?alt=media" alt=""><figcaption><p>Overview for setting up monitor</p></figcaption></figure>

{% hint style="info" %}
For a detailed understanding of Grouped By, check out [Grouped-By Monitors](https://docs.decube.io/data-quality/how-to-set-up-monitors/set-up-grouped-by-monitors)
{% endhint %}

* **Enable “Grouped By” (if applicable)** by toggling the switch.
* Select the column for grouping and click **Validate**.
* A success message (**“Column is valid to be grouped by”**) confirms validation.

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-4d103cf5b8ef0845e7433080d4c1d120f5929535%2Fimage%20(271).png?alt=media" alt=""><figcaption><p>Grouped-by toggle disabled</p></figcaption></figure>

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-0700ec0ccc2bda53b763ecbc2aaaba295410e885%2Fimage%20(272).png?alt=media" alt=""><figcaption><p>Grouped-by toggle enabled with success message</p></figcaption></figure>

* Click **“Proceed to Monitor Setup”** to move to the next step.

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-672b3f190e2c9538d02fe7aa73598132d2712166%2Fimage%20(273).png?alt=media" alt=""><figcaption><p>Overview for selecting Monitor mode</p></figcaption></figure>

### Step 2: Configure: Scheduled Monitor

* Once you proceed to setup, you’ll reach the **“Configure”** page, where you can review your previous selections.

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-058c5b55f53db31e256f6653eb63886393dee624%2Fimage.png?alt=media" alt=""><figcaption><p>Overview for previous selection</p></figcaption></figure>

In the “Configure” popup, users must complete the required fields to save their preferences and set up their Freshness/Volume monitor. These required fields include:

{% hint style="info" %}

* Can create multiple tests for each test type per column/table

* Able to add a test name to differentiate monitors created
  {% endhint %}

* **Monitor Name**

* **Monitor Description** is Optional.

* **Row Creation:** Select the Row creation from given options:
  * **Timestamp** (Select Timestamp from the dropdown column)
  * **Validation for SQL Expression** (when SQL Expression is chosen)
  * **All Records**
  * **Enable Smart Training(Optional):** Train your monitor on historical data to reduce the training period
  * **Frequency** (Learn more about [**Custom Scheduling For Monitors**](https://docs.decube.io/data-quality/custom-scheduling-for-monitors))

### **SQL Expression**

SQL Expressions allow you to convert your non-standard timestamp formats into timestamp when setting up scheduled or on-demand monitors. This allows you to utilize the incremental monitor scanning functionality based on a given timestamp column.

{% hint style="info" %}
When using **SQL Expression:**

* Validating your query is compulsory.
* Ensure your query is written in the **SQL dialect** compatible with your linked data source (e.g., BigQuery, PostgreSQL, Snowflake).
* SQL Expressions are typically used **after the WHERE clause** to filter records.
  {% endhint %}

**Common Use Cases & Examples**

* **Converting a String Column to a Timestamp**
  * Some datasets store timestamps as strings, requiring conversion.

For example:

**BigQuery-** CAST(your\_string\_column AS DATETIME)

**PostgreSQL-** your\_string\_column::timestamp

When working with Google BigQuery, you can review the provided documentation for further details [here](https://cloud.google.com/bigquery/docs/reference/standard-sql/conversion_functions#cast_as_datetime).

* **Converting Unix Timestamp to a Datetime**
  * If timestamps are stored as Unix epoch time (seconds or milliseconds), conversion is required.

For example:

**BigQuery-** TIMESTAMP\_SECONDS(your\_unix\_column)

**PostgreSQL-** TO\_TIMESTAMP(your\_unix\_column)

* **Combining Separate Date and Time Columns**
  * Some databases store date and time in separate columns, requiring concatenation.

For example:

(use date\_column || ' ' || time\_column)

**When Should You Use SQL Expressions?**

* Use SQL Expressions when:
  * Your timestamps are stored as strings instead of actual timestamp values.
  * Your dataset uses Unix timestamps instead of standard date/time formats.
  * You have separate date and time columns that need to be combined.
* If your data already contains a proper timestamp column, you can simply select it without needing an SQL Expression.

### Smart Training

Smart Training automatically learns patterns from historical data to enhance row creation and threshold settings. It helps users define dynamic monitoring parameters by analyzing past trends, improving anomaly detection and data quality insights.

{% hint style="info" %}
**Smart Training** is applicable for both Row Creation and Threshold settings.

To activate Smart Training in Row Creation:

* Users should initially select the timestamp.
* If SQL Expression is chosen for row creation, users are required to validate the SQL Expression.

When Smart Training is activated for Row Creation, it enables the option to choose the Lookback Period. It's important to note that the Lookback Period becomes selectable only when Smart Training is enabled.
{% endhint %}

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-293f9b885e857ccaebcfc472c40c95e435753e1a%2Fimage.png?alt=media" alt=""><figcaption><p>Overview of Configuring monitor</p></figcaption></figure>

## Get Notified/Custom Alert

* To set custom alerts, first, turn on the `"Notify default channel"` toggle. This enables users to specify their preferred alert channels, such as email or Slack.
  * Select the desired alert channels from the dropdown.
  * Enter the email address or Slack channel name in the provided field.
* Finally, specify the **Incident Level**.

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-3d64196506fc41e74ea7482fe0c14ce8cf2b0f77%2Fimage.png?alt=media" alt=""><figcaption><p>Overview for setting notification</p></figcaption></figure>

* Click on `Submit` to create your monitor successfully.
* Once the monitor is created, you will be redirected to the ALL MONITORS tab.

### Step 2: Configure: On-demand Monitor

{% hint style="info" %}
**Note: Key Differences:**

i. The **"Frequency"** field is not applicable for On-Demand monitors and is therefore neglected.

ii. The **"Enable Smart Training"** and **"Auto Threshold"** options are not considered when setting up an On-Demand monitor.

iii. **"Grouped By"** is not available in On-Demand monitor mode.
{% endhint %}

* Select **On-Demand** as the Monitor Mode and click **“Proceed to Monitor Setup”**.

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-d7cc00edc72c8d5bf3ed2e0d09a19de1270ccbf2%2Fimage.png?alt=media" alt=""><figcaption><p>Overview for selecting Monitor Mode</p></figcaption></figure>

* Within the 'Configure' popup, users must complete the required fields to save their preferences and successfully set up their Freshness/Volume Monitor. The required fields include:

{% hint style="info" %}

* Can create multiple tests for each test type per column/table
* Able to add a test name to differentiate monitors created
  {% endhint %}

- **Monitor Name**
- **Monitor Description** is Optional.
- **Row Creation:** Select the Row creation from given options:
  * **Timestamp** (Select a timestamp column from the dropdown)
  * **Validation for SQL Expression** (when SQL Expression is chosen)
- **Lookback Period**
- **Incident Levels**

{% hint style="info" %}
**Custom Notifications:** Custom alerts can be configured as in scheduled monitors.

Mention the link to the **Get Notified/Custom Alert**
{% endhint %}

**Finalizing On-Demand Monitor Setup**

* Upon completing the required fields to create an On Demand monitor for Freshness/Volume, users can complete the setup process by choosing one of the following confirmation buttons based on their preferred use case:
  * `Save`: Creates the monitor without running it. This is an applicable option for users who wish to set up an On-Demand monitor without running the monitor scan immediately after creation.
  * `Save and run` : Runs the On-Demand Monitor immediately upon creation. To run the monitor again later, users can navigate to **All Monitors**.
  * After selecting the above option you will be redirected to ALL MONITORS tab.

**Modify Monitoring**

To modify an existing monitor:

1. Go to [**All Monitors**.](https://docs.decube.io/enable-asset-monitoring#all-monitors-tab)
2. Click the ellipsis (︙) and select **View Monitor**.
3. Click on `Run once` to run the monitor manually.

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-e0072bd583c307e530cbdb92c9694a6df30f52e6%2Fimage.png?alt=media" alt=""><figcaption><p>Overview for Modify form through All Monitors</p></figcaption></figure>
