# Source: bosh-exporter
---
- type: replace
  path: /instance_groups/name=prometheus2/jobs/name=prometheus2/properties/prometheus/custom_rules?/-
  value:
    name: BoshDiegoCellAvailableMemory
    rules:
      - record: bosh_job:mem_percent:diego_cell:avg5m
        expr: 100 - avg_over_time(bosh_job_mem_percent{environment="((metrics_environment))",bosh_job_name="diego-cell"}[5m])
      - &alert
        alert: BoshDiegoCellAvailableMemory_Warning
        expr: bosh_job:mem_percent:diego_cell:avg5m < 55
        for: 2h
        labels:
          severity: warning
          notify: email
        annotations:
          summary: Low memory free on {{ $labels.bosh_job_name }}.
          description: >
            {{ $labels.bosh_job_name }}/{{ $labels.bosh_job_id }}
            memory free was low {{ $value | printf "%.0f" }}%
            in the last two hours on average.
            Review if we need to scale...
          url: https://team-manual.cloud.service.gov.uk/architecture_decision_records/ADR021-cell-capacity-assignment-2/#decision

      - <<: *alert
        alert: BoshDiegoCellAvailableMemory_Critical
        expr: bosh_job:mem_percent:diego_cell:avg5m < 50
        labels:
          severity: critical
          notify: email

Migrate alert "cell available memory" to Prometheus
Migrate alert "cell available memory" to Prometheus

Original datadog monitor:

avg(last_2h):avg:system.mem.pct_usable{bosh-job:diego-cell}

from terraform/datadog/cell.tf cell-available-memory
