Skip to content

Commit

Permalink
Merge pull request kruize#1249 from shekhar316/adding_namespace_queries
Browse files Browse the repository at this point in the history
Adding Queries For Namespace Recommendations
  • Loading branch information
dinogun authored Sep 12, 2024
2 parents 913fd10 + 1f7ba53 commit 6d10f29
Show file tree
Hide file tree
Showing 2 changed files with 358 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,199 @@
"query": "max by(namespace,container) (last_over_time((timestamp(container_cpu_usage_seconds_total{namespace=\"$NAMESPACE$\", container=\"$CONTAINER_NAME$\"} > 0))[15d:]))"
}
]
},
{
"name": "namespaceCpuRequest",
"datasource": "prometheus",
"value_type": "double",
"kubernetes_object": "namespace",
"aggregation_functions": [
{
"function": "sum",
"query": "sum by (namespace) (kube_resourcequota{namespace=\"$NAMESPACE$\", resource=\"requests.cpu\", type=\"hard\"})",
"version": ""
}
]
},
{
"name": "namespaceCpuLimit",
"datasource": "prometheus",
"value_type": "double",
"kubernetes_object": "namespace",
"aggregation_functions": [
{
"function": "sum",
"query": "sum by (namespace) (kube_resourcequota{namespace=\"$NAMESPACE$\", resource=\"limits.cpu\", type=\"hard\"})",
"version": ""
}
]
},
{
"name": "namespaceMemoryRequest",
"datasource": "prometheus",
"value_type": "double",
"kubernetes_object": "namespace",
"aggregation_functions": [
{
"function": "sum",
"query": "sum by (namespace) (kube_resourcequota{namespace=\"$NAMESPACE$\", resource=\"requests.memory\", type=\"hard\"})",
"version": ""
}
]
},
{
"name": "namespaceMemoryLimit",
"datasource": "prometheus",
"value_type": "double",
"kubernetes_object": "namespace",
"aggregation_functions": [
{
"function": "sum",
"query": "sum by (namespace) (kube_resourcequota{namespace=\"$NAMESPACE$\", resource=\"limits.memory\", type=\"hard\"})",
"version": ""
}
]
},
{
"name": "namespaceCpuUsage",
"datasource": "prometheus",
"value_type": "double",
"kubernetes_object": "namespace",
"aggregation_functions": [
{
"function": "avg",
"query": "avg_over_time(sum by(namespace) (node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
},
{
"function": "max",
"query": "max_over_time(sum by(namespace) (node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
},
{
"function": "min",
"query": "min_over_time(sum by(namespace) (node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
}
]
},
{
"name": "namespaceCpuThrottle",
"datasource": "prometheus",
"value_type": "double",
"kubernetes_object": "namespace",
"aggregation_functions": [
{
"function": "avg",
"query": "avg_over_time(sum by(namespace) (rate(container_cpu_cfs_throttled_seconds_total{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''}[5m]))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
},
{
"function": "max",
"query": "max_over_time(sum by(namespace) (rate(container_cpu_cfs_throttled_seconds_total{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''}[5m]))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
},
{
"function": "min",
"query": "min_over_time(sum by(namespace) (rate(container_cpu_cfs_throttled_seconds_total{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''}[5m]))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
}
]
},
{
"name": "namespaceMemoryUsage",
"datasource": "prometheus",
"value_type": "double",
"kubernetes_object": "namespace",
"aggregation_functions": [
{
"function": "avg",
"query": "avg_over_time(sum by(namespace) (container_memory_working_set_bytes{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
},
{
"function": "max",
"query": "max_over_time(sum by(namespace) (container_memory_working_set_bytes{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
},
{
"function": "min",
"query": "min_over_time(sum by(namespace) (container_memory_working_set_bytes{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
}
]
},
{
"name": "namespaceMemoryRSS",
"datasource": "prometheus",
"value_type": "double",
"kubernetes_object": "namespace",
"aggregation_functions": [
{
"function": "avg",
"query": "avg_over_time(sum by(namespace) (container_memory_rss{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
},
{
"function": "max",
"query": "max_over_time(sum by(namespace) (container_memory_rss{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
},
{
"function": "min",
"query": "min_over_time(sum by(namespace) (container_memory_rss{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
}
]
},
{
"name": "namespaceTotalPods",
"datasource": "prometheus",
"value_type": "double",
"kubernetes_object": "namespace",
"aggregation_functions": [
{
"function": "max",
"query": "max_over_time(sum by(namespace) ((kube_pod_info{namespace=\"$NAMESPACE$\"}))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
},
{
"function": "avg",
"query": "avg_over_time(sum by(namespace) ((kube_pod_info{namespace=\"$NAMESPACE$\"}))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
}
]
},
{
"name": "namespaceRunningPods",
"datasource": "prometheus",
"value_type": "double",
"kubernetes_object": "namespace",
"aggregation_functions": [
{
"function": "max",
"query": "max_over_time(sum by(namespace) ((kube_pod_status_phase{phase=\"Running\", namespace=\"$NAMESPACE$\"}))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
},
{
"function": "avg",
"query": "avg_over_time(sum by(namespace) ((kube_pod_status_phase{phase=\"Running\", namespace=\"$NAMESPACE$\"}))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
}
]
},
{
"name": "namespaceMaxDate",
"datasource": "prometheus",
"value_type": "double",
"kubernetes_object": "namespace",
"aggregation_functions": [
{
"function": "max",
"query": "max(last_over_time(timestamp((sum by (namespace) (container_cpu_usage_seconds_total{namespace=\"$NAMESPACE$\"})) > 0 )[15d:]))",
"version": ""
}
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,168 @@ slo:
aggregation_functions:
- function: max
query: 'max by(namespace,container) (last_over_time((timestamp(container_cpu_usage_seconds_total{namespace="$NAMESPACE$", container="$CONTAINER_NAME$"} > 0))[15d:]))'

## namespace related queries

# Namespace quota for CPU requests
# Show namespace quota for CPU requests in cores for a namespace
- name: namespaceCpuRequest
datasource: prometheus
value_type: "double"
kubernetes_object: "namespace"
aggregation_functions:
# sum of all cpu request quotas for a namespace in cores
- function: sum
query: 'sum by (namespace) (kube_resourcequota{namespace="$NAMESPACE$", resource="requests.cpu", type="hard"})'

# Namespace quota for CPU limits
# Show namespace quota for CPU limits in cores for a namespace
- name: namespaceCpuLimit
datasource: prometheus
value_type: "double"
kubernetes_object: "namespace"
aggregation_functions:
# sum of all cpu limits quotas for a namespace in cores
- function: sum
query: 'sum by (namespace) (kube_resourcequota{namespace="$NAMESPACE$", resource="limits.cpu", type="hard"})'


# Namespace quota for memory requests
# Show namespace quota for memory requests in bytes for a namespace
- name: namespaceMemoryRequest
datasource: prometheus
value_type: "double"
kubernetes_object: "namespace"
aggregation_functions:
# sum of all memory requests quotas for a namespace in bytes
- function: sum
query: 'sum by (namespace) (kube_resourcequota{namespace="$NAMESPACE$", resource="requests.memory", type="hard"})'


# Namespace quota for memory limits
# Show namespace quota for memory limits in bytes for a namespace
- name: namespaceMemoryLimit
datasource: prometheus
value_type: "double"
kubernetes_object: "namespace"
aggregation_functions:
# sum of all memory limits quotas for a namespace in bytes
- function: sum
query: 'sum by (namespace) (kube_resourcequota{namespace="$NAMESPACE$", resource="limits.memory", type="hard"})'


# Namespace CPU usage
# Show cpu usages in cores for a namespace
- name: namespaceCpuUsage
datasource: prometheus
value_type: "double"
kubernetes_object: "namespace"
aggregation_functions:
# average cpu usages in cores for a namespace
- function: avg
query: 'avg_over_time(sum by(namespace) (node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{namespace="$NAMESPACE$", container!="", container!="POD", pod!=""})[$MEASUREMENT_DURATION_IN_MIN$m:])'

# maximum cpu usages in cores for a namespace
- function: max
query: 'max_over_time(sum by(namespace) (node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{namespace="$NAMESPACE$", container!="", container!="POD", pod!=""})[$MEASUREMENT_DURATION_IN_MIN$m:])'

# minimum cpu usages in cores for a namespace
- function: min
query: 'min_over_time(sum by(namespace) (node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{namespace="$NAMESPACE$", container!="", container!="POD", pod!=""})[$MEASUREMENT_DURATION_IN_MIN$m:])'


# Namespace CPU Throttle
# Show cpu throttle in cores for a namespace
- name: namespaceCpuThrottle
datasource: prometheus
value_type: "double"
kubernetes_object: "namespace"
aggregation_functions:
# average cpu throttle in cores for a namespace
- function: avg
query: 'avg_over_time(sum by(namespace) (rate(container_cpu_cfs_throttled_seconds_total{namespace="$NAMESPACE$", container!="", container!="POD", pod!=""}[5m]))[$MEASUREMENT_DURATION_IN_MIN$m:])'

# maximum cpu throttle in cores for a namespace
- function: max
query: 'max_over_time(sum by(namespace) (rate(container_cpu_cfs_throttled_seconds_total{namespace="$NAMESPACE$", container!="", container!="POD", pod!=""}[5m]))[$MEASUREMENT_DURATION_IN_MIN$m:])'

# minimum cpu throttle in cores for a namespace
- function: min
query: 'min_over_time(sum by(namespace) (rate(container_cpu_cfs_throttled_seconds_total{namespace="$NAMESPACE$", container!="", container!="POD", pod!=""}[5m]))[$MEASUREMENT_DURATION_IN_MIN$m:])'


# Namespace memory usage
# Show memory usages in bytes for a namespace
- name: namespaceMemoryUsage
datasource: prometheus
value_type: "double"
kubernetes_object: "namespace"
aggregation_functions:
# average memory usage in bytes for a namespace
- function: avg
query: 'avg_over_time(sum by(namespace) (container_memory_working_set_bytes{namespace="$NAMESPACE$", container!="", container!="POD", pod!=""})[$MEASUREMENT_DURATION_IN_MIN$m:])'

# maximum memory usage in bytes for a namespace
- function: max
query: 'max_over_time(sum by(namespace) (container_memory_working_set_bytes{namespace="$NAMESPACE$", container!="", container!="POD", pod!=""})[$MEASUREMENT_DURATION_IN_MIN$m:])'

# minimum memory usage in bytes for a namespace
- function: min
query: 'min_over_time(sum by(namespace) (container_memory_working_set_bytes{namespace="$NAMESPACE$", container!="", container!="POD", pod!=""})[$MEASUREMENT_DURATION_IN_MIN$m:])'


# Namespace memory rss value
# Show memory rss in bytes for a namespace
- name: namespaceMemoryRSS
datasource: prometheus
value_type: "double"
kubernetes_object: "namespace"
aggregation_functions:
# average memory rss in bytes for a namespace
- function: avg
query: 'avg_over_time(sum by(namespace) (container_memory_rss{namespace="$NAMESPACE$", container!="", container!="POD", pod!=""})[$MEASUREMENT_DURATION_IN_MIN$m:])'

# maximum memory rss in bytes for a namespace
- function: max
query: 'max_over_time(sum by(namespace) (container_memory_rss{namespace="$NAMESPACE$", container!="", container!="POD", pod!=""})[$MEASUREMENT_DURATION_IN_MIN$m:])'

# minimum memory rss in bytes for a namespace
- function: min
query: 'min_over_time(sum by(namespace) (container_memory_rss{namespace="$NAMESPACE$", container!="", container!="POD", pod!=""})[$MEASUREMENT_DURATION_IN_MIN$m:])'


# Show total pods in a namespace
- name: namespaceTotalPods
datasource: prometheus
value_type: "double"
kubernetes_object: "namespace"
aggregation_functions:
# maximum total pods in a namespace
- function: max
query: 'max_over_time(sum by(namespace) ((kube_pod_info{namespace="$NAMESPACE$"}))[$MEASUREMENT_DURATION_IN_MIN$m:])'
# average total pods in a namespace
- function: avg
query: 'avg_over_time(sum by(namespace) ((kube_pod_info{namespace="$NAMESPACE$"}))[$MEASUREMENT_DURATION_IN_MIN$m:])'


# Show total running pods in a namespace
- name: namespaceRunningPods
datasource: prometheus
value_type: "double"
kubernetes_object: "namespace"
aggregation_functions:
# maximum total pods in a namespace
- function: max
query: 'max_over_time(sum by(namespace) ((kube_pod_status_phase{phase="Running"}))[$MEASUREMENT_DURATION_IN_MIN$m:])'
# average total pods in a namespace
- function: avg
query: 'avg_over_time(sum by(namespace) ((kube_pod_status_phase{phase="Running"}))[$MEASUREMENT_DURATION_IN_MIN$m:])'

# Show last activity for a namespace
- name: namespaceMaxDate
datasource: prometheus
value_type: "double"
kubernetes_object: "namespace"
aggregation_functions:
- function: max
query: 'max(last_over_time(timestamp((sum by (namespace) (container_cpu_usage_seconds_total{namespace="$NAMESPACE$"})) > 0 )[15d:]))'

0 comments on commit 6d10f29

Please sign in to comment.