예제 #1
0
    def calc_stats():
        VolMgr.STATS = {
            'date': '',
            'num_users': 0,
            'loopback': {
                'num_files': 0,
                'total_size': 0,
                'sizes': [],
                'min_size': 0,
                'max_size': 0,
                'avg_size': 0,
                'sizes_hist': {
                    'counts': [],
                    'bins': []
                }
            }
        }

        result_set = JBoxUserV2.table().scan(attributes=('user_id', ))
        for user in result_set:
            VolMgr.calc_stat(user['user_id'])

        sizes = VolMgr.STATS['loopback']['sizes']
        VolMgr.STATS['loopback']['num_files'] = len(sizes)
        VolMgr.STATS['loopback']['total_size'] = sum(sizes)
        VolMgr.STATS['loopback']['min_size'] = min(sizes)
        VolMgr.STATS['loopback']['max_size'] = max(sizes)
        VolMgr.STATS['loopback']['avg_size'] = sum(sizes) / len(sizes)

        bin_size = int((VolMgr.STATS['loopback']['max_size'] -
                        VolMgr.STATS['loopback']['min_size']) / 10)
        min_size = VolMgr.STATS['loopback']['min_size']
        bins = []
        for idx in range(0, 10):
            bins.append(min_size + bin_size * idx)
        bins.append(VolMgr.STATS['loopback']['max_size'])
        counts = [0] * 10

        for size in sizes:
            for idx in range(1, 11):
                if size <= bins[idx]:
                    counts[idx - 1] += 1
                    break
        VolMgr.STATS['loopback']['sizes_hist']['counts'] = counts
        VolMgr.STATS['loopback']['sizes_hist']['bins'] = bins
        del VolMgr.STATS['loopback']['sizes']
        VolMgr.STATS['date'] = datetime.datetime.now(pytz.utc).isoformat()
예제 #2
0
    def calc_stats():
        VolMgr.STATS = {
            'date': '',
            'num_users': 0,
            'loopback': {
                'num_files': 0,
                'total_size': 0,
                'sizes': [],
                'min_size': 0,
                'max_size': 0,
                'avg_size': 0,
                'sizes_hist': {
                    'counts': [],
                    'bins': []
                }
            }
        }

        result_set = JBoxUserV2.table().scan(attributes=('user_id',))
        for user in result_set:
            VolMgr.calc_stat(user['user_id'])

        sizes = VolMgr.STATS['loopback']['sizes']
        VolMgr.STATS['loopback']['num_files'] = len(sizes)
        VolMgr.STATS['loopback']['total_size'] = sum(sizes)
        VolMgr.STATS['loopback']['min_size'] = min(sizes)
        VolMgr.STATS['loopback']['max_size'] = max(sizes)
        VolMgr.STATS['loopback']['avg_size'] = sum(sizes) / len(sizes)

        bin_size = int((VolMgr.STATS['loopback']['max_size'] - VolMgr.STATS['loopback']['min_size']) / 10)
        min_size = VolMgr.STATS['loopback']['min_size']
        bins = []
        for idx in range(0, 10):
            bins.append(min_size + bin_size*idx)
        bins.append(VolMgr.STATS['loopback']['max_size'])
        counts = [0] * 10

        for size in sizes:
            for idx in range(1, 11):
                if size <= bins[idx]:
                    counts[idx-1] += 1
                    break
        VolMgr.STATS['loopback']['sizes_hist']['counts'] = counts
        VolMgr.STATS['loopback']['sizes_hist']['bins'] = bins
        del VolMgr.STATS['loopback']['sizes']
        VolMgr.STATS['date'] = datetime.datetime.now(pytz.utc).isoformat()