import pandas as pd
import xlwt
import os
workbook = xlwt.Workbook()
name_list = ['V_YDJT_MHXT_DB_01_USED .xls', 'V_YDJT_HRXT_DB_01_USED.xls', 'V_YDJT_DS_DB_01_USED.xls']
files = os.listdir(r'.')
for txt_file in files:
for name in name_list:
if name in txt_file:
#print(txt_file)
df = pd.DataFrame(pd.read_excel(txt_file))
istackList = df[['istack']].values.T.tolist()[:][0]
computeList = df[['compute01']].values.T.tolist()[:][0]
ipList = df[['ip']].values.T.tolist()[:][0]
instanceList = df[['instance-name']].values.T.tolist()[:][0]
# print (instanceList [0] )
# print("all istack")
# print(istackList)
istackList = list(set(istackList))
# print("NO repetition")
# print(istackList)
for name in istackList:
istack = df.loc[df['istack'] == name]
# print('\r\n')
#print(istack)
# data
a = istack["cpu_used"].describe()
print(a)
# plot
b = istack["cpu_used"].hist()
b.plot()
import matplotlib.pyplot as plt
plt.show()
cmean = '%.2f' % (istack["cpu_used"].mean())
cmin = '%.2f' % (istack["cpu_used"].min())
cmax = '%.2f' % (istack["cpu_used"].max())
mmean = '%.1f' % (istack["mem_used"].mean())
mmin = '%.1f' % (istack["mem_used"].min())
mmax = '%.1f' % (istack["mem_used"].max())
dmean = '%.1f' % (istack["disk_used"].mean())
dmin = '%.1f' % (istack["disk_used"].min())
dmax = '%.1f' % (istack["disk_used"].max())
# print(type(dmin)) str
# print("istack %s cmean %s cmin "
# "%s cmax %s mmean %s mmin %s mmax %s dmean %s dmin %s dmax %s "
# ""%(istackList[i],cmean,cmin,cmax,mmean,mmin,mmax,dmean,dmin,dmax))
advisec = "0"
advisem = "0"
advised = "0"
if float(cmin) < 10:
advisec = "Reduce cpu"
# print (advisec)
elif float(cmax) >= 50:
advisec = "Expand cpu"
# print (advisec)
else:
advisec = "No change cpu"
# print (advisec)
if float(mmin) < 10:
advisem = "Reduce mem"
# print (advisem)
elif float(mmax) >= 50:
advisem = "Expand mem"
# print (advisem)
else:
advisem = "No change mem"
# print (advisem)
# disk
if float(dmax) > 50.0:
advised = "Expand disk"
# print (advised)
else:
advised = "No change disk"
# print (advised)
adv = "%s %s %s %s %s " \
" %s %s %s %s %s %s %s %s %s %s %s" \
% (
istackList[0], computeList[0], ipList[0], instanceList[0], cmax, cmin, cmean, mmax, mmin,
mmean,
dmax, dmin, dmean, advisec, advisem, advised)
print(adv)
# writer
st = str(name)
sheet = workbook.add_sheet(st, cell_overwrite_ok=False)
sheet.write(0, 0, adv) # row, column, value
workbook.save(str(name) + "advise.xls")
pandas
最新推荐文章于 2022-04-02 12:51:07 发布