pandas

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")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值