Raw SLI

# This example shows another less accurate or simpler way of creating the home wifi SLO.
#
# The metrics already give us a metric in ratio for each wifi connection satisfaction, instead of getting
# good and bad events as connection with a minimum satisfaction ratio, we will calculate the averate of all
# ratio satisfaction connections over the time window.
# So we can't use the `events` SLI because we are not going to divide bad and total events.
#
# - `wifi-client-satisfaction`
#   - This SLO warn us that we have an average wifi connection satisfaction.
#   - SLI error: Calculated internally by ubiquitis metrics, we use directly the ratio.
#   - SLO objective (95%): We allow the average wifi connection satisfaction is >=95%
#
# `sloth generate -i ./examples/raw-home-wifi.yml`
#
version: "prometheus/v1"
service: "home-wifi"
labels:
  cluster: "valhalla"
  component: "ubiquiti"
  context: "home"
slos:
  - name: "wifi-client-satisfaction"
    objective: 95
    description: "Warn us that we have an average wifi connection satisfaction."
    sli:
      raw:
        # Get the averate satisfaction ratio and rest 1 (max good) to get the error ratio.
        error_ratio_query: |
          1 - (
            sum(sum_over_time(unifipoller_client_satisfaction_ratio[{{.window}}]))
            /
            sum(count_over_time(unifipoller_client_satisfaction_ratio[{{.window}}]))
          )
    alerting:
      name: WifiClientSatisfaction
      page_alert:
        labels:
          severity: home
      ticket_alert:
        labels:
          severity: warning
---
# Code generated by Sloth (dev): https://github.com/slok/sloth.
# DO NOT EDIT.

groups:
- name: sloth-slo-sli-recordings-home-wifi-wifi-client-satisfaction
  rules:
  - record: slo:sli_error:ratio_rate5m
    expr: |-
      (1 - (
        sum(sum_over_time(unifipoller_client_satisfaction_ratio[5m]))
        /
        sum(count_over_time(unifipoller_client_satisfaction_ratio[5m]))
      )
      )
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
      sloth_window: 5m
  - record: slo:sli_error:ratio_rate30m
    expr: |-
      (1 - (
        sum(sum_over_time(unifipoller_client_satisfaction_ratio[30m]))
        /
        sum(count_over_time(unifipoller_client_satisfaction_ratio[30m]))
      )
      )
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
      sloth_window: 30m
  - record: slo:sli_error:ratio_rate1h
    expr: |-
      (1 - (
        sum(sum_over_time(unifipoller_client_satisfaction_ratio[1h]))
        /
        sum(count_over_time(unifipoller_client_satisfaction_ratio[1h]))
      )
      )
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
      sloth_window: 1h
  - record: slo:sli_error:ratio_rate2h
    expr: |-
      (1 - (
        sum(sum_over_time(unifipoller_client_satisfaction_ratio[2h]))
        /
        sum(count_over_time(unifipoller_client_satisfaction_ratio[2h]))
      )
      )
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
      sloth_window: 2h
  - record: slo:sli_error:ratio_rate6h
    expr: |-
      (1 - (
        sum(sum_over_time(unifipoller_client_satisfaction_ratio[6h]))
        /
        sum(count_over_time(unifipoller_client_satisfaction_ratio[6h]))
      )
      )
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
      sloth_window: 6h
  - record: slo:sli_error:ratio_rate1d
    expr: |-
      (1 - (
        sum(sum_over_time(unifipoller_client_satisfaction_ratio[1d]))
        /
        sum(count_over_time(unifipoller_client_satisfaction_ratio[1d]))
      )
      )
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
      sloth_window: 1d
  - record: slo:sli_error:ratio_rate3d
    expr: |-
      (1 - (
        sum(sum_over_time(unifipoller_client_satisfaction_ratio[3d]))
        /
        sum(count_over_time(unifipoller_client_satisfaction_ratio[3d]))
      )
      )
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
      sloth_window: 3d
  - record: slo:sli_error:ratio_rate30d
    expr: |
      sum_over_time(slo:sli_error:ratio_rate5m{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"}[30d])
      / ignoring (sloth_window)
      count_over_time(slo:sli_error:ratio_rate5m{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"}[30d])
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
      sloth_window: 30d
- name: sloth-slo-meta-recordings-home-wifi-wifi-client-satisfaction
  rules:
  - record: slo:objective:ratio
    expr: vector(0.95)
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
  - record: slo:error_budget:ratio
    expr: vector(1-0.95)
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
  - record: slo:time_period:days
    expr: vector(30)
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
  - record: slo:current_burn_rate:ratio
    expr: |
      slo:sli_error:ratio_rate5m{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"}
      / on(sloth_id, sloth_slo, sloth_service) group_left
      slo:error_budget:ratio{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"}
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
  - record: slo:period_burn_rate:ratio
    expr: |
      slo:sli_error:ratio_rate30d{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"}
      / on(sloth_id, sloth_slo, sloth_service) group_left
      slo:error_budget:ratio{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"}
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
  - record: slo:period_error_budget_remaining:ratio
    expr: 1 - slo:period_burn_rate:ratio{sloth_id="home-wifi-wifi-client-satisfaction",
      sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"}
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
  - record: sloth_slo_info
    expr: vector(1)
    labels:
      cluster: valhalla
      cmd: examplesgen.sh
      component: ubiquiti
      context: home
      sloth_id: home-wifi-wifi-client-satisfaction
      sloth_mode: cli-gen-prom
      sloth_objective: "95"
      sloth_service: home-wifi
      sloth_slo: wifi-client-satisfaction
      sloth_spec: prometheus/v1
      sloth_version: dev
- name: sloth-slo-alerts-home-wifi-wifi-client-satisfaction
  rules:
  - alert: WifiClientSatisfaction
    expr: |
      (
          max(slo:sli_error:ratio_rate5m{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"} > (14.4 * 0.05)) without (sloth_window)
          and
          max(slo:sli_error:ratio_rate1h{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"} > (14.4 * 0.05)) without (sloth_window)
      )
      or
      (
          max(slo:sli_error:ratio_rate30m{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"} > (6 * 0.05)) without (sloth_window)
          and
          max(slo:sli_error:ratio_rate6h{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"} > (6 * 0.05)) without (sloth_window)
      )
    labels:
      severity: home
      sloth_severity: page
    annotations:
      summary: '{{$labels.sloth_service}} {{$labels.sloth_slo}} SLO error budget burn
        rate is over expected.'
      title: (page) {{$labels.sloth_service}} {{$labels.sloth_slo}} SLO error budget
        burn rate is too fast.
  - alert: WifiClientSatisfaction
    expr: |
      (
          max(slo:sli_error:ratio_rate2h{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"} > (3 * 0.05)) without (sloth_window)
          and
          max(slo:sli_error:ratio_rate1d{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"} > (3 * 0.05)) without (sloth_window)
      )
      or
      (
          max(slo:sli_error:ratio_rate6h{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"} > (1 * 0.05)) without (sloth_window)
          and
          max(slo:sli_error:ratio_rate3d{sloth_id="home-wifi-wifi-client-satisfaction", sloth_service="home-wifi", sloth_slo="wifi-client-satisfaction"} > (1 * 0.05)) without (sloth_window)
      )
    labels:
      severity: warning
      sloth_severity: ticket
    annotations:
      summary: '{{$labels.sloth_service}} {{$labels.sloth_slo}} SLO error budget burn
        rate is over expected.'
      title: (ticket) {{$labels.sloth_service}} {{$labels.sloth_slo}} SLO error budget
        burn rate is too fast.