Skip to content

Commit

Permalink
update cpu/mem usage (#5006)
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyxjh authored Aug 28, 2024
1 parent 31471d7 commit 06caa81
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
8 changes: 4 additions & 4 deletions service/launchpad/request/req.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func GetQuery(query *api.VMRequest) (string, error) {
var result string
switch query.Type {
case "cpu":
result = "round(max by (pod) (rate(container_cpu_usage_seconds_total{namespace=~\"$namespace\",pod=~\"$pod.*\"}[5m])) / on (pod) (max by (pod) (container_spec_cpu_quota{namespace=~\"$namespace\",pod=~\"$pod.*\"} / 100000)) ,0.01)"
result = "round(sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{cluster!=\"\", namespace=~\"$namespace\",pod=~\"$pod.*\"}) by (pod) / sum(cluster:namespace:pod_cpu:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"$namespace\",pod=~\"$pod.*\"}) by (pod)*100,0.01)"
case "memory":
result = "round(max by (pod)(container_memory_usage_bytes{namespace=~\"$namespace\",pod=~\"$pod.*\"})/ on (pod) (max by (pod) (container_spec_memory_limit_bytes{namespace=~\"$namespace\",pod=~\"$pod.*\"})) ,0.01)"
result = "round(sum(container_memory_working_set_bytes{job=\"kubelet\", metrics_path=\"/metrics/cadvisor\",cluster!=\"\", namespace=~\"$namespace\",pod=~\"$pod.*\"}) by(pod) / sum(cluster:namespace:pod_memory:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"$namespace\",pod=~\"$pod.*\"}) by (pod) * 100, 0.01)"
case "average_cpu":
result = "avg(round(max by (pod) (rate(container_cpu_usage_seconds_total{namespace=~\"$namespace\",pod=~\"$pod.*\"}[5m])) / on (pod) (max by (pod) (container_spec_cpu_quota{namespace=~\"$namespace\",pod=~\"$pod.*\"} / 100000)) ,0.01))"
result = "avg(sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{cluster!=\"\", namespace=~\"$namespace\",pod=~\"$pod.*\"}) by (pod) / sum(cluster:namespace:pod_cpu:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"$namespace\",pod=~\"$pod.*\"}) by (pod)*100,0.01)"
case "average_memory":
result = "avg(round(max by (pod)(container_memory_usage_bytes{namespace=~\"$namespace\",pod=~\"$pod.*\"})/ on (pod) (max by (pod) (container_spec_memory_limit_bytes{namespace=~\"$namespace\",pod=~\"$pod.*\"})) ,0.01))"
result = "avg(sum(container_memory_working_set_bytes{job=\"kubelet\", metrics_path=\"/metrics/cadvisor\",cluster!=\"\", namespace=~\"$namespace\",pod=~\"$pod.*\"}) by(pod) / sum(cluster:namespace:pod_memory:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"$namespace\",pod=~\"$pod.*\"}) by (pod) * 100, 0.01)"
default:
log.Println(query.Type)
}
Expand Down
21 changes: 10 additions & 11 deletions service/pkg/api/req.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ type Stats struct {

var (
Mysql = map[string]string{
"cpu": "round(max by (pod) (rate(container_cpu_usage_seconds_total{namespace=~\"#\",pod=~\"@-mysql-\\\\d\",container=\"mysql\" }[5m])) / on (pod) (max by (pod) (container_spec_cpu_quota{namespace=~\"#\", pod=~\"@-mysql-\\\\d\",container=\"mysql\"} / 100000)) * 100,0.01)",
"memory": "round(max by (pod)(container_memory_usage_bytes{namespace=~\"#\",pod=~\"@-mysql-\\\\d\",container=\"mysql\"})/ on (pod) (max by (pod) (container_spec_memory_limit_bytes{namespace=~\"#\", pod=~\"@-mysql-\\\\d\", container=\"mysql\"})) * 100,0.01)",
"cpu": "round(sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{cluster!=\"\", namespace=~\"#\",pod=~\"@-mysql-\\\\d\"}) by (pod) / sum(cluster:namespace:pod_cpu:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"#\",pod=~\"@-mysql-\\\\d\"}) by (pod)*100,0.01)",
"memory": "round(sum(container_memory_working_set_bytes{job=\"kubelet\", metrics_path=\"/metrics/cadvisor\",cluster!=\"\", namespace=~\"#\",container!=\"\", image!=\"\",pod=~\"@-mysql-\\\\d\"}) by(pod) / sum(cluster:namespace:pod_memory:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"#\", pod=~\"@-mysql-\\\\d\"}) by (pod) * 100, 0.01)",
"disk_capacity": "(max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_capacity_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-mysql-\\\\d\"}))",
"disk_used": "(max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_used_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-mysql-\\\\d\"}))",
"disk": "round((max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_used_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-mysql-\\\\d\"})) / (max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_capacity_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-mysql-\\\\d\"})) * 100, 0.01)",
Expand All @@ -88,9 +88,8 @@ var (
"table_locks": "sum(rate(mysql_global_status_table_locks_immediate{namespace=~\"#\", app_kubernetes_io_instance=~\"@\"}[1m])) by (namespace,app_kubernetes_io_instance,pod)",
}
Pgsql = map[string]string{
"cpu": "round(max by (pod) (rate(container_cpu_usage_seconds_total{namespace=~\"#\",pod=~\"@-postgresql-\\\\d\" ,container=\"postgresql\"}[5m])) / on (pod) (max by (pod) (container_spec_cpu_quota{namespace=~\"#\", pod=~\"@-postgresql-\\\\d\",container=\"postgresql\"} / 100000)) * 100,0.01)",

"memory": "round(max by (pod)(container_memory_usage_bytes{namespace=~\"#\",pod=~\"@-postgresql-\\\\d\",container=\"postgresql\" })/ on (pod) (max by (pod) (container_spec_memory_limit_bytes{namespace=~\"#\", pod=~\"@-postgresql-\\\\d\", container=\"postgresql\"})) * 100,0.01)",
"cpu": "round(sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{cluster!=\"\", namespace=~\"#\",pod=~\"@-postgresql-\\\\d\"}) by (pod) / sum(cluster:namespace:pod_cpu:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"#\",pod=~\"@-postgresql-\\\\d\"}) by (pod)*100,0.01)",
"memory": "round(sum(container_memory_working_set_bytes{job=\"kubelet\", metrics_path=\"/metrics/cadvisor\",cluster!=\"\", namespace=~\"#\",container!=\"\", image!=\"\",pod=~\"@-postgresql-\\\\d\"}) by(pod) / sum(cluster:namespace:pod_memory:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"#\", pod=~\"@-postgresql-\\\\d\"}) by (pod) * 100, 0.01)",
"disk": "round((max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_used_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-postgresql-\\\\d\"})) / (max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_capacity_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-postgresql-\\\\d\"})) * 100, 0.01)",
"disk_capacity": "(max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_capacity_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-postgresql-\\\\d\"}))",
"disk_used": "(max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_used_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-postgresql-\\\\d\"}))",
Expand All @@ -109,8 +108,8 @@ var (
}

Mongo = map[string]string{
"cpu": "round(max by (pod) (rate(container_cpu_usage_seconds_total{namespace=~\"#\",pod=~\"@-mongodb-\\\\d\" ,container=\"mongodb\" }[5m])) / on (pod) (max by (pod) (container_spec_cpu_quota{namespace=~\"#\", pod=~\"@-mongodb-\\\\d\" ,container=\"mongodb\"} / 100000)) * 100,0.01)",
"memory": "round(max by (pod)(container_memory_usage_bytes{namespace=~\"#\",pod=~\"@-mongodb-\\\\d\" ,container=\"mongodb\"})/ on (pod) (max by (pod) (container_spec_memory_limit_bytes{namespace=~\"#\", pod=~\"@-mongodb-\\\\d\",container=\"mongodb\"})) * 100,0.01)",
"cpu": "round(sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{cluster!=\"\", namespace=~\"#\",pod=~\"@-mongodb-\\\\d\"}) by (pod) / sum(cluster:namespace:pod_cpu:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"#\",pod=~\"@-mongodb-\\\\d\"}) by (pod)*100,0.01)",
"memory": "round(sum(container_memory_working_set_bytes{job=\"kubelet\", metrics_path=\"/metrics/cadvisor\",cluster!=\"\", namespace=~\"#\",container!=\"\", image!=\"\",pod=~\"@-mongodb-\\\\d\"}) by(pod) / sum(cluster:namespace:pod_memory:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"#\", pod=~\"@-mongodb-\\\\d\"}) by (pod) * 100, 0.01)",
"disk_capacity": "(max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_capacity_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-mongodb-\\\\d\"}))",
"disk": "round((max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_used_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-mongodb-\\\\d\"})) / (max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_capacity_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-mongodb-\\\\d\"})) * 100, 0.01)",
"disk_used": "(max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_used_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-mongodb-\\\\d\"}))",
Expand All @@ -125,8 +124,8 @@ var (
}

Redis = map[string]string{
"cpu": "round(max by (pod) (rate(container_cpu_usage_seconds_total{namespace=~\"#\",pod=~\"@-redis-\\\\d\" ,container=\"redis\"}[5m])) / on (pod) (max by (pod) (container_spec_cpu_quota{namespace=~\"#\", pod=~\"@-redis-\\\\d\",container=\"redis\"} / 100000)) * 100,0.01)",
"memory": "round(max by (pod)(container_memory_usage_bytes{namespace=~\"#\",pod=~\"@-redis-\\\\d\",container=\"redis\" })/ on (pod) (max by (pod) (container_spec_memory_limit_bytes{namespace=~\"#\", pod=~\"@-redis-\\\\d\",container=\"redis\"})) * 100,0.01)",
"cpu": "round(sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{cluster!=\"\", namespace=~\"#\",pod=~\"@-redis-\\\\d\"}) by (pod) / sum(cluster:namespace:pod_cpu:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"#\",pod=~\"@-redis-\\\\d\"}) by (pod)*100,0.01)",
"memory": "round(sum(container_memory_working_set_bytes{job=\"kubelet\", metrics_path=\"/metrics/cadvisor\",cluster!=\"\", namespace=~\"#\",container!=\"\", image!=\"\",pod=~\"@-redis-\\\\d\"}) by(pod) / sum(cluster:namespace:pod_memory:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"#\", pod=~\"@-redis-\\\\d\"}) by (pod) * 100, 0.01)",
"disk_capacity": "(max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_capacity_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-redis-\\\\d\"}))",
"disk": "round((max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_used_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-redis-\\\\d\"})) / (max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_capacity_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-redis-\\\\d\"})) * 100, 0.01)",
"disk_used": "(max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_used_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-redis-\\\\d\"}))",
Expand All @@ -150,8 +149,8 @@ var (
}

Kafka = map[string]string{
"cpu": "round(max by (pod) (rate(container_cpu_usage_seconds_total{namespace=~\"#\",pod=~\"@-(kafka-broker|kafka-server|controller)-\\\\d\" ,container=\"kafka\"}[5m])) / on (pod) (max by (pod) (container_spec_cpu_quota{namespace=~\"#\", pod=~\"@-(kafka-broker|kafka-server|controller)-\\\\d\",container=\"kafka\"} / 100000)) * 100,0.01)",
"memory": "round(max by (pod)(container_memory_usage_bytes{namespace=~\"#\",pod=~\"@-(kafka-broker|kafka-server|controller)-\\\\d\",container=\"kafka\" })/ on (pod) (max by (pod) (container_spec_memory_limit_bytes{namespace=~\"#\", pod=~\"@-(kafka-broker|kafka-server|controller)-\\\\d\",container=\"kafka\"})) * 100,0.01)",
"cpu": "round(sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{cluster!=\"\", namespace=~\"#\",pod=~\"@-kafka-\\\\d\"}) by (pod) / sum(cluster:namespace:pod_cpu:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"#\",pod=~\"@-kafka-\\\\d\"}) by (pod)*100,0.01)",
"memory": "round(sum(container_memory_working_set_bytes{job=\"kubelet\", metrics_path=\"/metrics/cadvisor\",cluster!=\"\", namespace=~\"#\",container!=\"\", image!=\"\",pod=~\"@-kafka-\\\\d\"}) by(pod) / sum(cluster:namespace:pod_memory:active:kube_pod_container_resource_limits{cluster!=\"\", namespace=~\"#\", pod=~\"@-kafka-\\\\d\"}) by (pod) * 100, 0.01)",
"disk_capacity": "(max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_capacity_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-(kafka-broker|kafka-server)-\\\\d\"}))",
"disk": "round((max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_used_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-(kafka-broker|kafka-server)-\\\\d\"})) / (max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_capacity_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-(kafka-broker|kafka-server)-\\\\d\"})) * 100, 0.01)",
"disk_used": "(max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_used_bytes {namespace=~\"#\", persistentvolumeclaim=~\"data-@-(kafka-broker|kafka-server)-\\\\d\"}))",
Expand Down

0 comments on commit 06caa81

Please sign in to comment.