import io,threading import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import seaborn as sns import numpy as np _lock=threading.Lock() def heatmap(rows): with _lock: fig,ax=plt.subplots(figsize=(9,max(3,len(rows)*.35+1.5))) values=np.array([[r['cpu'],r['ram'],r['disk']] for r in rows],dtype=float) sns.heatmap(values,annot=True,fmt='.1f',vmin=0,vmax=100,cmap='YlGnBu',xticklabels=['CPU %','RAM %','Disk %'],yticklabels=[r['server__name'] for r in rows],ax=ax,cbar_kws={'label':'Auslastung (%)'}) ax.set_title('dilib Operations ยท Mittlere Ressourcenauslastung',pad=18) fig.tight_layout(); b=io.BytesIO();fig.savefig(b,format='png',dpi=140);plt.close(fig);return b.getvalue()