comments and error handling on metrics
This commit is contained in:
parent
17159ddbf3
commit
df156181b4
@ -81,6 +81,7 @@ def get_plot_bytes(metric, capsulid, duration, size):
|
||||
if interval_seconds < 30:
|
||||
interval_seconds = 30
|
||||
|
||||
# Prometheus queries to pull metrics for VMs
|
||||
metric_queries = dict(
|
||||
cpu=f"irate(libvirtd_domain_info_cpu_time_seconds_total{{domain='{capsulid}'}}[30s])",
|
||||
memory=f"libvirtd_domain_info_memory_usage_bytes{{domain='{capsulid}'}}",
|
||||
@ -89,12 +90,14 @@ def get_plot_bytes(metric, capsulid, duration, size):
|
||||
disk=f"rate(libvirtd_domain_block_stats_read_bytes_total{{domain='{capsulid}'}}[{interval_seconds}s])%2Brate(libvirtd_domain_block_stats_write_bytes_total{{domain='{capsulid}'}}[{interval_seconds}s])",
|
||||
)
|
||||
|
||||
# These represent the top of the graph for graphs that are designed to be viewed at a glance.
|
||||
# they are also used to colorize the graph at any size.
|
||||
scales = dict(
|
||||
cpu=vm["vcpus"],
|
||||
memory=vm["memory_mb"]*1024*1024,
|
||||
network_in=1024*1024*2,
|
||||
network_out=1024*200,
|
||||
disk=1024*1024*2,
|
||||
disk=1024*1024*4,
|
||||
)
|
||||
|
||||
if metric not in metric_queries:
|
||||
@ -110,19 +113,20 @@ def get_plot_bytes(metric, capsulid, duration, size):
|
||||
if prometheus_response.status_code >= 300:
|
||||
return (502, None)
|
||||
|
||||
|
||||
if len(prometheus_response.json()["data"]["result"]) == 0:
|
||||
return (404, None)
|
||||
|
||||
time_series_data = list(map(
|
||||
lambda x: (datetime.fromtimestamp(x[0]), float(x[1])),
|
||||
prometheus_response.json()["data"]["result"][0]["values"]
|
||||
))
|
||||
|
||||
plot_bytes = draw_plot_bytes(time_series_data, scale=scales[metric], size_x=sizes[size][0], size_y=sizes[size][1])
|
||||
plot_bytes = draw_plot_png_bytes(time_series_data, scale=scales[metric], size_x=sizes[size][0], size_y=sizes[size][1])
|
||||
|
||||
return (200, plot_bytes)
|
||||
|
||||
|
||||
def draw_plot_bytes(data, scale, size_x=3, size_y=1):
|
||||
def draw_plot_png_bytes(data, scale, size_x=3, size_y=1):
|
||||
|
||||
pyplot.style.use("seaborn-dark")
|
||||
fig, my_plot = pyplot.subplots(figsize=(size_x, size_y))
|
||||
@ -156,7 +160,7 @@ def draw_plot_bytes(data, scale, size_x=3, size_y=1):
|
||||
hours = minutes/float(60)
|
||||
days = hours/float(24)
|
||||
|
||||
day_locator = mdates.WeekdayLocator()
|
||||
week_locator = mdates.WeekdayLocator()
|
||||
minute_locator = mdates.MinuteLocator()
|
||||
ten_minute_locator = mdates.MinuteLocator(interval=10)
|
||||
hour_locator = mdates.HourLocator(interval=6)
|
||||
@ -173,7 +177,7 @@ def draw_plot_bytes(data, scale, size_x=3, size_y=1):
|
||||
my_plot.xaxis.set_major_locator(hour_locator)
|
||||
my_plot.xaxis.set_major_formatter(hour_minute_formatter)
|
||||
else:
|
||||
my_plot.xaxis.set_major_locator(day_locator)
|
||||
my_plot.xaxis.set_major_locator(week_locator)
|
||||
my_plot.xaxis.set_major_formatter(day_formatter)
|
||||
|
||||
max_value = reduce(lambda a, b: a if a > b else b, y, scale)
|
||||
|
Loading…
Reference in New Issue
Block a user