# Build a SLI

SLIs are key metrics that measure specific aspects of your service's performance and reliability. By following these steps, you'll learn to configure effective SLIs to monitor your service quality.

{% hint style="info" %}
Before writing a SLI query, the engine asks you to state whether you are defining a Value SLI (e.g. latency, MTTD) or a Percentage SLI (e.g. uptime, error rate). It does so to allow for maximum flexibility in terms of the Objective (SLO) you get to define later, as the two streams demand different treatment to produce error free results.
{% endhint %}

## Create a Value SLI

Follow these steps to create a Value Service Level Indicator (SLI):

1. Find and click on "Indicators" in the side navigation bar
2. Click the "+ New SLI" button to open the Create SLI modal
3. Choose "Value" as the type of SLI you'll be building
4. **Choose a metric query, aggregator, and filter**
   1. <mark style="color:orange;">**Allowed aggregators**</mark>**:** `COUNT`, `SUM`, `MAX`, `MIN`, `AVG`

      `n/a` is also an acceptable input; this will output an array of metrics without any aggregation
   2. <mark style="color:orange;">**You can create multiple queries**</mark> by clicking "+ New Query" and add a formula in the formula box to define the relationship between them.&#x20;
   3. <mark style="color:orange;">**Operators allowed on the formula builder**</mark>: `*` , `/`, `+`, `-` , `<` , `>` , `<=` , `>=,` `=` , `!=`
5. Provide a clear, descriptive name for your SLI and a description to explain its purpose and function.
6. Click the "Save" button to create your new Value SLI.

### Examples

{% tabs %}
{% tab title="List of Latencies" %}
**QUERY**

**A: SELECT** {`n/a`} {`latency_metric`} **FROM** {`key`} **WHERE** {`status_code < 500`}

Unit `ms`

Example implementation 👇

<figure><img src="https://711169838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXD619BqgHmtAt8T9VUqw%2Fuploads%2FFg4uvOFTcj1wHm4Ngpae%2FScreenshot%202024-09-11%20at%2008.20.00.png?alt=media&#x26;token=b620adf0-fb72-44bb-8d1b-4d89cd60b4ec" alt=""><figcaption></figcaption></figure>

This SLI will output a stream of latencies like `{121,90,48,291,44,29,90,81...}`` ``seconds`
{% endtab %}

{% tab title="Average Latency" %}
**QUERY**

**A: SELECT** {`AVG`} {`latency_metric`} **FROM** {`key`} **WHERE** {`status_code < 500`}

Unit `ms`

Example Implementation 👇

<figure><img src="https://711169838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXD619BqgHmtAt8T9VUqw%2Fuploads%2F7vPEvOFmrmyyFzMTIwS7%2FScreenshot%202024-09-11%20at%2008.19.18.png?alt=media&#x26;token=8109c1ae-b2d8-4c59-81f7-5b4a4dddcb4c" alt=""><figcaption></figcaption></figure>

This SLI will output a the average latency of all the latencies sent within a period. For example, if the latencies sent were `{121,90,48,291,44,29,90,81} seconds`, the output of which would be 99.25 seconds.
{% endtab %}

{% tab title="Data Freshness" %}
**QUERY**

**A: SELECT** {`n/a`} {`external_timestamp_metric`} **FROM** {`key1`}&#x20;

**B: SELECT** {`n/a`} {`internal_timestamp_metric`} **FROM** {`key2`}&#x20;

Unit `epochs`

Formula: `A - B`

Example implementation 👇

<figure><img src="https://711169838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXD619BqgHmtAt8T9VUqw%2Fuploads%2FVyq1TRjWywdE0Nm8n36L%2FScreenshot%202024-09-11%20at%2008.21.30.png?alt=media&#x26;token=196ae587-e325-4fd3-824b-ae3bb8a8b17a" alt=""><figcaption></figcaption></figure>

This SLI will output a stream of integers like `{2,5,1,1,2,1,1,3,...} epochs`.
{% endtab %}

{% tab title="Average Data Freshness" %}
**QUERY**

**A: SELECT** {`AVG`} {`external_timestamp_metric`} **FROM** {`key1`}&#x20;

**B: SELECT** {`AVG`} {`internal_timestamp_metric`} **FROM** {`key2`}&#x20;

