make metrics show up gray when prometheus returns no data
This commit is contained in:
parent
0434c4d43b
commit
67120e9461
@ -33,6 +33,8 @@ green = (121/255, 240/255, 50/255)
|
||||
blue = (70/255, 150/255, 255/255)
|
||||
red = (255/255, 50/255, 8/255)
|
||||
|
||||
gray = (128/255, 128/255, 128/255)
|
||||
|
||||
@bp.route("/html/<string:metric>/<string:capsulid>/<string:duration>")
|
||||
@account_required
|
||||
def display_metric(metric, capsulid, duration):
|
||||
@ -113,12 +115,18 @@ 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)
|
||||
series = prometheus_response.json()["data"]["result"]
|
||||
if len(series) == 0:
|
||||
now_timestamp = datetime.timestamp(datetime.now())
|
||||
series = [
|
||||
dict(
|
||||
values=[[now_timestamp - interval_seconds, float(0)],[now_timestamp, float(0)]]
|
||||
)
|
||||
]
|
||||
|
||||
time_series_data = list(map(
|
||||
lambda x: (datetime.fromtimestamp(x[0]), float(x[1])),
|
||||
prometheus_response.json()["data"]["result"][0]["values"]
|
||||
series[0]["values"]
|
||||
))
|
||||
|
||||
plot_bytes = draw_plot_png_bytes(time_series_data, scale=scales[metric], size_x=sizes[size][0], size_y=sizes[size][1])
|
||||
@ -182,6 +190,7 @@ def draw_plot_png_bytes(data, scale, size_x=3, size_y=1):
|
||||
|
||||
max_value = reduce(lambda a, b: a if a > b else b, y, scale)
|
||||
|
||||
if len(data) > 2:
|
||||
average=(sum(y)/len(y))/scale
|
||||
average=average*1.25+0.1
|
||||
|
||||
@ -191,6 +200,8 @@ def draw_plot_png_bytes(data, scale, size_x=3, size_y=1):
|
||||
|
||||
fill_color=color_gradient(average)
|
||||
highlight_color=lerp_rgb_tuples(fill_color, (1,1,1), 0.5)
|
||||
else:
|
||||
bg_color = fill_color = highlight_color = gray
|
||||
|
||||
my_plot.fill_between( x, max_value, color=bg_color, alpha=0.13)
|
||||
my_plot.fill_between( x, y, color=highlight_color, alpha=0.3)
|
||||
|
Loading…
Reference in New Issue
Block a user