Commit db0fd796 by Karsa Zoltán István

retry for get stats from dc

parent 7b6e956c
import requests
import json
import logging
import time
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"
MEM_USAGE_TARGET = "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"
......@@ -18,7 +19,7 @@ STAT_TARGETS = {
}
def get_stat_from_dc(datacenter):
def get_stat_from_dc(datacenter, retry = False):
stat = {}
for key, target in STAT_TARGETS.items():
url: str = f"{datacenter}/{PREFIX}{target}"
......@@ -35,4 +36,14 @@ def get_stat_from_dc(datacenter):
data = json.loads(req.content)
stat[key] = [i["datapoints"][0][0] for i in data]
if retry and stat[key][0] is None:
time.sleep(1)
req = requests.request(
method="GET",
url=url,
verify=False,
)
data = json.loads(req.content)
stat[key] = [i["datapoints"][0][0] for i in data]
return stat
......@@ -62,7 +62,7 @@ def update_datacenter_stats():
all_keys = r.hgetall("datacenters_hash")
for dc in all_keys.values():
logger.info(f"Get stats from {dc}")
get_stat_from_dc(dc)
get_stat_from_dc(dc, retry=True)
# update_stats(stats)
......
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