Skip to content

Commit

Permalink
fix: CPU和内存使用率的计算增加过滤条件 (#3600)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyudeqiu authored Nov 11, 2024
1 parent cbfae55 commit 1c5e3c0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bcs-services/bcs-monitor/pkg/api/metrics/query/bk_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ func (h BKMonitorHandler) GetClusterOverview(c *rest.Context) (ClusterOverviewMe
}

promqlMap := map[string]string{
"cpu_used": `sum(rate(bkmonitor:container_cpu_usage_seconds_total{bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m]))`,
"cpu_used": `sum(rate(bkmonitor:container_cpu_usage_seconds_total{pod_name!="", bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m]))`,
"cpu_request": `sum(avg_over_time(bkmonitor:kube_pod_container_resource_requests_cpu_cores{bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m]))`,
"cpu_total": `sum(avg_over_time(bkmonitor:kube_node_status_allocatable_cpu_cores{bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m]))`,
"memory_used": `sum(avg_over_time(bkmonitor:container_memory_usage_bytes{bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m]))`,
"memory_used": `sum(avg_over_time(bkmonitor:container_memory_usage_bytes{pod_name!="", bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m]))`,
"memory_request": `sum(avg_over_time(bkmonitor:kube_pod_container_resource_requests_memory_bytes{bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m]))`,
"memory_total": `sum(avg_over_time(bkmonitor:kube_node_status_allocatable_memory_bytes{bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m]))`,
"disk_used": `(sum(avg_over_time(bkmonitor:node_filesystem_size_bytes{bcs_cluster_id="%<clusterID>s", fstype=~"%<fstype>s", mountpoint=~"%<mountpoint>s"}[2m])) ` +
Expand Down Expand Up @@ -155,7 +155,7 @@ func (h BKMonitorHandler) ClusterPodUsage(c *rest.Context) (promclient.ResultDat
// ClusterCPUUsage implements Handler.
// nolint
func (h BKMonitorHandler) ClusterCPUUsage(c *rest.Context) (promclient.ResultData, error) {
promql := `sum(rate(bkmonitor:container_cpu_usage_seconds_total{bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m])) / ` +
promql := `sum(rate(bkmonitor:container_cpu_usage_seconds_total{pod_name!="", bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m])) / ` +
`sum(avg_over_time(bkmonitor:kube_node_status_allocatable_cpu_cores{bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m])) * 100`

return h.handleBKMonitorClusterMetric(c, promql)
Expand All @@ -173,7 +173,7 @@ func (h BKMonitorHandler) ClusterCPURequestUsage(c *rest.Context) (promclient.Re
// ClusterMemoryUsage implements Handler.
// nolint
func (h BKMonitorHandler) ClusterMemoryUsage(c *rest.Context) (promclient.ResultData, error) {
promql := `sum(avg_over_time(bkmonitor:container_memory_usage_bytes{bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m])) / ` +
promql := `sum(avg_over_time(bkmonitor:container_memory_usage_bytes{pod_name!="", bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m])) / ` +
`sum(avg_over_time(bkmonitor:kube_node_status_allocatable_memory_bytes{bcs_cluster_id="%<clusterID>s", node!=""%<node>s}[2m])) * 100`

return h.handleBKMonitorClusterMetric(c, promql)
Expand Down

0 comments on commit 1c5e3c0

Please sign in to comment.