监控修改
Former-commit-id: 6546b9888afc383fc497b7b4990f489125cb4b5d
This commit is contained in:
parent
74bfb9c5b7
commit
c42afa719a
|
@ -11,10 +11,12 @@ info(
|
|||
type ControllerMetricsReq {
|
||||
Metrics []string `form:"metrics"`
|
||||
ParticipantId int64 `form:"participantId"`
|
||||
Pods string `form:"pods"`
|
||||
Pod string `form:"pod,optional"`
|
||||
WorkloadName string `form:"workloadName,optional"`
|
||||
Steps string `form:"steps"`
|
||||
Start string `form:"start"`
|
||||
End string `form:"end"`
|
||||
Level string `form:"level,optional"`
|
||||
}
|
||||
|
||||
type (
|
||||
|
@ -29,26 +31,26 @@ type (
|
|||
Name string `form:"name"` // 名称
|
||||
}
|
||||
|
||||
CloudResp {
|
||||
CloudResp {
|
||||
Code string `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Msg string `json:"msg"`
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
TenantInfo {
|
||||
Id int64 `json:"id"` // id
|
||||
TenantName string `json:"tenantName"` // 租户名称
|
||||
TenantDesc string `json:"tenantDesc"` // 描述信息
|
||||
Clusters string `json:"clusters"` // 集群名称,用","分割
|
||||
Type int64 `json:"type"` // 租户所属(0数算,1超算,2智算)
|
||||
DeletedFlag int64 `json:"deletedFlag"` // 是否删除
|
||||
CreatedBy int64 `json:"createdBy"` // 创建人
|
||||
CreatedTime string `json:"createdTime"` // 创建时间
|
||||
UpdatedBy int64 `json:"updatedBy"` // 更新人
|
||||
UpdatedTime string `json:"updated_time"` // 更新时间
|
||||
Id int64 `json:"id"` // id
|
||||
TenantName string `json:"tenantName"` // 租户名称
|
||||
TenantDesc string `json:"tenantDesc"` // 描述信息
|
||||
Clusters string `json:"clusters"` // 集群名称,用","分割
|
||||
Type int64 `json:"type"` // 租户所属(0数算,1超算,2智算)
|
||||
DeletedFlag int64 `json:"deletedFlag"` // 是否删除
|
||||
CreatedBy int64 `json:"createdBy"` // 创建人
|
||||
CreatedTime string `json:"createdTime"` // 创建时间
|
||||
UpdatedBy int64 `json:"updatedBy"` // 更新人
|
||||
UpdatedTime string `json:"updated_time"` // 更新时间
|
||||
}
|
||||
|
||||
UpdateTenantReq{
|
||||
UpdateTenantReq {
|
||||
Tenants [] TenantInfo `json:"tenants"`
|
||||
}
|
||||
)
|
||||
|
|
|
@ -26,9 +26,15 @@ func NewControllerMetricsLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||
|
||||
func (l *ControllerMetricsLogic) ControllerMetrics(req *types.ControllerMetricsReq) (resp *types.ControllerMetricsResp, err error) {
|
||||
resp = &types.ControllerMetricsResp{}
|
||||
metrics := l.svcCtx.PromClient[req.ParticipantId].GetNamedMetricsByTime(req.Metrics, req.Start, req.End, 60*time.Minute, tracker.ControllerOption{
|
||||
PodsName: req.Pods,
|
||||
})
|
||||
resp.Data = metrics
|
||||
if len(req.Pod) != 0 {
|
||||
resp.Data = l.svcCtx.PromClient[req.ParticipantId].GetNamedMetricsByTime(req.Metrics, req.Start, req.End, 60*time.Minute, tracker.PodOption{
|
||||
PodName: req.Pod,
|
||||
})
|
||||
} else {
|
||||
|
||||
resp.Data = l.svcCtx.PromClient[req.ParticipantId].GetNamedMetricsByTime(req.Metrics, req.Start, req.End, 60*time.Minute, tracker.ControllerOption{
|
||||
WorkloadName: req.WorkloadName,
|
||||
})
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
@ -3410,10 +3410,12 @@ type ShowNodeDetailsResp struct {
|
|||
type ControllerMetricsReq struct {
|
||||
Metrics []string `form:"metrics"`
|
||||
ParticipantId int64 `form:"participantId"`
|
||||
Pods string `form:"pods"`
|
||||
Pod string `form:"pod,optional"`
|
||||
WorkloadName string `form:"workloadName,optional"`
|
||||
Steps string `form:"steps"`
|
||||
Start string `form:"start"`
|
||||
End string `form:"end"`
|
||||
Level string `form:"level,optional"`
|
||||
}
|
||||
|
||||
type RegisterClusterReq struct {
|
||||
|
|
|
@ -56,8 +56,8 @@ var promQLTemplates = map[string]string{
|
|||
"namespace_ingresses_extensions_count": `sum by (namespace) (kube_ingress_labels{namespace!=""} * on (namespace) group_left(workspace) kube_namespace_labels{$1})`,
|
||||
"namespace_s2ibuilder_count": `sum by (namespace) (s2i_s2ibuilder_created{namespace!=""} * on (namespace) group_left(workspace) kube_namespace_labels{$1})`,
|
||||
|
||||
"controller_cpu_usage_rate": `round(sum by (owner_name) (sum by (owner_name, pod) (irate(container_cpu_usage_seconds_total{job="kubelet", $1, image!=""}[5m]))/ sum by (owner_name,pod) (kube_pod_container_resource_limits{resource="cpu"}))/count(kube_pod_info{$2}) by (owner_name),0.0001)`,
|
||||
"controller_memory_usage_rate": `round(sum by (owner_name) (sum by (owner_name, pod) (irate(container_memory_usage_bytes{job="kubelet", $1, image!=""}[5m]))/ sum by (owner_name,pod) (kube_pod_container_resource_limits{resource="memory"}))/count(kube_pod_info{$2}) by (owner_name),0.0001)`,
|
||||
"controller_cpu_usage_rate": `sum( node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{}* on(namespace,pod) group_left(workload) namespace_workload_pod:kube_pod_owner:relabel{$1}) by (workload)/sum( kube_pod_container_resource_limits{job="kube-state-metrics", resource="cpu"}* on(namespace,pod) group_left(workload) namespace_workload_pod:kube_pod_owner:relabel{ }) by (workload)`,
|
||||
"controller_memory_usage_rate": `sum( container_memory_working_set_bytes{job="kubelet", metrics_path="/metrics/cadvisor", container!="", image!=""} * on(namespace,pod) group_left(workload) namespace_workload_pod:kube_pod_owner:relabel{$1}) by (workload)/sum( kube_pod_container_resource_limits{job="kube-state-metrics", resource="memory"}* on(namespace,pod) group_left(workload) namespace_workload_pod:kube_pod_owner:relabel{ }) by (workload)`,
|
||||
// pod
|
||||
"pod_cpu_usage": `round(sum by (namespace, pod) (irate(container_cpu_usage_seconds_total{job="kubelet", pod!="", image!=""}[5m])) * on (namespace, pod) group_left(owner_kind,owner_name) kube_pod_owner{$1} * on (namespace, pod) group_left(node) kube_pod_info{$2}, 0.001)`,
|
||||
"pod_cpu_usage_rate": `sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{ $1}) by (pod) / sum(kube_pod_container_resource_limits{ $1,unit="core"}) by (pod)`,
|
||||
|
@ -147,82 +147,17 @@ func makeNamespaceMetricExpr(tmpl string, o QueryOptions) string {
|
|||
}
|
||||
|
||||
func makeControllerMetricExpr(tmpl string, o QueryOptions) string {
|
||||
var podName string
|
||||
var workload string
|
||||
|
||||
podName = fmt.Sprintf(`pod=~"%s"`, o.PodName)
|
||||
return strings.NewReplacer("$1", podName, "$2", podName).Replace(tmpl)
|
||||
workload = fmt.Sprintf(`workload="%s"`, o.WorkloadName)
|
||||
return strings.NewReplacer("$1", workload).Replace(tmpl)
|
||||
}
|
||||
|
||||
func makePodMetricExpr(tmpl string, o QueryOptions) string {
|
||||
var podSelector, workloadSelector string
|
||||
var podName string
|
||||
|
||||
// For monitoriong pods of the specific workload
|
||||
// GET /namespaces/{namespace}/workloads/{kind}/{workload}/pods
|
||||
|
||||
// For monitoring pods in the specific namespace
|
||||
// GET /namespaces/{namespace}/workloads/{kind}/{workload}/pods or
|
||||
// GET /namespaces/{namespace}/pods/{pod} or
|
||||
// GET /namespaces/{namespace}/pods
|
||||
if o.Namespace != "" {
|
||||
if o.PodName != "" {
|
||||
podSelector = fmt.Sprintf(`pod="%s", namespace="%s"`, o.PodName, o.Namespace)
|
||||
} else {
|
||||
podSelector = fmt.Sprintf(`pod=~"%s", namespace="%s"`, o.ResourceFilter, o.Namespace)
|
||||
}
|
||||
} else {
|
||||
var namespaces, pods []string
|
||||
if o.NamespacedResourcesFilter != "" {
|
||||
for _, np := range strings.Split(o.NamespacedResourcesFilter, "|") {
|
||||
if nparr := strings.SplitN(np, "/", 2); len(nparr) > 1 {
|
||||
namespaces = append(namespaces, nparr[0])
|
||||
pods = append(pods, nparr[1])
|
||||
} else {
|
||||
pods = append(pods, np)
|
||||
}
|
||||
}
|
||||
}
|
||||
// For monitoring pods on the specific node
|
||||
// GET /nodes/{node}/pods/{pod}
|
||||
// GET /nodes/{node}/pods
|
||||
if o.NodeName != "" {
|
||||
if o.PodName != "" {
|
||||
if nparr := strings.SplitN(o.PodName, "/", 2); len(nparr) > 1 {
|
||||
podSelector = fmt.Sprintf(`namespace="%s",pod="%s", node="%s"`, nparr[0], nparr[1], o.NodeName)
|
||||
} else {
|
||||
podSelector = fmt.Sprintf(`pod="%s", node="%s"`, o.PodName, o.NodeName)
|
||||
}
|
||||
} else {
|
||||
var ps []string
|
||||
ps = append(ps, fmt.Sprintf(`node="%s"`, o.NodeName))
|
||||
if o.ResourceFilter != "" {
|
||||
ps = append(ps, fmt.Sprintf(`pod=~"%s"`, o.ResourceFilter))
|
||||
}
|
||||
|
||||
if len(namespaces) > 0 {
|
||||
ps = append(ps, fmt.Sprintf(`namespace=~"%s"`, strings.Join(namespaces, "|")))
|
||||
}
|
||||
if len(pods) > 0 {
|
||||
ps = append(ps, fmt.Sprintf(`pod=~"%s"`, strings.Join(pods, "|")))
|
||||
}
|
||||
podSelector = strings.Join(ps, ",")
|
||||
}
|
||||
} else {
|
||||
// For monitoring pods in the whole cluster
|
||||
// Get /pods
|
||||
var ps []string
|
||||
if len(namespaces) > 0 {
|
||||
ps = append(ps, fmt.Sprintf(`namespace=~"%s"`, strings.Join(namespaces, "|")))
|
||||
}
|
||||
if len(pods) > 0 {
|
||||
ps = append(ps, fmt.Sprintf(`pod=~"%s"`, strings.Join(pods, "|")))
|
||||
}
|
||||
if len(ps) > 0 {
|
||||
podSelector = strings.Join(ps, ",")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return strings.NewReplacer("$1", workloadSelector, "$2", podSelector).Replace(tmpl)
|
||||
podName = fmt.Sprintf(`pod="%s"`, o.PodName)
|
||||
return strings.NewReplacer("$1", podName).Replace(tmpl)
|
||||
}
|
||||
|
||||
func makeContainerMetricExpr(tmpl string, o QueryOptions) string {
|
||||
|
|
|
@ -72,6 +72,7 @@ type QueryOptions struct {
|
|||
WorkspaceName string
|
||||
Namespace string
|
||||
WorkloadKind string
|
||||
WorkloadName string
|
||||
OwnerName string
|
||||
PodName string
|
||||
PodsName string
|
||||
|
@ -250,11 +251,10 @@ type PodOption struct {
|
|||
}
|
||||
|
||||
type ControllerOption struct {
|
||||
PodsName string
|
||||
Namespace string
|
||||
Kind string
|
||||
OwnerName string
|
||||
Level string
|
||||
Namespace string
|
||||
Kind string
|
||||
WorkloadName string
|
||||
Level string
|
||||
}
|
||||
|
||||
func (po PodOption) Apply(o *QueryOptions) {
|
||||
|
@ -272,8 +272,7 @@ func (co ControllerOption) Apply(o *QueryOptions) {
|
|||
o.Level = LevelController
|
||||
o.Namespace = co.Namespace
|
||||
o.WorkloadKind = co.Kind
|
||||
o.OwnerName = co.OwnerName
|
||||
o.PodName = co.PodsName
|
||||
o.WorkloadName = co.WorkloadName
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue