-
Notifications
You must be signed in to change notification settings - Fork 252
Update memory_query and cpu_query for Prometheus #420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,11 +252,13 @@ async def get_cluster_summary(self) -> Dict[str, Any]: | |
|
|
||
| # use this for queries with no labels. turn ', cluster="xxx"' to 'cluster="xxx"' | ||
| single_cluster_label = cluster_label.replace(",", "") | ||
|
|
||
| memory_query = f""" | ||
| sum(max by (instance) (machine_memory_bytes{{ {single_cluster_label} }})) | ||
| sum(kube_node_status_capacity{{ resource='memory' {single_cluster_label} }}) | ||
| """ | ||
|
|
||
| cpu_query = f""" | ||
| sum(max by (instance) (machine_cpu_cores{{ {single_cluster_label} }})) | ||
| sum(kube_node_status_capacity{{ resource='cpu' {single_cluster_label} }}) | ||
| """ | ||
|
Comment on lines
260
to
262
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainFix PromQL syntax: use double quotes for label values. PromQL requires double quotes for label values, not single quotes. The current syntax Apply this diff to fix the syntax: cpu_query = f"""
- sum(kube_node_status_capacity{{ resource='cpu' {single_cluster_label} }})
+ sum(kube_node_status_capacity{{ resource="cpu" {single_cluster_label} }})
"""After applying the fixes, please verify that both queries execute successfully in your Prometheus environments: 🏁 Script executed: #!/bin/bash
# Description: Test the corrected Prometheus queries return valid results
# This verifies the syntax is correct and metrics exist
# Note: Replace PROMETHEUS_URL with your actual Prometheus endpoint
PROMETHEUS_URL="${PROMETHEUS_URL:-http://localhost:9090}"
echo "Testing memory query..."
curl -s "${PROMETHEUS_URL}/api/v1/query" \
--data-urlencode 'query=sum(kube_node_status_capacity{resource="memory"})' | jq '.data.result'
echo -e "\nTesting CPU query..."
curl -s "${PROMETHEUS_URL}/api/v1/query" \
--data-urlencode 'query=sum(kube_node_status_capacity{resource="cpu"})' | jq '.data.result'Length of output: 45 I need to verify the PromQL syntax rules and inspect the actual codebase since the Prometheus endpoint is unavailable in the sandbox. Now let me inspect the actual file to verify the current state of the code: Length of output: 16651 Fix PromQL syntax: use double quotes for label values in both queries. PromQL requires double quotes for label values, not single quotes. The current syntax with single quotes will cause query syntax errors. Both the Apply this diff to fix both queries: memory_query = f"""
- sum(kube_node_status_capacity{{ resource='memory' {single_cluster_label} }})
+ sum(kube_node_status_capacity{{ resource="memory" {single_cluster_label} }})
"""
cpu_query = f"""
- sum(kube_node_status_capacity{{ resource='cpu' {single_cluster_label} }})
+ sum(kube_node_status_capacity{{ resource="cpu" {single_cluster_label} }})
"""
🤖 Prompt for AI Agents |
||
| kube_system_requests_mem = f""" | ||
| sum(max(kube_pod_container_resource_requests{{ namespace='kube-system', resource='memory' {cluster_label} }}) by (job, pod, container) ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix PromQL syntax: use double quotes for label values.
PromQL requires double quotes for label values, not single quotes. The current syntax
resource='memory'will cause a query syntax error.Apply this diff to fix the syntax:
📝 Committable suggestion
🤖 Prompt for AI Agents