Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
balancer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
86a187cb
authored
Oct 25, 2023
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfix
parent
6890d130
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
17 deletions
+44
-17
balancer/stats.py
+25
-7
core/models.py
+1
-0
main.py
+1
-0
sredis/models.py
+1
-0
sredis/sredis.py
+16
-10
No files found.
balancer/stats.py
View file @
86a187cb
...
@@ -9,7 +9,8 @@ MEM_ALLOCATED_TARGET = "RBstat?target=circle.*.memory.allocated&format=json&time
...
@@ -9,7 +9,8 @@ MEM_ALLOCATED_TARGET = "RBstat?target=circle.*.memory.allocated&format=json&time
MEM_USAGE_TARGET
=
"RBstat?target=circle.*.memory.usage&format=json&time=-2min"
MEM_USAGE_TARGET
=
"RBstat?target=circle.*.memory.usage&format=json&time=-2min"
VMCOUNT_TARGET
=
"RBstat?target=circle.*.vmcount&format=json&time=-2min"
VMCOUNT_TARGET
=
"RBstat?target=circle.*.vmcount&format=json&time=-2min"
CPU_PERCENT_TARGET
=
"RBstat?target=circle.*.cpu.percent&format=json&time=-2min"
CPU_PERCENT_TARGET
=
"RBstat?target=circle.*.cpu.percent&format=json&time=-2min"
STATIC_INFO
=
"dashboard/acpi/nodesum/"
STATIC_INFO_NODE
=
"dashboard/acpi/nodesum/"
STATIC_INFO_VM
=
"dashboard/acpi/vmsum/"
STAT_TARGETS
=
{
STAT_TARGETS
=
{
"mem_allocated"
:
MEM_ALLOCATED_TARGET
,
"mem_allocated"
:
MEM_ALLOCATED_TARGET
,
...
@@ -20,7 +21,8 @@ STAT_TARGETS = {
...
@@ -20,7 +21,8 @@ STAT_TARGETS = {
def
get_static_info_from_dc
(
datacenter
):
def
get_static_info_from_dc
(
datacenter
):
url
:
str
=
f
"{datacenter}/{STATIC_INFO}"
url
:
str
=
f
"{datacenter}/{STATIC_INFO_NODE}"
infos
=
{
"core_num"
:
0
,
"max_ram"
:
0
,
"core_num_sum"
:
0
}
req
=
requests
.
request
(
req
=
requests
.
request
(
method
=
"GET"
,
method
=
"GET"
,
url
=
url
,
url
=
url
,
...
@@ -30,16 +32,32 @@ def get_static_info_from_dc(datacenter):
...
@@ -30,16 +32,32 @@ def get_static_info_from_dc(datacenter):
logger
.
warning
(
logger
.
warning
(
f
"cannot retrieve the data, from dc: {datacenter} ({req.status_code})"
f
"cannot retrieve the data, from dc: {datacenter} ({req.status_code})"
)
)
return
0
,
0
else
:
else
:
try
:
try
:
data
=
json
.
loads
(
req
.
content
)
data
=
json
.
loads
(
req
.
content
)
core_num
=
data
[
"core_num"
]
infos
[
"core_num"
]
=
data
[
"core_num"
]
max_ram
=
data
[
"max_ram"
]
infos
[
"max_ram"
]
=
data
[
"max_ram"
]
return
core_num
,
max_ram
except
json
.
decoder
.
JSONDecodeError
:
except
json
.
decoder
.
JSONDecodeError
:
logger
.
warning
(
"JSON decoding error: Static infos"
)
logger
.
warning
(
"JSON decoding error: Static infos"
)
return
0
,
0
url
=
f
"{datacenter}/{STATIC_INFO_VM}"
req
=
requests
.
request
(
method
=
"GET"
,
url
=
url
,
verify
=
False
,
)
if
int
(
req
.
status_code
/
100
)
!=
2
:
logger
.
warning
(
f
"cannot retrieve the data, from dc: {datacenter} ({req.status_code})"
)
else
:
try
:
data
=
json
.
loads
(
req
.
content
)
infos
[
"core_num_sum"
]
=
data
[
"core_num_sum"
]
except
json
.
decoder
.
JSONDecodeError
:
logger
.
warning
(
"JSON decoding error: Static infos"
)
return
infos
def
get_stat_from_dc
(
datacenter
,
retry
=
False
):
def
get_stat_from_dc
(
datacenter
,
retry
=
False
):
...
...
core/models.py
View file @
86a187cb
...
@@ -54,4 +54,5 @@ class ResourceStat(BaseModel):
...
@@ -54,4 +54,5 @@ class ResourceStat(BaseModel):
mem_used
:
int
mem_used
:
int
cpu_usage
:
float
cpu_usage
:
float
cpu_core
:
int
cpu_core
:
int
vcpu_num
:
int
vm_count
:
int
vm_count
:
int
main.py
View file @
86a187cb
...
@@ -142,6 +142,7 @@ def get_datacenter_stat(username=Depends(get_current_user)):
...
@@ -142,6 +142,7 @@ def get_datacenter_stat(username=Depends(get_current_user)):
cpu_usage
=
x
.
cpu_usage
,
cpu_usage
=
x
.
cpu_usage
,
vm_count
=
x
.
vm_count
,
vm_count
=
x
.
vm_count
,
cpu_core
=
x
.
cpu_core
,
cpu_core
=
x
.
cpu_core
,
vcpu_num
=
x
.
vcpu_num
,
)
)
for
x
in
stats
for
x
in
stats
]
]
...
...
sredis/models.py
View file @
86a187cb
...
@@ -30,3 +30,4 @@ class DataCenterResource(HashModel):
...
@@ -30,3 +30,4 @@ class DataCenterResource(HashModel):
cpu_usage
:
float
=
Field
()
cpu_usage
:
float
=
Field
()
vm_count
:
int
=
Field
()
vm_count
:
int
=
Field
()
cpu_core
:
int
=
Field
()
cpu_core
:
int
=
Field
()
vcpu_num
:
int
=
Field
()
sredis/sredis.py
View file @
86a187cb
...
@@ -63,21 +63,25 @@ def update_datacenter_stats():
...
@@ -63,21 +63,25 @@ def update_datacenter_stats():
for
dc
in
all_keys
.
values
():
for
dc
in
all_keys
.
values
():
logger
.
info
(
f
"Get stats from {dc}"
)
logger
.
info
(
f
"Get stats from {dc}"
)
stats
=
get_stat_from_dc
(
dc
,
retry
=
True
)
stats
=
get_stat_from_dc
(
dc
,
retry
=
True
)
cpu_core
,
mem_max
=
get_static_info_from_dc
(
dc
)
infos
=
get_static_info_from_dc
(
dc
)
cpu_core
=
infos
[
"core_num"
]
mem_max
=
infos
[
"max_ram"
]
vcpu_num
=
infos
[
"core_num_sum"
]
rs
=
ResourceStat
(
rs
=
ResourceStat
(
datacenter_name
=
dc
,
datacenter_name
=
dc
,
vcpu_num
=
vcpu_num
,
cpu_core
=
cpu_core
,
cpu_core
=
cpu_core
,
mem_max
=
int
(
mem_max
/
1048576
)
if
mem_max
else
4096
,
mem_max
=
int
(
mem_max
/
1048576
)
if
mem_max
else
4096
,
mem_allocated
=
int
(
stats
[
"mem_allocated"
][
0
]
/
1048576.0
)
mem_allocated
=
int
(
stats
[
"mem_allocated"
][
0
]
/
1048576.0
)
if
stats
[
"mem_allocated"
]
if
"mem_allocated"
in
stats
and
stats
[
"mem_allocated"
][
0
]
else
0
,
else
0
,
mem_used
=
int
(
stats
[
"mem_usage"
][
0
]
*
4096
/
100.0
)
mem_used
=
int
(
stats
[
"mem_usage"
][
0
]
*
4096
/
100.0
)
if
stats
[
"mem_usage"
][
0
]
if
"mem_usage"
in
stats
and
stats
[
"mem_usage"
][
0
]
else
0
,
else
0
,
cpu_usage
=
float
(
stats
[
"cpu_percent"
][
0
])
cpu_usage
=
float
(
stats
[
"cpu_percent"
][
0
])
if
stats
[
"cpu_percent"
][
0
]
if
"cpu_percent"
in
stats
and
stats
[
"cpu_percent"
][
0
]
else
0.0
,
else
0.0
,
vm_count
=
int
(
stats
[
"vmcount"
][
0
])
if
stats
[
"vmcount"
][
0
]
else
0
,
vm_count
=
int
(
stats
[
"vmcount"
][
0
])
if
"vmcount"
in
stats
and
stats
[
"vmcount"
][
0
]
else
0
,
)
)
update_stats
(
rs
)
update_stats
(
rs
)
...
@@ -180,15 +184,17 @@ def update_stats(stat: ResourceStat):
...
@@ -180,15 +184,17 @@ def update_stats(stat: ResourceStat):
cpu_usage
=
stat
.
cpu_usage
,
cpu_usage
=
stat
.
cpu_usage
,
vm_count
=
stat
.
vm_count
,
vm_count
=
stat
.
vm_count
,
cpu_core
=
stat
.
cpu_core
,
cpu_core
=
stat
.
cpu_core
,
vcpu_num
=
stat
.
vcpu_num
,
)
)
dc
.
save
()
dc
.
save
()
else
:
else
:
dc
=
dc
[
0
]
dc
=
dc
[
0
]
dc
.
mem_max
=
stat
.
mem_max
if
stat
.
mem_max
else
dc
.
mem_max
dc
.
mem_max
=
stat
.
mem_max
if
stat
.
mem_max
is
not
None
else
dc
.
mem_max
dc
.
mem_used
=
stat
.
mem_used
if
stat
.
mem_used
else
dc
.
mem_used
dc
.
mem_used
=
stat
.
mem_used
if
stat
.
mem_used
is
not
None
else
dc
.
mem_used
dc
.
cpu_usage
=
stat
.
cpu_usage
if
stat
.
cpu_usage
else
dc
.
cpu_usage
dc
.
cpu_usage
=
stat
.
cpu_usage
if
stat
.
cpu_usage
is
not
None
else
dc
.
cpu_usage
dc
.
vm_count
=
stat
.
vm_count
if
stat
.
vm_count
else
dc
.
vm_count
dc
.
vm_count
=
stat
.
vm_count
if
stat
.
vm_count
is
not
None
else
dc
.
vm_count
dc
.
cpu_core
=
stat
.
cpu_core
if
stat
.
cpu_core
else
dc
.
cpu_core
dc
.
cpu_core
=
stat
.
cpu_core
if
stat
.
cpu_core
is
not
None
else
dc
.
cpu_core
dc
.
vcpu_num
=
stat
.
vcpu_num
if
stat
.
vcpu_num
is
not
None
else
dc
.
vcpu_num
dc
.
save
()
dc
.
save
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment