Unverified Commit f371be5f authored by Frederic Branczyk's avatar Frederic Branczyk Committed by GitHub

Merge pull request #1260 from prometheus/update-recording-rules

Update recording rules best practices to 2.x format
parents 0c3f7457 c1049a73
...@@ -50,66 +50,81 @@ conflicts and give you more useful metrics and alerts. ...@@ -50,66 +50,81 @@ conflicts and give you more useful metrics and alerts.
Aggregating up requests per second that has a `path` label: Aggregating up requests per second that has a `path` label:
``` ```
instance_path:requests:rate5m = - record: instance_path:requests:rate5m
rate(requests_total{job="myjob"}[5m]) expr: rate(requests_total{job="myjob"}[5m])
path:requests:rate5m = - record: path:requests:rate5m
sum without (instance)(instance_path:requests:rate5m{job="myjob"}) expr: sum without (instance)(instance_path:requests:rate5m{job="myjob"})
``` ```
Calculating a request failure ratio and aggregating up to the job-level failure ratio: Calculating a request failure ratio and aggregating up to the job-level failure ratio:
``` ```
instance_path:request_failures:rate5m = - record: instance_path:request_failures:rate5m
rate(request_failures_total{job="myjob"}[5m]) expr: rate(request_failures_total{job="myjob"}[5m])
instance_path:request_failures_per_requests:ratio_rate5m = - record: instance_path:request_failures_per_requests:ratio_rate5m
instance_path:request_failures:rate5m{job="myjob"} expr: |
/ (
instance_path:requests:rate5m{job="myjob"} instance_path:request_failures:rate5m{job="myjob"}
/
// Aggregate up numerator and denominator, then divide to get path-level ratio. instance_path:requests:rate5m{job="myjob"}
path:request_failures_per_requests:ratio_rate5m = )
sum without (instance)(instance_path:request_failures:rate5m{job="myjob"})
/ # Aggregate up numerator and denominator, then divide to get path-level ratio.
sum without (instance)(instance_path:requests:rate5m{job="myjob"}) - record: path:request_failures_per_requests:ratio_rate5m
expr: |
// No labels left from instrumentation or distinguishing instances, (
// so we use 'job' as the level. sum without (instance)(instance_path:request_failures:rate5m{job="myjob"})
job:request_failures_per_requests:ratio_rate5m = /
sum without (instance, path)(instance_path:request_failures:rate5m{job="myjob"}) sum without (instance)(instance_path:requests:rate5m{job="myjob"})
/ )
sum without (instance, path)(instance_path:requests:rate5m{job="myjob"})
# No labels left from instrumentation or distinguishing instances,
# so we use 'job' as the level.
- record: job:request_failures_per_requests:ratio_rate5m
expr: |
(
sum without (instance, path)(instance_path:request_failures:rate5m{job="myjob"})
/
sum without (instance, path)(instance_path:requests:rate5m{job="myjob"})
)
``` ```
Calculating average latency over a time period from a Summary: Calculating average latency over a time period from a Summary:
``` ```
instance_path:request_latency_seconds_count:rate5m = - record: instance_path:request_latency_seconds_count:rate5m
rate(request_latency_seconds_count{job="myjob"}[5m]) expr: rate(request_latency_seconds_count{job="myjob"}[5m])
instance_path:request_latency_seconds_sum:rate5m = - record: instance_path:request_latency_seconds_sum:rate5m
rate(request_latency_seconds_sum{job="myjob"}[5m]) expr: rate(request_latency_seconds_sum{job="myjob"}[5m])
instance_path:request_latency_seconds:mean5m = - record: instance_path:request_latency_seconds:mean5m
instance_path:request_latency_seconds_sum:rate5m{job="myjob"} expr: |
/ (
instance_path:request_latency_seconds_count:rate5m{job="myjob"} instance_path:request_latency_seconds_sum:rate5m{job="myjob"}
/
// Aggregate up numerator and denominator, then divide. instance_path:request_latency_seconds_count:rate5m{job="myjob"}
path:request_latency_seconds:mean5m = )
sum without (instance)(instance_path:request_latency_seconds_sum:rate5m{job="myjob"})
/ # Aggregate up numerator and denominator, then divide.
sum without (instance)(instance_path:request_latency_seconds_count:rate5m{job="myjob"}) - record: path:request_latency_seconds:mean5m
expr: |
(
sum without (instance)(instance_path:request_latency_seconds_sum:rate5m{job="myjob"})
/
sum without (instance)(instance_path:request_latency_seconds_count:rate5m{job="myjob"})
)
``` ```
Calculating the average query rate across instances and paths is done using the Calculating the average query rate across instances and paths is done using the
`avg()` function: `avg()` function:
``` ```
job:request_latency_seconds_count:avg_rate5m = - record: job:request_latency_seconds_count:avg_rate5m
avg without (instance, path)(instance:request_latency_seconds_count:rate5m{job="myjob"}) expr: avg without (instance, path)(instance:request_latency_seconds_count:rate5m{job="myjob"})
``` ```
Notice that when aggregating that the labels in the `without` clause are removed Notice that when aggregating that the labels in the `without` clause are removed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment