# Prometheus metrics for resource optimization ## Reward | Description | Metric | Format | | - | - | - | Collect the CPU utilization of entire Kubernetes | `sum (rate (container_cpu_usage_seconds_total{id="/"}[2m])) / sum (machine_cpu_cores) * 100` | float literal | | Collect the Memory utilization of entire Kubernetes | `sum(container_memory_working_set_bytes{name!~"POD"})` | float literal | | Collect the total seconds of CPU throttled by Linux kernel in the entire Kubernetes | `sum(rate(container_cpu_cfs_throttled_seconds_total[2m])) ` | float literal | | Collect the cumulative received data traffic of the entire Kubernetes in the past 3 minutes | `sum(rate(container_network_receive_bytes_total{name!~"POD"}[2m]))` | float literal | | Collect the cumulative transmitted data traffic of the entire Kubernetes in the past 3 minutes | `sum(rate(container_network_transmit_bytes_total{name!~"POD"}[2m]))` | float literal | | Collect the cumulative number of Pod restarts in the entire Kubernetes | `sum(kube_pod_container_status_restarts_total)` | float literal | | Collect the cumulative number of filesystem write bytes in the entire Kubernetes | `sum(rate(container_fs_writes_bytes_total[2m]))` | float literal | | Collect the cumulative number of filesystem read bytes in the entire Kubernetes | `sum(rate(container_fs_reads_bytes_total[2m]))` | float literal | :::info ‍`container_cpu_cfs_throttled_seconds_total` This measures the total amount of time a certain container has been throttled. Generally, container CPU usage can be throttled to prevent a single busy container from essentially choking other containers by taking away all the available CPU resources. Throttling is usually a good way to ensure a minimum processing power is available for essential services on all running containers. This metric measures the total time that a container’s CPU usage was throttled, and observing this provides the information one needs to properly reallocate resources to specific containers. This can be done, for example, by adjusting the setting for cpu shares in Docker.‍ ::: ## Action 1. Specify CPU/Memory requests and limits via configuration file 2. Specify which node to put the pod via configuration file <!-- | Collect the memory bytes limited by Pods in the entire Kubernetes | `sum(kube_pod_container_resource_limits{resource="memory", unit="byte"})` | float literal | | Collect the CPU cores limited by Pods in the entire Kubernetes | `sum(kube_pod_container_resource_limits{resource="cpu",unit="core"})` | float literal | | Collect the CPU cores required and used by Pods in the entire Kubernetes | `sum(kube_pod_container_resource_requests{resource="cpu",unit="core"})` | float literal | | Collect the memory bytes required and used by Pods in the entire Kubernetes | `sum(kube_pod_container_resource_requests{resource="memory", unit="byte"})` | float literal | -->