• python统计ES存储空间占用的代码


    import os
    from os.path import join, getsize
    
    
    def get_dir_size(dir, suffix_filter=None):
       size = 0L
       if not suffix_filter:
           for root, dirs, files in os.walk(dir):
               size += sum([getsize(join(root, name)) for name in files])
       else:
           pos = len(suffix_filter)
           for root, dirs, files in os.walk(dir):
               size += sum([getsize(join(root, name)) for name in files if name[-pos:] == suffix_filter])
       return size
    
    
    if __name__ == "__main__":
        suffix = [".doc", ".pos", ".tim", ".tip", ".dvd", ".dvm", ".fdt", ".fdx", ".fnm", ".nvd", ".nvm"]
        sums = [0]*len(suffix)
        print "total size,", suffix
        all_size = 0.0
        for i in range(0, 20):
            dir_name = r'D:expelasticsearch-2.4.1dataelasticsearch
    odesmetadata-dis-2017.05.17-192.168.10.5-93001\%d' % i
            total_size = get_dir_size(dir_name)
            all_size += total_size
            print total_size, ",",
            for index,f in enumerate(suffix):
                filesize = get_dir_size(dir_name, f)
                print filesize,
                if index != len(suffix)-1:
                    print ",",
                sums[index] += filesize
            print ""
        print "sum:==>"
        print all_size, ",", sums
        print suffix, "==>"
        print "rate:",["{:6.4f}".format(sums[index]/all_size) for index,f in enumerate(suffix)], "other rate:", "{:6.4f}".format((all_size-sum(sums))/all_size)

    结果:

    total size, ['.doc', '.pos', '.tim', '.tip', '.dvd', '.dvm', '.fdt', '.fdx', '.fnm', '.nvd', '.nvm']
    1317898783 , 151402808 , 49137369 , 301883415 , 4172214 , 141468778 , 2638 , 584778163 , 251283 , 14098 , 84785648 , 766
    1322178937 , 151260397 , 49087934 , 301549945 , 4152932 , 141485775 , 2614 , 583980598 , 251572 , 14281 , 90390501 , 786
    1319649899 , 151221470 , 49071207 , 301534617 , 4170120 , 140942980 , 2638 , 583509290 , 251019 , 14372 , 88929787 , 796
    1314658083 , 151146248 , 49063654 , 301531446 , 4160809 , 140569823 , 2638 , 583241932 , 250572 , 14098 , 84674494 , 766
    1320535933 , 151531650 , 49176093 , 302016964 , 4169422 , 141155952 , 2574 , 584516976 , 249055 , 14280 , 87700579 , 786
    1320124857 , 151273971 , 49132333 , 301772358 , 4170596 , 141370180 , 2646 , 583164239 , 251026 , 14372 , 88970738 , 796
    1316604607 , 151108604 , 49028330 , 301445032 , 4157849 , 140884622 , 2646 , 583674391 , 249567 , 14190 , 86036998 , 776
    1318000530 , 151303288 , 49096354 , 301799237 , 4165775 , 141048755 , 2622 , 584203445 , 250668 , 14189 , 86113818 , 776
    1319766874 , 151220609 , 49114923 , 301645769 , 4164351 , 141300148 , 2614 , 583120289 , 249195 , 14372 , 88932205 , 796
    1316689373 , 151233222 , 49121429 , 301457255 , 4162316 , 141250414 , 2614 , 583262641 , 250656 , 14189 , 85932258 , 776
    1318198716 , 151174674 , 49109038 , 301525947 , 4166291 , 140899847 , 2670 , 583598013 , 251472 , 14281 , 87454094 , 786
    1320522076 , 151321339 , 49123177 , 301757750 , 4169815 , 141420824 , 2638 , 583468296 , 252283 , 14372 , 88989183 , 796
    1319417975 , 151437201 , 49178363 , 301895414 , 4172117 , 140741668 , 2598 , 584117457 , 252773 , 14281 , 87603715 , 786
    1317865422 , 151324795 , 49079342 , 301808126 , 4162318 , 141039688 , 2590 , 584047373 , 251114 , 14189 , 86133508 , 776
    1319633778 , 151143225 , 49103608 , 301496485 , 4162216 , 140890300 , 2630 , 583678114 , 252802 , 14372 , 88887627 , 796
    1317628208 , 151325819 , 49158454 , 301771482 , 4164837 , 141049094 , 2622 , 583762862 , 250401 , 14190 , 86126068 , 776
    1318628784 , 151251125 , 49101866 , 301657775 , 4163649 , 140656991 , 2622 , 583999255 , 251506 , 14281 , 87527326 , 786
    1316949748 , 151240013 , 49118487 , 301544994 , 4157729 , 140576588 , 2606 , 583907402 , 251325 , 14189 , 86134036 , 776
    1316521884 , 151169612 , 49090142 , 301601874 , 4157814 , 140947297 , 2670 , 583231827 , 250762 , 14189 , 86053318 , 776
    1319378726 , 151381023 , 49179677 , 301868523 , 4171265 , 140769513 , 2614 , 584110351 , 251400 , 14280 , 87627691 , 786
    sum:==>
    26370853193.0 , [3025471093L, 982271780L, 6033564408L, 83294435L, 2820469237L, 52504L, 11675372914L, 5020451L, 285065L, 1745003592L, 15660L]
    ['.doc', '.pos', '.tim', '.tip', '.dvd', '.dvm', '.fdt', '.fdx', '.fnm', '.nvd', '.nvm'] ==>
    rate: ['0.1147', '0.0372', '0.2288', '0.0032', '0.1070', '0.0000', '0.4427', '0.0002', '0.0000', '0.0662', '0.0000'] other rate: 0.0000

  • 相关阅读:
    132123
    (一)robotframework自动化环境搭建
    python读取xlsx、csv、txt、html文件
    (二)robotframework自动化中遇到的错误及解决思路
    python使用小技巧
    三生零基础大白菜自动重装系统教程
    安装JDK和配置环境变量
    webpack 一套工程代码 管理多个相似项目
    box2dWeb 学习笔记
    简单计时器
  • 原文地址:https://www.cnblogs.com/bonelee/p/6932271.html
Copyright © 2020-2023  润新知