def get_bucket_usage(bucket): name = "_bucket_usage_%s" % bucket raw_result = hgetall(name) usage = {"requests": [], "bandwidth": [], "file_size": "", "docs_count": 0} if not bucket: return usage usage["file_size"] = bytes2human(get_bucket_file_size(bucket)) usage["docs_count"] = get_records_count(bucket) usage["posts_count"] = count_records_by_type_for_bucket(bucket, "post") usage["files_count"] = count_records_by_type_for_bucket(bucket, "file") usage["images_count"] = count_records_by_type_for_bucket(bucket, "image") usage["folders_count"] = count_records_by_type_for_bucket(bucket, "folder") raw_result.reverse() for k, v in raw_result: v = to_int(v, default_if_fail=0) if not v: continue if k.endswith("r"): # requests month = k[:-1] usage["requests"].append(dict( month=month, value=v, )) elif k.endswith("b"): # bandwidth month = k[:-1] usage["bandwidth"].append(dict( month=month, value=bytes2human(v), )) return usage
def get_bucket_usage(bucket, for_human=False): try: usage = int(hget('_bucket_usage', bucket)) except: usage = 0 if for_human: usage = bytes2human(usage) return usage
def get_all_buckets_bandwidth(score_start=0, per_page=1000): result = [] raw_result = zrscan("_bucket_usage_bandwidth", score_start=score_start or "", limit=per_page) for bucket, value in raw_result: value = to_int(value, default_if_fail=0) result.append(dict(bucket=bucket, value=bytes2human(value))) return result
def get_bucket_status(bucket): status_info = {} size = get_bucket_size(bucket) status_info['size'] = size last_updated_at = zget('buckets', bucket) if last_updated_at: status_info['date'] = db_timestamp_to_date_string(last_updated_at) max_record_id = hget('_bucket_max_id', bucket) delta_record_id = hget('_bucket_delta_id', bucket) status_info['max_record_id'] = max_record_id status_info['delta_record_id'] = delta_record_id status_info['max_record_date'] = record_id_to_date_string(max_record_id) status_info['delta_record_date'] = record_id_to_date_string(delta_record_id) try: usage = int(hget('_bucket_usage', bucket) or 0) except: usage = 0 status_info['usage'] = usage status_info['usage_for_human'] = bytes2human(usage) if usage and size: usage_per_record = round(usage/float(size), 2) status_info['usage_per_record'] = usage_per_record status_info['usage_per_record_for_human'] = bytes2human(usage_per_record) return status_info
def get_db_system_status(): if not db_client: return {} raw_db_info = db_client.info() db_size = db_client.dbsize() db_size_for_human = bytes2human(db_size) leveldb_status = raw_db_info.get('leveldb.stats') or '' leveldb_status = leveldb_status.split('\n') status_info = { 'size': db_size_for_human, 'version': raw_db_info.get('version'), 'calls': raw_db_info.get('total_calls'), 'db_status': leveldb_status, } return status_info