def dehydrate_stats(self, bundle):
from chroma_core.models import SimpleHistoStoreTime
from chroma_core.models import SimpleHistoStoreBin
stats = {}
for s in StorageResourceStatistic.objects.filter(storage_resource = bundle.obj):
from django.db import transaction
stat_props = s.storage_resource.get_statistic_properties(s.name)
if isinstance(stat_props, statistics.BytesHistogram):
with transaction.commit_manually():
transaction.commit()
try:
time = SimpleHistoStoreTime.objects.filter(storage_resource_statistic = s).latest('time')
bins = SimpleHistoStoreBin.objects.filter(histo_store_time = time).order_by('bin_idx')
finally:
transaction.commit()
type_name = 'histogram'
# Composite type
data = {
'bin_labels': [u'\u2264%s' % (bin[1:] or '') for bin in stat_props.bins],
'values': [bin.value for bin in bins],
}
else:
type_name = 'timeseries'
# Go get the data from <resource>/metrics/
data = None
label = stat_props.label
if not label:
label = s.name
stat_data = {'name': s.name,
'label': label,
'type': type_name,
'unit_name': stat_props.get_unit_name(),
'data': data}
stats[s.name] = stat_data
return stats
storage_resource.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录