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
7b6e956c
authored
Sep 29, 2023
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get stats from remote skeleton
parent
b22c95bd
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
10 deletions
+52
-10
balancer/stats.py
+38
-0
balancer/util.py
+4
-4
main.py
+3
-2
sredis/sredis.py
+7
-4
No files found.
balancer/stats.py
0 → 100644
View file @
7b6e956c
import
requests
import
json
import
logging
logger
=
logging
.
getLogger
(
__name__
)
PREFIX
=
"RBstat?"
MEM_ALLOCATED_TARGET
=
"target=circle.*.memory.allocated&format=json&time=-1min"
MEM_USAGE_TARGET
=
"circle.*.memory.usage&format=json&time=-1min"
VMCOUNT_TARGET
=
"target=circle.*.vmcount&format=json&time=-1min"
CPU_PERCENT_TARGET
=
"target=circle.*.cpu.percent&format=json&time=-1min"
STAT_TARGETS
=
{
"mem_allocated"
:
MEM_ALLOCATED_TARGET
,
"mem_usage"
:
MEM_USAGE_TARGET
,
"vmcount"
:
VMCOUNT_TARGET
,
"cpu_percent"
:
CPU_PERCENT_TARGET
,
}
def
get_stat_from_dc
(
datacenter
):
stat
=
{}
for
key
,
target
in
STAT_TARGETS
.
items
():
url
:
str
=
f
"{datacenter}/{PREFIX}{target}"
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
:
data
=
json
.
loads
(
req
.
content
)
stat
[
key
]
=
[
i
[
"datapoints"
][
0
][
0
]
for
i
in
data
]
return
stat
balancer/util.py
View file @
7b6e956c
from
fastapi.responses
import
ORJSONResponse
from
fastapi.responses
import
ORJSONResponse
from
balancer.stats
import
get_stat_from_dc
from
sredis.sredis
import
(
from
sredis.sredis
import
(
get_all_datacenter
,
get_all_datacenter
,
get_datacenter_token
,
get_datacenter_token
,
...
@@ -10,6 +11,9 @@ from fastapi import HTTPException
...
@@ -10,6 +11,9 @@ from fastapi import HTTPException
import
requests
import
requests
import
json
import
json
from
core.models
import
ResourcePoolSchema
from
core.models
import
ResourcePoolSchema
import
logging
logger
=
logging
.
getLogger
(
__name__
)
def
proxy_datacenters
(
def
proxy_datacenters
(
...
@@ -80,10 +84,6 @@ def create_vm_from_template(
...
@@ -80,10 +84,6 @@ def create_vm_from_template(
raise
HTTPException
(
status_code
=
500
,
detail
=
"Remote server error"
)
raise
HTTPException
(
status_code
=
500
,
detail
=
"Remote server error"
)
def
get_stat_from_dc
(
datacenter
):
pass
def
create_rp
(
username
:
str
,
rp
:
ResourcePoolSchema
):
def
create_rp
(
username
:
str
,
rp
:
ResourcePoolSchema
):
if
rp
.
manual
:
if
rp
.
manual
:
id
=
0
id
=
0
...
...
main.py
View file @
7b6e956c
...
@@ -38,6 +38,9 @@ requests.packages.urllib3.disable_warnings()
...
@@ -38,6 +38,9 @@ requests.packages.urllib3.disable_warnings()
Migrator
()
.
run
()
Migrator
()
.
run
()
app
=
FastAPI
()
app
=
FastAPI
()
reset
()
add_datacenter
(
"https://kappa1.fured.cloud.bme.hu"
)
add_datacenter
(
"https://kappa1.fured.cloud.bme.hu"
)
add_datacenter
(
"https://kappa2.fured.cloud.bme.hu"
)
add_datacenter
(
"https://kappa2.fured.cloud.bme.hu"
)
add_datacenter
(
"https://kappa3.fured.cloud.bme.hu"
)
add_datacenter
(
"https://kappa3.fured.cloud.bme.hu"
)
...
@@ -46,8 +49,6 @@ create_superpuser(
...
@@ -46,8 +49,6 @@ create_superpuser(
User
(
username
=
"admin"
,
email
=
"example@domain.com"
,
password
=
os
.
getenv
(
"ADMIN_PASS"
))
User
(
username
=
"admin"
,
email
=
"example@domain.com"
,
password
=
os
.
getenv
(
"ADMIN_PASS"
))
)
)
reset
()
@app.post
(
"/user/signup"
,
tags
=
[
"user"
])
@app.post
(
"/user/signup"
,
tags
=
[
"user"
])
async
def
create_user
(
user
:
User
=
Body
(
...
)):
async
def
create_user
(
user
:
User
=
Body
(
...
)):
...
...
sredis/sredis.py
View file @
7b6e956c
import
redis
import
redis
import
requests
import
requests
from
balancer.stats
import
get_stat_from_dc
from
core.models
import
UserLoginSchema
,
ResourceStat
from
core.models
import
UserLoginSchema
,
ResourceStat
from
.models
import
PUser
,
DataCenterResource
,
ResourcePool
from
.models
import
PUser
,
DataCenterResource
,
ResourcePool
from
passlib.hash
import
pbkdf2_sha256
from
passlib.hash
import
pbkdf2_sha256
...
@@ -45,22 +46,24 @@ def get_all_datacenter():
...
@@ -45,22 +46,24 @@ def get_all_datacenter():
def
update_status
(
datacenter
):
def
update_status
(
datacenter
):
status
=
"OK"
if
get_status
(
datacenter_url
=
datacenter
)
is
True
else
"Wrong"
status
=
"OK"
if
get_status
(
datacenter_url
=
datacenter
)
is
True
else
"Wrong"
if
status
==
"Wrong"
:
if
status
==
"Wrong"
:
logg
ing
.
warning
(
f
"{datacenter} is inactive status"
)
logg
er
.
warning
(
f
"{datacenter} is inactive status"
)
r
.
hset
(
"datacenter_status"
,
datacenter
,
status
)
r
.
hset
(
"datacenter_status"
,
datacenter
,
status
)
def
update_datacenter_status
():
def
update_datacenter_status
():
logg
ing
.
info
(
"Update datacenters status"
)
logg
er
.
info
(
"Update datacenters status"
)
all_keys
=
r
.
hgetall
(
"datacenters_hash"
)
all_keys
=
r
.
hgetall
(
"datacenters_hash"
)
for
dc
in
all_keys
.
values
():
for
dc
in
all_keys
.
values
():
update_status
(
datacenter
=
dc
)
update_status
(
datacenter
=
dc
)
def
update_datacenter_stats
():
def
update_datacenter_stats
():
logg
ing
.
info
(
"Update datacenters stats"
)
logg
er
.
info
(
"Update datacenters stats"
)
all_keys
=
r
.
hgetall
(
"datacenters_hash"
)
all_keys
=
r
.
hgetall
(
"datacenters_hash"
)
for
dc
in
all_keys
.
values
():
for
dc
in
all_keys
.
values
():
logging
.
info
(
"Get stats from"
,
dc
)
logger
.
info
(
f
"Get stats from {dc}"
)
get_stat_from_dc
(
dc
)
# update_stats(stats)
def
add_datacenter
(
datacenter
:
str
):
def
add_datacenter
(
datacenter
:
str
):
...
...
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