# This is a hack to expose a "cadvisor_container_restart_count" metric per container.
#
# For details on what is going on here, see https://gist.github.com/slimsag/85e06781eb0d4d35beee12916aefac5f
#
# This metric is only non-null in deployment types with cadvisor (Docker Compose, Pure Docker).
groups:
  - name: cadvisor-restart-count.rules
    rules:
      - record: cadvisor_container_restart_count
        expr: |-
          (
          (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^$"}) * 0)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~".*1$"}) * 1)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~".*2$"}) * 2)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~".*3$"}) * 3)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~".*4$"}) * 4)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~".*5$"}) * 5)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~".*6$"}) * 6)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~".*7$"}) * 7)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~".*8$"}) * 8)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~".*9$"}) * 9)
          )
          +
          (
          (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^.$"}) * 0)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^1.$"}) * 10)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^2.$"}) * 20)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^3.$"}) * 30)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^4.$"}) * 40)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^5.$"}) * 50)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^6.$"}) * 60)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^7.$"}) * 70)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^8.$"}) * 80)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^9.$"}) * 90)
          )
          +
          (
          (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^.$"}) * 0)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^..$"}) * 0)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^1..$"}) * 100)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^2..$"}) * 200)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^3..$"}) * 300)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^4..$"}) * 400)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^5..$"}) * 500)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^6..$"}) * 600)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^7..$"}) * 700)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^8..$"}) * 800)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^9..$"}) * 900)
          )
          +
          (
          (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^.$"}) * 0)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^..$"}) * 0)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^...$"}) * 0)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^1...$"}) * 1000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^2...$"}) * 2000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^3...$"}) * 3000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^4...$"}) * 4000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^5...$"}) * 5000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^6...$"}) * 6000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^7...$"}) * 7000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^8...$"}) * 8000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^9...$"}) * 9000)
          )
          +
          (
          (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^.$"}) * 0)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^..$"}) * 0)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^...$"}) * 0)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^....$"}) * 0)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^1....$"}) * 10000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^2....$"}) * 20000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^3....$"}) * 30000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^4....$"}) * 40000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^5....$"}) * 50000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^6....$"}) * 60000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^7....$"}) * 70000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^8....$"}) * 80000)
          or (count by (name)(container_spec_cpu_shares{container_label_restartcount=~"^9....$"}) * 90000)
          )
