Commit 3f0c51d5 authored by ZhangSetSail's avatar ZhangSetSail
Browse files

feat: add application

Showing with 355 additions and 327 deletions
+355 -327
......@@ -120,6 +120,7 @@ func (t *TenantAction) BindTenantsResource(source []*dbmodel.Tenants) api_model.
item.RunningAppNum = re.RunningAppNum
item.RunningAppInternalNum = re.RunningAppInternalNum
item.RunningAppThirdNum = re.RunningAppThirdNum
item.RunningApplications = re.RunningApplications
}
list.Add(item)
}
......@@ -341,12 +342,14 @@ func (t *TenantAction) GetTenantsResources(ctx context.Context, tr *api_model.Te
"service_running_num": 0,
"cpu": 0,
"memory": 0,
"app_running_num": 0,
}
tr, _ := resources[tenantID]
if tr != nil {
result[tenantID]["service_running_num"] = tr.RunningAppNum
result[tenantID]["cpu"] = tr.CpuRequest
result[tenantID]["memory"] = tr.MemoryRequest
result[tenantID]["app_running_num"] = tr.RunningApplications
}
}
//query disk used in prometheus
......@@ -367,16 +370,17 @@ func (t *TenantAction) GetTenantsResources(ctx context.Context, tr *api_model.Te
//TenantResourceStats tenant resource stats
type TenantResourceStats struct {
TenantID string `json:"tenant_id,omitempty"`
CPURequest int64 `json:"cpu_request,omitempty"`
CPULimit int64 `json:"cpu_limit,omitempty"`
MemoryRequest int64 `json:"memory_request,omitempty"`
MemoryLimit int64 `json:"memory_limit,omitempty"`
RunningAppNum int64 `json:"running_app_num"`
UnscdCPUReq int64 `json:"unscd_cpu_req,omitempty"`
UnscdCPULimit int64 `json:"unscd_cpu_limit,omitempty"`
UnscdMemoryReq int64 `json:"unscd_memory_req,omitempty"`
UnscdMemoryLimit int64 `json:"unscd_memory_limit,omitempty"`
TenantID string `json:"tenant_id,omitempty"`
CPURequest int64 `json:"cpu_request,omitempty"`
CPULimit int64 `json:"cpu_limit,omitempty"`
MemoryRequest int64 `json:"memory_request,omitempty"`
MemoryLimit int64 `json:"memory_limit,omitempty"`
RunningAppNum int64 `json:"running_app_num"`
UnscdCPUReq int64 `json:"unscd_cpu_req,omitempty"`
UnscdCPULimit int64 `json:"unscd_cpu_limit,omitempty"`
UnscdMemoryReq int64 `json:"unscd_memory_req,omitempty"`
UnscdMemoryLimit int64 `json:"unscd_memory_limit,omitempty"`
RunningApplications int64 `json:"running_applications"`
}
//GetTenantResource get tenant resource
......@@ -391,6 +395,7 @@ func (t *TenantAction) GetTenantResource(tenantID string) (ts TenantResourceStat
ts.MemoryLimit = tr.MemoryLimit
ts.MemoryRequest = tr.MemoryRequest
ts.RunningAppNum = tr.RunningAppNum
ts.RunningApplications = tr.RunningApplications
return
}
......
......@@ -77,6 +77,7 @@ type TenantAndResource struct {
RunningAppNum int64 `json:"running_app_num"`
RunningAppInternalNum int64 `json:"running_app_internal_num"`
RunningAppThirdNum int64 `json:"running_app_third_num"`
RunningApplications int64 `json:"running_applications"`
}
//TenantList Tenant list struct
......
This diff is collapsed.
......@@ -104,6 +104,7 @@ message TenantResource {
int64 running_app_num = 5;
int64 running_app_third_num = 10;
int64 running_app_internal_num = 11;
int64 running_applications = 12;
}
message TenantResourceList {
......
......@@ -227,18 +227,23 @@ func (r *RuntimeServer) GetTenantResource(ctx context.Context, re *pb.TenantRequ
}
res := r.store.GetTenantResource(tenant.Namespace)
runningApps := r.store.GetTenantRunningApp(re.TenantId)
runningApplications := make(map[string]struct{})
for _, app := range runningApps {
if app.ServiceKind == model.ServiceKindThirdParty {
tr.RunningAppThirdNum++
} else if app.ServiceKind == model.ServiceKindInternal {
tr.RunningAppInternalNum++
}
if _, ok := runningApplications[app.AppID]; !ok {
runningApplications[app.AppID] = struct{}{}
}
}
tr.RunningAppNum = int64(len(runningApps))
tr.CpuLimit = res.CPULimit
tr.CpuRequest = res.CPURequest
tr.MemoryLimit = res.MemoryLimit / 1024 / 1024
tr.MemoryRequest = res.MemoryRequest / 1024 / 1024
tr.RunningApplications = int64(len(runningApplications))
return &tr, nil
}
......@@ -249,13 +254,18 @@ func (r *RuntimeServer) GetTenantResources(context.Context, *pb.Empty) (*pb.Tena
for _, re := range res {
var tr pb.TenantResource
runningApps := r.store.GetTenantRunningApp(re.Namespace)
runningApplications := make(map[string]struct{})
for _, app := range runningApps {
if app.ServiceKind == model.ServiceKindThirdParty {
tr.RunningAppThirdNum++
} else if app.ServiceKind == model.ServiceKindInternal {
tr.RunningAppInternalNum++
}
if _, ok := runningApplications[app.AppID]; !ok {
runningApplications[app.AppID] = struct{}{}
}
}
tr.RunningApplications = int64(len(runningApplications))
tr.RunningAppNum = int64(len(runningApps))
tr.CpuLimit = re.CPULimit
tr.CpuRequest = re.CPURequest
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment