diff --git a/rules/apps.libsonnet b/rules/apps.libsonnet index 82bf17463..0cf255aa6 100644 --- a/rules/apps.libsonnet +++ b/rules/apps.libsonnet @@ -83,6 +83,29 @@ { name: 'k8s.rules.container_memory_requests', rules: [ + { + record: 'cluster:namespace:pod_memory:active:kube_pod_container_resource_requests', + expr: ||| + kube_pod_container_resource_requests{resource="memory",%(kubeStateMetricsSelector)s} * on (namespace, pod, %(clusterLabel)s) + group_left() max by (namespace, pod, %(clusterLabel)s) ( + (kube_pod_status_phase{phase=~"Pending|Running"} == 1) + ) + ||| % $._config, + }, + { + record: 'namespace_memory:kube_pod_container_resource_requests:sum', + expr: ||| + sum by (namespace, %(clusterLabel)s) ( + sum by (namespace, pod, %(clusterLabel)s) ( + max by (namespace, pod, container, %(clusterLabel)s) ( + kube_pod_container_resource_requests{resource="memory",%(kubeStateMetricsSelector)s} + ) * on(namespace, pod, %(clusterLabel)s) group_left() max by (namespace, pod, %(clusterLabel)s) ( + kube_pod_status_phase{phase=~"Pending|Running"} == 1 + ) + ) + ) + ||| % $._config, + }, { record: 'cluster:namespace:pod_memory:active:kube_pod_resource_request_or_kube_pod_container_resource_requests', expr: ||| @@ -106,6 +129,29 @@ { name: 'k8s.rules.container_cpu_requests', rules: [ + { + record: 'cluster:namespace:pod_cpu:active:kube_pod_container_resource_requests', + expr: ||| + kube_pod_container_resource_requests{resource="cpu",%(kubeStateMetricsSelector)s} * on (namespace, pod, %(clusterLabel)s) + group_left() max by (namespace, pod, %(clusterLabel)s) ( + (kube_pod_status_phase{phase=~"Pending|Running"} == 1) + ) + ||| % $._config, + }, + { + record: 'namespace_cpu:kube_pod_container_resource_requests:sum', + expr: ||| + sum by (namespace, %(clusterLabel)s) ( + sum by (namespace, pod, %(clusterLabel)s) ( + max by (namespace, pod, container, %(clusterLabel)s) ( + kube_pod_container_resource_requests{resource="cpu",%(kubeStateMetricsSelector)s} + ) * on(namespace, pod, %(clusterLabel)s) group_left() max by (namespace, pod, %(clusterLabel)s) ( + kube_pod_status_phase{phase=~"Pending|Running"} == 1 + ) + ) + ) + ||| % $._config, + }, { record: 'cluster:namespace:pod_cpu:active:kube_pod_resource_request_or_kube_pod_container_resource_requests', expr: ||| @@ -129,6 +175,29 @@ { name: 'k8s.rules.container_memory_limits', rules: [ + { + record: 'cluster:namespace:pod_memory:active:kube_pod_container_resource_limits', + expr: ||| + kube_pod_container_resource_limits{resource="memory",%(kubeStateMetricsSelector)s} * on (namespace, pod, %(clusterLabel)s) + group_left() max by (namespace, pod, %(clusterLabel)s) ( + (kube_pod_status_phase{phase=~"Pending|Running"} == 1) + ) + ||| % $._config, + }, + { + record: 'namespace_memory:kube_pod_container_resource_limits:sum', + expr: ||| + sum by (namespace, %(clusterLabel)s) ( + sum by (namespace, pod, %(clusterLabel)s) ( + max by (namespace, pod, container, %(clusterLabel)s) ( + kube_pod_container_resource_limits{resource="memory",%(kubeStateMetricsSelector)s} + ) * on(namespace, pod, %(clusterLabel)s) group_left() max by (namespace, pod, %(clusterLabel)s) ( + kube_pod_status_phase{phase=~"Pending|Running"} == 1 + ) + ) + ) + ||| % $._config, + }, { record: 'cluster:namespace:pod_memory:active:kube_pod_resource_limit_or_kube_pod_container_resource_limits', expr: ||| @@ -152,6 +221,29 @@ { name: 'k8s.rules.container_cpu_limits', rules: [ + { + record: 'cluster:namespace:pod_cpu:active:kube_pod_container_resource_limits', + expr: ||| + kube_pod_container_resource_limits{resource="cpu",%(kubeStateMetricsSelector)s} * on (namespace, pod, %(clusterLabel)s) + group_left() max by (namespace, pod, %(clusterLabel)s) ( + (kube_pod_status_phase{phase=~"Pending|Running"} == 1) + ) + ||| % $._config, + }, + { + record: 'namespace_cpu:kube_pod_container_resource_limits:sum', + expr: ||| + sum by (namespace, %(clusterLabel)s) ( + sum by (namespace, pod, %(clusterLabel)s) ( + max by (namespace, pod, container, %(clusterLabel)s) ( + kube_pod_container_resource_limits{resource="cpu",%(kubeStateMetricsSelector)s} + ) * on(namespace, pod, %(clusterLabel)s) group_left() max by (namespace, pod, %(clusterLabel)s) ( + kube_pod_status_phase{phase=~"Pending|Running"} == 1 + ) + ) + ) + ||| % $._config, + }, { record: 'cluster:namespace:pod_cpu:active:kube_pod_resource_limit_or_kube_pod_container_resource_limits', expr: |||