forked from 3wordchant/capsul-flask
fix segfault in draw_plot_png_bytes
This commit is contained in:
parent
4833c6250b
commit
3fdd78df2e
@ -3,8 +3,9 @@ import matplotlib.pyplot as pyplot
|
||||
import matplotlib.dates as mdates
|
||||
from functools import reduce
|
||||
import requests
|
||||
#import json
|
||||
import json
|
||||
from datetime import datetime
|
||||
from threading import Lock
|
||||
from io import BytesIO
|
||||
from flask import Blueprint
|
||||
from flask import current_app
|
||||
@ -15,6 +16,7 @@ from werkzeug.exceptions import abort
|
||||
from capsulflask.db import get_model
|
||||
from capsulflask.auth import account_required
|
||||
|
||||
mutex = Lock()
|
||||
bp = Blueprint("metrics", __name__, url_prefix="/metrics")
|
||||
|
||||
durations = dict(
|
||||
@ -116,6 +118,7 @@ def get_plot_bytes(metric, capsulid, duration, size):
|
||||
return (502, None)
|
||||
|
||||
series = prometheus_response.json()["data"]["result"]
|
||||
|
||||
if len(series) == 0:
|
||||
now_timestamp = datetime.timestamp(datetime.now())
|
||||
series = [
|
||||
@ -129,13 +132,19 @@ def get_plot_bytes(metric, capsulid, duration, size):
|
||||
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])
|
||||
mutex.acquire()
|
||||
try:
|
||||
plot_bytes = draw_plot_png_bytes(time_series_data, scale=scales[metric], size_x=sizes[size][0], size_y=sizes[size][1])
|
||||
finally:
|
||||
mutex.release()
|
||||
|
||||
return (200, plot_bytes)
|
||||
|
||||
|
||||
def draw_plot_png_bytes(data, scale, size_x=3, size_y=1):
|
||||
|
||||
#current_app.logger.info(json.dumps(data, indent=4, default=str))
|
||||
|
||||
pyplot.style.use("seaborn-dark")
|
||||
fig, my_plot = pyplot.subplots(figsize=(size_x, size_y))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user