Formula: `A - B`

Unit `epochs`

Example implementation 👇

<figure><img src="https://711169838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXD619BqgHmtAt8T9VUqw%2Fuploads%2FUyl6BDnjZEIvLDln5rV6%2FScreenshot%202024-09-11%20at%2008.24.47.png?alt=media&#x26;token=84eae5f2-0f5d-4eae-8090-ca6837d998fa" alt=""><figcaption></figcaption></figure>

This SLI will output the average data freshness within a period. For example, if the `external_timestamp` averages to `1.2 epochs` and the `internal_timestamp` averages out to `1 epoch`, the SLI will output `0.2 epochs`.
{% endtab %}
{% endtabs %}

## Create a Percentage SLI

Follow these steps to create a Percentage Service Level Indicator (SLI):

1. Find and click on "Indicators" in the side navigation bar
2. Click the "+ New SLI" button to open the Create SLI modal
3. Choose "Percentage" as the type of SLI you'll be building
4. **Choose a metric query, aggregator, and filter**
   1. <mark style="color:orange;">**Allowed aggregators**</mark>**:** `COUNT`, `SUM`, `MAX`, `MIN`, `AVG`

      `n/a` is also an acceptable input; this will output an array of metrics without any aggregation
   2. <mark style="color:orange;">**You can create multiple queries**</mark> by clicking "+ New Query" and add a formula in the formula box to define the relationship between them
   3. <mark style="color:orange;">**Operators allowed on the formula builder**</mark>: `*` , `/`, `+`, `-` , `<` , `>` , `<=` , `>=,` `=` , `!=`
5. Provide a clear, descriptive name for your SLI and a description to explain its purpose and function
6. Click the "Save" button to create your new Percentage SLI

### Examples

{% tabs %}
{% tab title="Defining Uptime on slaOS" %}
**QUERY**

**A: SELECT** {`count`} {`*`} **FROM** {`key1`}  **WHERE** {`status_code < 500`}

**B: SELECT** {`count`} {`*`} **FROM** {`key2`}&#x20;

Formula : `A/B`

Example implementation 👇

<figure><img src="https://711169838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXD619BqgHmtAt8T9VUqw%2Fuploads%2Fum3Iw8vrntKp7PlwhQfw%2FScreenshot%202024-09-11%20at%2008.28.14.png?alt=media&#x26;token=e6e02797-b259-4c40-8ba1-afb21f32c106" alt=""><figcaption></figcaption></figure>

The SLI will output a ratio, where the numerator counts all the events where the status code is less than 500 and the denominator is all events.&#x20;
{% endtab %}

{% tab title="Pre-aggregated Uptime" %}
**QUERY**

**A: SELECT** {`n/a`} {`uptime_metric`} **FROM** {`key`} &#x20;

Example implementation 👇

<figure><img src="https://711169838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXD619BqgHmtAt8T9VUqw%2Fuploads%2FLGGKpIJDavCgX4i7gdUG%2FScreenshot%202024-09-11%20at%2011.03.03.png?alt=media&#x26;token=e44cb9f5-12bc-4541-91f9-1ee28aae8402" alt=""><figcaption></figcaption></figure>

The SLI will output the average of the uptime metric over a time period. For example, if the uptime metric is passed hourly to slaOS as `{0.9998, 0.9992, 0.9892, 0.4819, 0.9999, 0.9759}`, the SLI output will be `0.90765` or `90.965%`
{% endtab %}

{% tab title="Error Rate" %}
**QUERY**

**A: SELECT** {`count`} {`*`} **FROM** {`key1`}  **WHERE** {`status_code >= 500`}

**B: SELECT** {`count`} {`*`} **FROM** {`key2`}&#x20;

Formula : `A/B`

Example implementation 👇

<figure><img src="https://711169838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXD619BqgHmtAt8T9VUqw%2Fuploads%2Fdr5SETdyJuJ0c9xclXSB%2FScreenshot%202024-09-11%20at%2008.30.35.png?alt=media&#x26;token=e63423d0-c019-42f5-ab0e-2cbb4aff62f1" alt=""><figcaption></figcaption></figure>

The SLI will output a ratio, where the numerator counts all the events where the status code is more than 500 and the denominator is all events.&#x20;
{% endtab %}
{% endtabs %}

<br>
