Commit 7b6e956c by Karsa Zoltán István

get stats from remote skeleton

parent b22c95bd
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
from fastapi.responses import ORJSONResponse
from balancer.stats import get_stat_from_dc
from sredis.sredis import (
get_all_datacenter,
get_datacenter_token,
......@@ -10,6 +11,9 @@ from fastapi import HTTPException
import requests
import json
from core.models import ResourcePoolSchema
import logging
logger = logging.getLogger(__name__)
def proxy_datacenters(
......@@ -80,10 +84,6 @@ def create_vm_from_template(
raise HTTPException(status_code=500, detail="Remote server error")
def get_stat_from_dc(datacenter):
pass
def create_rp(username: str, rp: ResourcePoolSchema):
if rp.manual:
id = 0
......
......@@ -38,6 +38,9 @@ requests.packages.urllib3.disable_warnings()
Migrator().run()
app = FastAPI()
reset()
add_datacenter("https://kappa1.fured.cloud.bme.hu")
add_datacenter("https://kappa2.fured.cloud.bme.hu")
add_datacenter("https://kappa3.fured.cloud.bme.hu")
......@@ -46,8 +49,6 @@ create_superpuser(
User(username="admin", email="example@domain.com", password=os.getenv("ADMIN_PASS"))
)
reset()
@app.post("/user/signup", tags=["user"])
async def create_user(user: User = Body(...)):
......
import redis
import requests
from balancer.stats import get_stat_from_dc
from core.models import UserLoginSchema, ResourceStat
from .models import PUser, DataCenterResource, ResourcePool
from passlib.hash import pbkdf2_sha256
......@@ -45,22 +46,24 @@ def get_all_datacenter():
def update_status(datacenter):
status = "OK" if get_status(datacenter_url=datacenter) is True else "Wrong"
if status == "Wrong":
logging.warning(f"{datacenter} is inactive status")
logger.warning(f"{datacenter} is inactive status")
r.hset("datacenter_status", datacenter, status)
def update_datacenter_status():
logging.info("Update datacenters status")
logger.info("Update datacenters status")
all_keys = r.hgetall("datacenters_hash")
for dc in all_keys.values():
update_status(datacenter=dc)
def update_datacenter_stats():
logging.info("Update datacenters stats")
logger.info("Update datacenters stats")
all_keys = r.hgetall("datacenters_hash")
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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment