Forked from devops-school/Example-prometheus-Recording-Rule.yaml
Created
September 28, 2021 13:11
-
-
Save derekjhyang/e0153317bc95e47c3e2071479c83a2b8 to your computer and use it in GitHub Desktop.
Example-prometheus Recording Rule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Recording Rule Example 1 | |
| ================================ | |
| # Aggregating up requests per second that has a path label: | |
| - record: instance_path:requests:rate5m | |
| expr: rate(requests_total{job="myjob"}[5m]) | |
| - record: path:requests:rate5m | |
| expr: sum without (instance)(instance_path:requests:rate5m{job="myjob"}) | |
| Recording Rule Example 2 | |
| ================================ | |
| # Calculating a request failure ratio and aggregating up to the job-level failure ratio: | |
| - record: instance_path:request_failures:rate5m | |
| expr: rate(request_failures_total{job="myjob"}[5m]) | |
| - record: instance_path:request_failures_per_requests:ratio_rate5m | |
| expr: |2 | |
| instance_path:request_failures:rate5m{job="myjob"} | |
| / | |
| instance_path:requests:rate5m{job="myjob"} | |
| # Aggregate up numerator and denominator, then divide to get path-level ratio. | |
| - record: path:request_failures_per_requests:ratio_rate5m | |
| expr: |2 | |
| sum without (instance)(instance_path:request_failures:rate5m{job="myjob"}) | |
| / | |
| sum without (instance)(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: |2 | |
| sum without (instance, path)(instance_path:request_failures:rate5m{job="myjob"}) | |
| / | |
| sum without (instance, path)(instance_path:requests:rate5m{job="myjob"}) | |
| Recording Rule Example 3 | |
| ================================ | |
| # Calculating average latency over a time period from a Summary: | |
| - record: instance_path:request_latency_seconds_count:rate5m | |
| expr: rate(request_latency_seconds_count{job="myjob"}[5m]) | |
| - record: instance_path:request_latency_seconds_sum:rate5m | |
| expr: rate(request_latency_seconds_sum{job="myjob"}[5m]) | |
| - record: instance_path:request_latency_seconds:mean5m | |
| expr: |2 | |
| instance_path:request_latency_seconds_sum:rate5m{job="myjob"} | |
| / | |
| instance_path:request_latency_seconds_count:rate5m{job="myjob"} | |
| # Aggregate up numerator and denominator, then divide. | |
| - record: path:request_latency_seconds:mean5m | |
| expr: |2 | |
| sum without (instance)(instance_path:request_latency_seconds_sum:rate5m{job="myjob"}) | |
| / | |
| sum without (instance)(instance_path:request_latency_seconds_count:rate5m{job="myjob"}) | |
| Recording Rule Example 5 | |
| ================================ | |
| # Calculating the average query rate across instances and paths is done using the avg() function: | |
| - record: job:request_latency_seconds_count:avg_rate5m | |
| expr: avg without (instance, path)(instance:request_latency_seconds_count:rate5m{job="myjob"}) | |
| Recording Rule Example 6 | |
| ================================ | |
| groups: | |
| - name: custom_rules | |
| rules: | |
| - record: node_memory_MemFree_percent | |
| expr: 100 - (100 * node_memory_MemFree_bytes / node_memory_MemTotal_bytes) | |
| - record: node_filesystem_free_percent | |
| expr: 100 * node_filesystem_free_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"} | |
| Recording Rule Example 7 | |
| ================================ | |
| groups: | |
| - name: recording_rules | |
| interval: 5s | |
| rules: | |
| - record: node_exporter:node_filesystem_free:fs_used_percents | |
| expr: 100 - 100 * ( node_filesystem_free{mountpoint="/"} / node_filesystem_size{mountpoint="/"} ) | |
| - record: node_exporter:node_memory_free:memory_used_percents | |
| expr: 100 - 100 * (node_memory_MemFree / node_memory_MemTotal) | |
| Recording Rule Example 8 | |
| ================================ | |
| groups: | |
| - name: custom_rules | |
| rules: | |
| - record: node_memory_MemFree_percent | |
| expr: 100 - (100 * node_memory_MemFree_bytes / node_memory_MemTotal_bytes) | |
| - record: node_filesystem_free_percent expr: 100 * node_filesystem_free_bytes{mountpoint="/"} / node_filesystem_size_bytes | |
| {mountpoint="/"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment