未验证 提交 fa3d09b8 编写于 作者: H huanggze

fix PromQL construction

Signed-off-by: Nhuanggze <loganhuang@yunify.com>
上级 7b81d24e
......@@ -27,12 +27,16 @@ func MakeWorkloadPromQL(metricName, nsName, resources_filter, wkKind string) str
wkKind = DaemonSet
case "statefulset":
wkKind = StatefulSet
default:
wkKind = "(.*)"
}
if resources_filter == "" {
resources_filter = ".*"
if wkKind == "" {
resources_filter = Any
} else if resources_filter == "" {
if strings.Contains(metricName, "pod") {
resources_filter = wkKind + ":" + Any
} else if strings.Contains(metricName, strings.ToLower(wkKind)) {
resources_filter = Any
}
} else {
var prefix string
......
......@@ -76,6 +76,7 @@ const (
StatefulSet = "StatefulSet"
DaemonSet = "DaemonSet"
Deployment = "Deployment"
Any = ".*"
)
const (
......@@ -598,6 +599,10 @@ var RulePromQLTmplMap = MetricMap{
// workload
// Join the "container_cpu_usage_seconds_total" metric with "kube_pod_owner" to calculate workload-level resource usage
//
// Note the name convention:
// For hardware resource metrics, combine pod metric name with `workload_`
// For k8s resource metrics, must specify the workload type in metric names
"workload_pod_cpu_usage": `round(namespace:workload_cpu_usage:sum{namespace="$2", workload=~"$3"}, 0.001)`,
"workload_pod_memory_usage": `namespace:workload_memory_usage:sum{namespace="$2", workload=~"$3"}`,
"workload_pod_memory_usage_wo_cache": `namespace:workload_memory_usage_wo_cache:sum{namespace="$2", workload=~"$3"}`,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册