# Building monitors

In your project you can currently build as many monitors as you like, there is no restriction to the number of monitors in the free plan.

## How to build a monitor

To navigate to the page for building the monitor you can either open `Explore` from the side navigation or on your monitors overview page click the `Add Monitor` button on the top right

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2Fd1BeJocY1a6GNVTDqOR0%2FScreenshot%202024-02-28%20at%2013.30.36.png?alt=media&#x26;token=7fbb660a-27ec-484a-8737-39e017e6f2a5" alt=""><figcaption></figcaption></figure>

### 1. Building the monitor query

1.1. Selecting the data source(s)

* The available data sources to build a monitor data query on are shown in a drop down. The `chain logo` indicates which chain this smart contract has been deployed on, folowed by the `Name` of the smart contract given by you when you added the smart contract

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2Flm1fS1Jo4HeUYqYx8xBz%2FScreenshot%202024-02-28%20at%2013.31.44.png?alt=media&#x26;token=71f359cc-3560-46d2-92f4-9d41ff328ade" alt=""><figcaption></figcaption></figure>

* You can choose one or multiple of them
* Chosen smart contracts can be deployed on different chains to build a cross-chain query

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2F47DwEAJJIf55hywHSMby%2FScreenshot%202024-02-28%20at%2013.32.36.png?alt=media&#x26;token=ce0d6477-887e-42b4-a583-17551ae4c511" alt=""><figcaption></figcaption></figure>

1.2. Selecting the metric to monitor from the drop down list

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FwDZIl3w4Jv0HBe3PuG8x%2FScreenshot%202024-02-28%20at%2013.44.49.png?alt=media&#x26;token=41e7b384-345f-41a1-bbc7-de3bd39c9c9e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FqlCNEjiIQD8UREGJ5MoM%2FScreenshot%202024-02-28%20at%2013.44.36.png?alt=media&#x26;token=ae3601e4-01cd-44a5-80bf-31fcfa2cb931" alt=""><figcaption></figcaption></figure>

1.3. Selecting specific events or state variables if the metric to monitors is `Transaction Event` or `Transaction State Variables.` All events or state variables detected that are avaiable to monitor are showin in the drop down. In case of a long list simply start writing the name of the variable the the list will update

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FdAcMMbCScoguDDLIYfFp%2FScreenshot%202024-02-28%20at%2013.45.36.png?alt=media&#x26;token=09fc877b-2d56-4e9c-b1e3-69758fb9bafc" alt=""><figcaption></figcaption></figure>

1.4. Setting conditionional filters. Setting filters is optional and can be dismissed. Based on the condition you choose the operator list differs. Multiple conditions can be concatenated

* `Transaction Status`&#x20;
  * Type: `string`&#x20;
  * Available operators: `=` (equal) and `!=` (not equal)
  * Values: `SUCCEEDED` or `REVERTED`&#x20;
* `Transaction Gas Used`, `Transaction Count`, `Transaction Index`, `Transaction Value`, `Transaction Gas Price` and `Max Fee Per Gas`
  * Type: `integer`
  * Available operators:`=` (equal), `!=` (not equal), `>` (larger than), `<` (smaller than), `>=` (larger and equal than) and `<=` (smaller and equal than)
  * Values: integers from 0 to bignumber

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FyVILBllhWwJEBK8Z6ZBA%2FScreenshot%202024-02-28%20at%2013.47.05.png?alt=media&#x26;token=a96cf89f-914b-45f5-b14d-7bf527130934" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FC0ygSylMV9UJgOgb52BX%2FScreenshot%202024-02-28%20at%2013.47.11.png?alt=media&#x26;token=fcca1105-72d1-48f8-b94d-04668a775748" alt=""><figcaption></figcaption></figure>

1.5. Grouping by is set to `None` by default, and can also be set to `Address`, `Blockchain`, `Signature` or `Event`

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FutG58pDk2fkHf5igthPE%2FScreenshot%202024-02-28%20at%2013.45.05.png?alt=media&#x26;token=8bfd622c-78e5-48ea-9503-970b92191f28" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FaJU8zkTSW6taK2AulfdX%2FScreenshot%202024-02-28%20at%2013.44.54.png?alt=media&#x26;token=6dcce03c-f2c9-48b5-8393-f0f375f1cd66" alt=""><figcaption></figcaption></figure>

