|
1 | 1 | use apollo_metrics::metric_definitions::METRIC_LABEL_FILTER; |
2 | 2 |
|
3 | | -use crate::dashboard::{Panel, PanelType, Row}; |
| 3 | +use crate::dashboard::{Panel, PanelType, Row, Unit}; |
| 4 | +use crate::infra_panels::POD_LEGEND; |
4 | 5 |
|
5 | | -fn get_pod_memory_utilization_panel() -> Panel { |
| 6 | +// TODO(Tsabary): add thresholds. |
| 7 | +// TODO(Tsabary): replace query building with relevant functions and templates. |
| 8 | + |
| 9 | +pub(crate) fn get_pod_metrics_row() -> Row { |
| 10 | + Row::new( |
| 11 | + "Pod Metrics", |
| 12 | + vec![ |
| 13 | + get_pod_cpu_request_utilization_panel(), |
| 14 | + get_pod_cpu_throttling_panel(), |
| 15 | + get_pod_memory_request_utilization_panel(), |
| 16 | + get_pod_memory_limit_utilization_panel(), |
| 17 | + get_pod_disk_utilization_panel(), |
| 18 | + get_pod_disk_limit_utilization_panel(), |
| 19 | + ], |
| 20 | + ) |
| 21 | +} |
| 22 | + |
| 23 | +const POD_METRICS_DEFAULT_DURATION: &str = "5m"; |
| 24 | + |
| 25 | +// ---------------------------- CPU ---------------------------- |
| 26 | + |
| 27 | +// Pod CPU utilization as a ratio of: |
| 28 | +// total CPU usage rate of containers in the pod (in cores) |
| 29 | +// -------------------------------------------------------- |
| 30 | +// total CPU cores requested by containers in the pod |
| 31 | +// Aggregated per (namespace, pod), the result is a value between 0.0 and 1.0 per pod. |
| 32 | +// Interpreted as: "How much of its requested CPU is this pod actually using?" |
| 33 | +fn get_pod_cpu_request_utilization_panel() -> Panel { |
6 | 34 | Panel::new( |
7 | | - "pod_memory_utilization", |
8 | | - "Pod Memory Utilization", |
9 | | - format!("container_memory_working_set_bytes{METRIC_LABEL_FILTER}"), |
| 35 | + "Pod CPU Request Utilization", |
| 36 | + format!("Pod CPU utilization (usage / requests) ({POD_METRICS_DEFAULT_DURATION} window)"), |
| 37 | + format!( |
| 38 | + " |
| 39 | + ( |
| 40 | + sum by (namespace, pod) ( |
| 41 | + rate(container_cpu_usage_seconds_total{METRIC_LABEL_FILTER}[{POD_METRICS_DEFAULT_DURATION}]) |
| 42 | + ) |
| 43 | + ) |
| 44 | + / |
| 45 | + ( |
| 46 | + sum by (namespace, pod) ( |
| 47 | + kube_pod_container_resource_requests_cpu_cores{METRIC_LABEL_FILTER} |
| 48 | + ) |
| 49 | + ) |
| 50 | + " |
| 51 | + ), |
10 | 52 | PanelType::TimeSeries, |
11 | 53 | ) |
| 54 | + .with_legends(POD_LEGEND) |
| 55 | + .with_unit(Unit::PercentUnit) |
12 | 56 | } |
13 | 57 |
|
14 | | -fn get_pod_disk_utilization_panel() -> Panel { |
| 58 | +// Pod CPU throttling as a ratio of: |
| 59 | +// number of CFS CPU periods where containers in the pod were throttled |
| 60 | +// -------------------------------------------------------------------- |
| 61 | +// total number of CFS CPU periods for containers in the pod |
| 62 | +// Aggregated per (namespace, pod), the result is a value between 0.0 and 1.0 per pod. |
| 63 | +// Interpreted as: "What fraction of time is this pod being CPU-throttled by its CPU *limit*?" |
| 64 | +fn get_pod_cpu_throttling_panel() -> Panel { |
15 | 65 | Panel::new( |
16 | | - "pod_disk_utilization", |
17 | | - "Pod Disk Utilization", |
18 | | - format!("kubelet_volume_stats_used_bytes{METRIC_LABEL_FILTER}"), |
| 66 | + "Pod CPU throttling", |
| 67 | + format!("Pod CPU throttling (throttled / total periods) ({POD_METRICS_DEFAULT_DURATION} window)"), |
| 68 | + format!( |
| 69 | + "( |
| 70 | + sum by (namespace, pod) ( |
| 71 | + rate(container_cpu_cfs_throttled_periods_total{METRIC_LABEL_FILTER}[{POD_METRICS_DEFAULT_DURATION}]) |
| 72 | + ) |
| 73 | + ) |
| 74 | + / |
| 75 | + ( |
| 76 | + sum by (namespace, pod) ( |
| 77 | + rate(container_cpu_cfs_periods_total{METRIC_LABEL_FILTER}[{POD_METRICS_DEFAULT_DURATION}]) |
| 78 | + ) |
| 79 | + ) |
| 80 | + " |
| 81 | + ), |
19 | 82 | PanelType::TimeSeries, |
20 | 83 | ) |
| 84 | + .with_legends(POD_LEGEND) |
| 85 | + .with_unit(Unit::PercentUnit) |
21 | 86 | } |
22 | 87 |
|
23 | | -fn get_pod_cpu_utilization_panel() -> Panel { |
| 88 | +// ---------------------------- MEMORY ---------------------------- |
| 89 | + |
| 90 | +// Pod memory utilization as a ratio of: |
| 91 | +// total memory used by containers in the pod |
| 92 | +// ------------------------------------------------ |
| 93 | +// total memory requested by containers in the pod |
| 94 | +// Aggregated per (namespace, pod), the result is a value between 0.0 and 1.0 per pod. |
| 95 | +// Interpreted as: "How much of its requested memory is this pod actually using?" |
| 96 | +fn get_pod_memory_request_utilization_panel() -> Panel { |
24 | 97 | Panel::new( |
25 | | - "pod_cpu_utilization", |
26 | | - "Pod CPU Utilization", |
27 | | - format!("container_cpu_usage_seconds_total{METRIC_LABEL_FILTER}"), |
| 98 | + "Pod Memory Request Utilization", |
| 99 | + "Pod memory utilization (used / requests)", |
| 100 | + format!( |
| 101 | + " |
| 102 | + ( |
| 103 | + sum by (namespace, pod) ( |
| 104 | + container_memory_working_set_bytes{METRIC_LABEL_FILTER} |
| 105 | + ) |
| 106 | + ) |
| 107 | + / |
| 108 | + ( |
| 109 | + sum by (namespace, pod) ( |
| 110 | + kube_pod_container_resource_requests_memory_bytes{METRIC_LABEL_FILTER} |
| 111 | + ) |
| 112 | + ) |
| 113 | + " |
| 114 | + ), |
28 | 115 | PanelType::TimeSeries, |
29 | 116 | ) |
| 117 | + .with_legends(POD_LEGEND) |
| 118 | + .with_unit(Unit::PercentUnit) |
30 | 119 | } |
31 | 120 |
|
32 | | -pub(crate) fn get_pod_metrics_row() -> Row { |
33 | | - Row::new( |
34 | | - "Pod Metrics", |
35 | | - vec![ |
36 | | - get_pod_memory_utilization_panel(), |
37 | | - get_pod_disk_utilization_panel(), |
38 | | - get_pod_cpu_utilization_panel(), |
39 | | - ], |
| 121 | +// Pod memory limit utilization as a ratio of: |
| 122 | +// total memory used by containers in the pod |
| 123 | +// ------------------------------------------ |
| 124 | +// total memory limit of containers in the pod |
| 125 | +// Aggregated per (namespace, pod), the result is a value between 0.0 and 1.0 per pod. |
| 126 | +// Interpreted as: "How close is this pod to its memory *limit* (OOM-kill threshold)?" |
| 127 | +// Note: memory is not throttled like CPU; crossing this limit results in OOM kills. |
| 128 | +fn get_pod_memory_limit_utilization_panel() -> Panel { |
| 129 | + Panel::new( |
| 130 | + "Pod Memory Limit Utilization", |
| 131 | + "Pod memory limit utilization (used / limits)", |
| 132 | + format!( |
| 133 | + " |
| 134 | + ( |
| 135 | + sum by (namespace, pod) ( |
| 136 | + container_memory_working_set_bytes{METRIC_LABEL_FILTER} |
| 137 | + ) |
| 138 | + ) |
| 139 | + / |
| 140 | + ( |
| 141 | + sum by (namespace, pod) ( |
| 142 | + container_spec_memory_limit_bytes{METRIC_LABEL_FILTER} |
| 143 | + ) |
| 144 | + ) |
| 145 | + " |
| 146 | + ), |
| 147 | + PanelType::TimeSeries, |
| 148 | + ) |
| 149 | + .with_legends(POD_LEGEND) |
| 150 | + .with_unit(Unit::PercentUnit) |
| 151 | +} |
| 152 | + |
| 153 | +// ---------------------------- DISK ---------------------------- |
| 154 | + |
| 155 | +// Pod disk utilization (PVC) as a ratio of: |
| 156 | +// total volume bytes used by the pod |
| 157 | +// ---------------------------------- |
| 158 | +// total volume capacity bytes of the pod |
| 159 | +// Aggregated per (namespace, pod), the result is a value between 0.0 and 1.0 per pod. |
| 160 | +// Interpreted as: "How much of the provisioned PVC capacity is this pod using?" |
| 161 | +fn get_pod_disk_utilization_panel() -> Panel { |
| 162 | + Panel::new( |
| 163 | + "Pod Disk Utilization", |
| 164 | + "Pod disk utilization (used / capacity)", |
| 165 | + format!( |
| 166 | + " |
| 167 | + ( |
| 168 | + sum by (namespace, pod) ( |
| 169 | + kubelet_volume_stats_used_bytes{METRIC_LABEL_FILTER} |
| 170 | + ) |
| 171 | + ) |
| 172 | + / |
| 173 | + ( |
| 174 | + sum by (namespace, pod) ( |
| 175 | + kubelet_volume_stats_capacity_bytes{METRIC_LABEL_FILTER} |
| 176 | + ) |
| 177 | + ) |
| 178 | + " |
| 179 | + ), |
| 180 | + PanelType::TimeSeries, |
| 181 | + ) |
| 182 | + .with_legends(POD_LEGEND) |
| 183 | + .with_unit(Unit::PercentUnit) |
| 184 | +} |
| 185 | + |
| 186 | +// Pod disk limit utilization (PVC) as a ratio of: |
| 187 | +// total volume bytes used by the pod |
| 188 | +// ---------------------------------- |
| 189 | +// total volume capacity bytes of the pod (effective disk limit) |
| 190 | +// Aggregated per (namespace, pod), the result is a value between 0.0 and 1.0 per pod. |
| 191 | +// Interpreted as: "How close is this pod's PVC storage to being full (disk *limit* saturation)?" |
| 192 | +fn get_pod_disk_limit_utilization_panel() -> Panel { |
| 193 | + Panel::new( |
| 194 | + "Pod Disk Limit Utilization", |
| 195 | + "Pod disk limit utilization (used / capacity)", |
| 196 | + format!( |
| 197 | + " |
| 198 | + ( |
| 199 | + sum by (namespace, pod) ( |
| 200 | + kubelet_volume_stats_used_bytes{METRIC_LABEL_FILTER} |
| 201 | + ) |
| 202 | + ) |
| 203 | + / |
| 204 | + ( |
| 205 | + sum by (namespace, pod) ( |
| 206 | + kubelet_volume_stats_capacity_bytes{METRIC_LABEL_FILTER} |
| 207 | + ) |
| 208 | + ) |
| 209 | + " |
| 210 | + ), |
| 211 | + PanelType::TimeSeries, |
40 | 212 | ) |
| 213 | + .with_legends(POD_LEGEND) |
| 214 | + .with_unit(Unit::PercentUnit) |
41 | 215 | } |
0 commit comments