'Return an iterable of models.Statistics instance.
Items are containing meter statistics described by the query
parameters. The filter must have a meter value set.'

def get_meter_statistics(self, sample_filter, period=None, groupby=None, aggregate=None):

    if aggregate:
        for a in aggregate:
            if (a.func not in self.AGGREGATES):
                msg = (_('Invalid    aggregation    function:    %s') % a.func)
                raise storage.StorageBadAggregate(msg)
    if (groupby and (set(groupby) - set(['user_id', 'project_id', 'resource_id', 'source', 'resource_metadata.instance_type']))):
        raise ceilometer.NotImplementedError('Unable    to    group    by    these    fields')
    q = pymongo_utils.make_query_from_filter(sample_filter)
    group_stage = {}
    project_stage = {'unit': '$_id.unit', 'name': '$_id.name', 'first_timestamp': '$first_timestamp', 'last_timestamp': '$last_timestamp', 'period_start': '$_id.period_start'}
    group_stage.update({'first_timestamp': {'$min': '$timestamp'}, 'last_timestamp': {'$max': '$timestamp'}})
    unique_group_field = {'name': '$counter_name', 'unit': '$counter_unit'}
    if sample_filter.start_timestamp:
        first_timestamp = sample_filter.start_timestamp
    else:
        first_timestamp_cursor = self.db.meter.find(limit=1, sort=[('timestamp', pymongo.ASCENDING)])
        if first_timestamp_cursor.count():
            first_timestamp = first_timestamp_cursor[0]['timestamp']
        else:
            first_timestamp = utils.EPOCH_TIME
    if period:
        period_dict = self._make_period_dict(period, first_timestamp)
        unique_group_field.update(period_dict)
    if groupby:
        unique_group_field.update(dict(((field.replace('.', '/'), ('$%s' % field)) for field in groupby)))
    group_stage.update({'_id': unique_group_field})
    self._compile_aggregate_stages(aggregate, group_stage, project_stage)
    aggregation_query = [{'$match': q}, {'$sort': {'timestamp': 1}}, {'$group': group_stage}, {'$sort': {'_id.period_start': 1}}, {'$project': project_stage}]
    results = self.db.meter.aggregate(aggregation_query, **self._make_aggregation_params())
    return [self._stats_result_to_model(point, groupby, aggregate, period, first_timestamp) for point in self._get_results(results)]