1.6. Choosing the mathematical operation to be performed on the query. The possible options are `AVG` (average), `COUNT`, `SUM`, `MIN` (minimum), `MAX` (maximum)&#x20;

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2F6FFYJ864gRwONsPcGF9n%2FScreenshot%202024-02-28%20at%2013.45.15.png?alt=media&#x26;token=36373417-7a21-46f0-8b6b-9de9c13cfafb" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FVl4BKUrjdQvQ30e6uX6t%2FScreenshot%202024-02-28%20at%2013.45.10.png?alt=media&#x26;token=868cef79-f33c-40f8-96bd-9f84c951f94f" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
Once you have fully set the query you will see the data visualized in the chart above. In our example query we are comparing  the accumulated (=`SUM` as math operation) number of transactions (= Transaction `Count` as metric) on the Uniswap SwapRouter on Ethereum and Arbitrum (= `Data Sources`) by grouping by `Blockchain`

{% endhint %}

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FxF0sJE9tKxz852p3XLw2%2FScreenshot%202024-02-28%20at%2013.47.26.png?alt=media&#x26;token=56e81711-388c-444f-8b45-477e51f0e294" alt=""><figcaption></figcaption></figure>

### 2. Setting the monitor time window

The time window of the monitor specifies the period the metric shall be calculated on on a roll basis. In our example above we calculate the amount of transactions on a 1 hour rolling basis.&#x20;

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2Fp9kJlmP3prUdF3aUsKwp%2FScreenshot%202024-02-28%20at%2013.47.53.png?alt=media&#x26;token=1be600b2-7cd5-43e4-a6ac-c474142b8bc1" alt=""><figcaption></figcaption></figure>

### 3. Setting the monitor target

The target of the monitor has an important implication for the [alerting](https://docs.blocktorch.xyz/use-cases/monitoring/alerting) functionality. As soon as the target is hit by the metric a notification will be triggered.&#x20;

The target is visualized in your monitor chart as a horizontal red line, any datapoint crossing the target is also visualized in red in your chart.

Type of the target is always an `integer.` If you are unsure where to set your target it makes sense to (1) analyze the chart of your query above and look into the range of y-axis values your data usualy moves in. A certain area outside of this norm range might be a suitable target (2) once you have set the monitor make sure to revisit regularly and adjust the target accordingly&#x20;

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FytrjWnRih3im9bHd8nDh%2FScreenshot%202024-02-28%20at%2013.47.56.png?alt=media&#x26;token=03160c9f-ed9f-4633-8d59-5ae4894825ef" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
Once you have set the time window to compute the metric and the  target your graph will be updated accordingly
{% endhint %}

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FlnhFKWKguZfY6pxlMLv2%2FScreenshot%202024-02-28%20at%2013.48.35.png?alt=media&#x26;token=a4eda459-2e44-4047-9160-1b153b5796ab" alt=""><figcaption></figcaption></figure>

### 4. Adding context with a title

For the purpose of context and also for searchability later on, add a descriptive Title to your monitor

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FXNynyhFTwvfaf0OwDWwA%2FScreenshot%202024-02-28%20at%2013.48.25.png?alt=media&#x26;token=a8701431-476f-4c87-92ab-76f9b952be27" alt=""><figcaption></figcaption></figure>

### 5. Saving the monitor

To finish the setup of your monitor hit the save button on the top right corner.

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FlnhFKWKguZfY6pxlMLv2%2FScreenshot%202024-02-28%20at%2013.48.35.png?alt=media&#x26;token=a4eda459-2e44-4047-9160-1b153b5796ab" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
The new monitor will now show up in your monitors overview page. The chains you grouped by show up as the chain IDs.  When clicking the pencil on the top right you can update your monitor
{% endhint %}

<figure><img src="https://4201788747-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5vTnL6SrT2qX7rXjH96E%2Fuploads%2FqrUIJLD1yRuYZoZJEFN0%2FScreenshot%202024-02-28%20at%2015.06.14.png?alt=media&#x26;token=2d873584-98c6-4e38-b953-c5be8ed013d7" alt=""><figcaption></figcaption></figure>
