Try to get rid of the "events" & "raw events" naming in the code.
Rather use the term "samples" as having both is confusing. Note: this does *not* change the API, just the terminology in the code. bug 1104492 Signed-off-by: Angus Salkeld <asalkeld@redhat.com> Change-Id: If8cf89db60b52815db8e0acbf466400d0e9238c6
This commit is contained in:
@@ -322,7 +322,7 @@ class Statistics(wtypes.Base):
|
|||||||
# If we got valid timestamps back, compute a duration in minutes.
|
# If we got valid timestamps back, compute a duration in minutes.
|
||||||
#
|
#
|
||||||
# If the min > max after clamping then we know the
|
# If the min > max after clamping then we know the
|
||||||
# timestamps on the events fell outside of the time
|
# timestamps on the samples fell outside of the time
|
||||||
# range we care about for the query, so treat them as
|
# range we care about for the query, so treat them as
|
||||||
# "invalid."
|
# "invalid."
|
||||||
#
|
#
|
||||||
@@ -365,7 +365,7 @@ class MeterController(rest.RestController):
|
|||||||
|
|
||||||
@wsme_pecan.wsexpose([Sample], [Query])
|
@wsme_pecan.wsexpose([Sample], [Query])
|
||||||
def get_all(self, q=[]):
|
def get_all(self, q=[]):
|
||||||
"""Return sample data for the meter.
|
"""Return samples for the meter.
|
||||||
|
|
||||||
:param q: Filter rules for the data to be returned.
|
:param q: Filter rules for the data to be returned.
|
||||||
"""
|
"""
|
||||||
@@ -373,12 +373,12 @@ class MeterController(rest.RestController):
|
|||||||
kwargs['meter'] = self._id
|
kwargs['meter'] = self._id
|
||||||
f = storage.EventFilter(**kwargs)
|
f = storage.EventFilter(**kwargs)
|
||||||
return [Sample(**e)
|
return [Sample(**e)
|
||||||
for e in pecan.request.storage_conn.get_raw_events(f)
|
for e in pecan.request.storage_conn.get_samples(f)
|
||||||
]
|
]
|
||||||
|
|
||||||
@wsme_pecan.wsexpose([Statistics], [Query], int)
|
@wsme_pecan.wsexpose([Statistics], [Query], int)
|
||||||
def statistics(self, q=[], period=None):
|
def statistics(self, q=[], period=None):
|
||||||
"""Computes the statistics of the meter events in the time range given.
|
"""Computes the statistics of the samples in the time range given.
|
||||||
|
|
||||||
:param q: Filter rules for the data to be returned.
|
:param q: Filter rules for the data to be returned.
|
||||||
:param period: Returned result will be an array of statistics for a
|
:param period: Returned result will be an array of statistics for a
|
||||||
|
|||||||
@@ -55,10 +55,10 @@
|
|||||||
# [x] /sources/<source>/meters -- list of meters reporting for parent obj
|
# [x] /sources/<source>/meters -- list of meters reporting for parent obj
|
||||||
# [x] /users/<user>/meters -- list of meters reporting for parent obj
|
# [x] /users/<user>/meters -- list of meters reporting for parent obj
|
||||||
#
|
#
|
||||||
# [x] /projects/<project>/meters/<meter> -- events
|
# [x] /projects/<project>/meters/<meter> -- samples
|
||||||
# [x] /resources/<resource>/meters/<meter> -- events
|
# [x] /resources/<resource>/meters/<meter> -- samples
|
||||||
# [x] /sources/<source>/meters/<meter> -- events
|
# [x] /sources/<source>/meters/<meter> -- samples
|
||||||
# [x] /users/<user>/meters/<meter> -- events
|
# [x] /users/<user>/meters/<meter> -- samples
|
||||||
#
|
#
|
||||||
# [ ] /projects/<project>/meters/<meter>/duration -- total time for selected
|
# [ ] /projects/<project>/meters/<meter>/duration -- total time for selected
|
||||||
# meter
|
# meter
|
||||||
@@ -380,15 +380,19 @@ def list_projects_by_source(source):
|
|||||||
return _list_projects(source=source)
|
return _list_projects(source=source)
|
||||||
|
|
||||||
|
|
||||||
## APIs for working with events.
|
## APIs for working with samples.
|
||||||
|
|
||||||
|
|
||||||
def _list_events(meter,
|
def _list_samples(meter,
|
||||||
project=None,
|
project=None,
|
||||||
resource=None,
|
resource=None,
|
||||||
source=None,
|
source=None,
|
||||||
user=None):
|
user=None):
|
||||||
"""Return a list of raw metering events.
|
"""Return a list of raw samples.
|
||||||
|
|
||||||
|
Note: the API talks about "events" these are equivelent to samples.
|
||||||
|
but we still need to return the samples within the "events" dict
|
||||||
|
to maintain API compatibilty.
|
||||||
"""
|
"""
|
||||||
q_ts = _get_query_timestamps(flask.request.args)
|
q_ts = _get_query_timestamps(flask.request.args)
|
||||||
f = storage.EventFilter(
|
f = storage.EventFilter(
|
||||||
@@ -401,7 +405,7 @@ def _list_events(meter,
|
|||||||
end=q_ts['end_timestamp'],
|
end=q_ts['end_timestamp'],
|
||||||
metaquery=_get_metaquery(flask.request.args),
|
metaquery=_get_metaquery(flask.request.args),
|
||||||
)
|
)
|
||||||
events = list(flask.request.storage_conn.get_raw_events(f))
|
events = list(flask.request.storage_conn.get_samples(f))
|
||||||
jsonified = flask.jsonify(events=events)
|
jsonified = flask.jsonify(events=events)
|
||||||
if request_wants_html():
|
if request_wants_html():
|
||||||
return flask.templating.render_template('list_event.html',
|
return flask.templating.render_template('list_event.html',
|
||||||
@@ -415,38 +419,38 @@ def _list_events(meter,
|
|||||||
|
|
||||||
|
|
||||||
@blueprint.route('/projects/<project>/meters/<meter>')
|
@blueprint.route('/projects/<project>/meters/<meter>')
|
||||||
def list_events_by_project(project, meter):
|
def list_samples_by_project(project, meter):
|
||||||
"""Return a list of raw metering events for the project.
|
"""Return a list of raw samples for the project.
|
||||||
|
|
||||||
:param project: The ID of the project.
|
:param project: The ID of the project.
|
||||||
:param meter: The name of the meter.
|
:param meter: The name of the meter.
|
||||||
:param start_timestamp: Limits events by timestamp >= this value.
|
:param start_timestamp: Limits samples by timestamp >= this value.
|
||||||
(optional)
|
(optional)
|
||||||
:type start_timestamp: ISO date in UTC
|
:type start_timestamp: ISO date in UTC
|
||||||
:param end_timestamp: Limits events by timestamp < this value.
|
:param end_timestamp: Limits samples by timestamp < this value.
|
||||||
(optional)
|
(optional)
|
||||||
:type end_timestamp: ISO date in UTC
|
:type end_timestamp: ISO date in UTC
|
||||||
"""
|
"""
|
||||||
check_authorized_project(project)
|
check_authorized_project(project)
|
||||||
return _list_events(project=project,
|
return _list_samples(project=project,
|
||||||
meter=meter,
|
meter=meter,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/resources/<resource>/meters/<meter>')
|
@blueprint.route('/resources/<resource>/meters/<meter>')
|
||||||
def list_events_by_resource(resource, meter):
|
def list_samples_by_resource(resource, meter):
|
||||||
"""Return a list of raw metering events for the resource.
|
"""Return a list of raw samples for the resource.
|
||||||
|
|
||||||
:param resource: The ID of the resource.
|
:param resource: The ID of the resource.
|
||||||
:param meter: The name of the meter.
|
:param meter: The name of the meter.
|
||||||
:param start_timestamp: Limits events by timestamp >= this value.
|
:param start_timestamp: Limits samples by timestamp >= this value.
|
||||||
(optional)
|
(optional)
|
||||||
:type start_timestamp: ISO date in UTC
|
:type start_timestamp: ISO date in UTC
|
||||||
:param end_timestamp: Limits events by timestamp < this value.
|
:param end_timestamp: Limits samples by timestamp < this value.
|
||||||
(optional)
|
(optional)
|
||||||
:type end_timestamp: ISO date in UTC
|
:type end_timestamp: ISO date in UTC
|
||||||
"""
|
"""
|
||||||
return _list_events(
|
return _list_samples(
|
||||||
resource=resource,
|
resource=resource,
|
||||||
meter=meter,
|
meter=meter,
|
||||||
project=acl.get_limited_to_project(flask.request.headers),
|
project=acl.get_limited_to_project(flask.request.headers),
|
||||||
@@ -454,19 +458,19 @@ def list_events_by_resource(resource, meter):
|
|||||||
|
|
||||||
|
|
||||||
@blueprint.route('/sources/<source>/meters/<meter>')
|
@blueprint.route('/sources/<source>/meters/<meter>')
|
||||||
def list_events_by_source(source, meter):
|
def list_samples_by_source(source, meter):
|
||||||
"""Return a list of raw metering events for the source.
|
"""Return a list of raw samples for the source.
|
||||||
|
|
||||||
:param source: The ID of the reporting source.
|
:param source: The ID of the reporting source.
|
||||||
:param meter: The name of the meter.
|
:param meter: The name of the meter.
|
||||||
:param start_timestamp: Limits events by timestamp >= this value.
|
:param start_timestamp: Limits samples by timestamp >= this value.
|
||||||
(optional)
|
(optional)
|
||||||
:type start_timestamp: ISO date in UTC
|
:type start_timestamp: ISO date in UTC
|
||||||
:param end_timestamp: Limits events by timestamp < this value.
|
:param end_timestamp: Limits samples by timestamp < this value.
|
||||||
(optional)
|
(optional)
|
||||||
:type end_timestamp: ISO date in UTC
|
:type end_timestamp: ISO date in UTC
|
||||||
"""
|
"""
|
||||||
return _list_events(
|
return _list_samples(
|
||||||
source=source,
|
source=source,
|
||||||
meter=meter,
|
meter=meter,
|
||||||
project=acl.get_limited_to_project(flask.request.headers),
|
project=acl.get_limited_to_project(flask.request.headers),
|
||||||
@@ -474,19 +478,19 @@ def list_events_by_source(source, meter):
|
|||||||
|
|
||||||
|
|
||||||
@blueprint.route('/users/<user>/meters/<meter>')
|
@blueprint.route('/users/<user>/meters/<meter>')
|
||||||
def list_events_by_user(user, meter):
|
def list_samples_by_user(user, meter):
|
||||||
"""Return a list of raw metering events for the user.
|
"""Return a list of raw samples for the user.
|
||||||
|
|
||||||
:param user: The ID of the user.
|
:param user: The ID of the user.
|
||||||
:param meter: The name of the meter.
|
:param meter: The name of the meter.
|
||||||
:param start_timestamp: Limits events by timestamp >= this value.
|
:param start_timestamp: Limits samples by timestamp >= this value.
|
||||||
(optional)
|
(optional)
|
||||||
:type start_timestamp: ISO date in UTC
|
:type start_timestamp: ISO date in UTC
|
||||||
:param end_timestamp: Limits events by timestamp < this value.
|
:param end_timestamp: Limits samples by timestamp < this value.
|
||||||
(optional)
|
(optional)
|
||||||
:type end_timestamp: ISO date in UTC
|
:type end_timestamp: ISO date in UTC
|
||||||
"""
|
"""
|
||||||
return _list_events(
|
return _list_samples(
|
||||||
user=user,
|
user=user,
|
||||||
meter=meter,
|
meter=meter,
|
||||||
project=acl.get_limited_to_project(flask.request.headers),
|
project=acl.get_limited_to_project(flask.request.headers),
|
||||||
@@ -571,7 +575,7 @@ def compute_duration_by_resource(resource, meter):
|
|||||||
# If we got valid timestamps back, compute a duration in minutes.
|
# If we got valid timestamps back, compute a duration in minutes.
|
||||||
#
|
#
|
||||||
# If the min > max after clamping then we know the
|
# If the min > max after clamping then we know the
|
||||||
# timestamps on the events fell outside of the time
|
# timestamps on the samples fell outside of the time
|
||||||
# range we care about for the query, so treat them as
|
# range we care about for the query, so treat them as
|
||||||
# "invalid."
|
# "invalid."
|
||||||
#
|
#
|
||||||
@@ -624,7 +628,7 @@ def compute_max_resource_volume(resource, meter):
|
|||||||
|
|
||||||
@blueprint.route('/resources/<resource>/meters/<meter>/volume/sum')
|
@blueprint.route('/resources/<resource>/meters/<meter>/volume/sum')
|
||||||
def compute_resource_volume_sum(resource, meter):
|
def compute_resource_volume_sum(resource, meter):
|
||||||
"""Return the total volume for a meter.
|
"""Return the sum of samples for a meter.
|
||||||
|
|
||||||
:param resource: The ID of the resource.
|
:param resource: The ID of the resource.
|
||||||
:param meter: The name of the meter.
|
:param meter: The name of the meter.
|
||||||
|
|||||||
@@ -120,14 +120,14 @@ class Connection(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_raw_events(self, event_filter):
|
def get_samples(self, event_filter):
|
||||||
"""Return an iterable of raw event data as created by
|
"""Return an iterable of samples as created by
|
||||||
:func:`ceilometer.meter.meter_message_from_counter`.
|
:func:`ceilometer.meter.meter_message_from_counter`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_volume_sum(self, event_filter):
|
def get_volume_sum(self, event_filter):
|
||||||
"""Return the sum of the volume field for the events
|
"""Return the sum of the volume field for the samples
|
||||||
described by the query parameters.
|
described by the query parameters.
|
||||||
|
|
||||||
The filter must have a meter value set.
|
The filter must have a meter value set.
|
||||||
@@ -139,7 +139,7 @@ class Connection(object):
|
|||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_volume_max(self, event_filter):
|
def get_volume_max(self, event_filter):
|
||||||
"""Return the maximum of the volume field for the events
|
"""Return the maximum of the volume field for the samples
|
||||||
described by the query parameters.
|
described by the query parameters.
|
||||||
|
|
||||||
The filter must have a meter value set.
|
The filter must have a meter value set.
|
||||||
@@ -151,8 +151,8 @@ class Connection(object):
|
|||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_event_interval(self, event_filter):
|
def get_event_interval(self, event_filter):
|
||||||
"""Return the min and max timestamps from events,
|
"""Return the min and max timestamps from samples,
|
||||||
using the event_filter to limit the events seen.
|
using the event_filter to limit the samples seen.
|
||||||
|
|
||||||
( datetime.datetime(), datetime.datetime() )
|
( datetime.datetime(), datetime.datetime() )
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ class Connection(base.Connection):
|
|||||||
resource_ids = {}
|
resource_ids = {}
|
||||||
if start_timestamp or end_timestamp:
|
if start_timestamp or end_timestamp:
|
||||||
# Look for resources matching the above criteria and with
|
# Look for resources matching the above criteria and with
|
||||||
# events in the time range we care about, then change the
|
# samples in the time range we care about, then change the
|
||||||
# resource query to return just those resources by id.
|
# resource query to return just those resources by id.
|
||||||
g = self.meter.scan(filter=q, row_start=start_row,
|
g = self.meter.scan(filter=q, row_start=start_row,
|
||||||
row_stop=end_row)
|
row_stop=end_row)
|
||||||
@@ -381,8 +381,8 @@ class Connection(base.Connection):
|
|||||||
}
|
}
|
||||||
yield m
|
yield m
|
||||||
|
|
||||||
def get_raw_events(self, event_filter):
|
def get_samples(self, event_filter):
|
||||||
"""Return an iterable of raw event data as created by
|
"""Return an iterable of samples as created by
|
||||||
:func:`ceilometer.meter.meter_message_from_counter`.
|
:func:`ceilometer.meter.meter_message_from_counter`.
|
||||||
"""
|
"""
|
||||||
q, start, stop = make_query_from_filter(event_filter,
|
q, start, stop = make_query_from_filter(event_filter,
|
||||||
@@ -494,7 +494,7 @@ class Connection(base.Connection):
|
|||||||
return list(results)
|
return list(results)
|
||||||
|
|
||||||
def get_volume_sum(self, event_filter):
|
def get_volume_sum(self, event_filter):
|
||||||
"""Return the sum of the volume field for the events
|
"""Return the sum of the volume field for the samples
|
||||||
described by the query parameters.
|
described by the query parameters.
|
||||||
"""
|
"""
|
||||||
q, start, stop = make_query_from_filter(event_filter)
|
q, start, stop = make_query_from_filter(event_filter)
|
||||||
@@ -509,7 +509,7 @@ class Connection(base.Connection):
|
|||||||
for (k, v) in results.iteritems())
|
for (k, v) in results.iteritems())
|
||||||
|
|
||||||
def get_volume_max(self, event_filter):
|
def get_volume_max(self, event_filter):
|
||||||
"""Return the maximum of the volume field for the events
|
"""Return the maximum of the volume field for the samples
|
||||||
described by the query parameters.
|
described by the query parameters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -525,8 +525,8 @@ class Connection(base.Connection):
|
|||||||
for (k, v) in results.iteritems())
|
for (k, v) in results.iteritems())
|
||||||
|
|
||||||
def get_event_interval(self, event_filter):
|
def get_event_interval(self, event_filter):
|
||||||
"""Return the min and max timestamps from events,
|
"""Return the min and max timestamps from samples,
|
||||||
using the event_filter to limit the events seen.
|
using the event_filter to limit the samples seen.
|
||||||
|
|
||||||
( datetime.datetime(), datetime.datetime() )
|
( datetime.datetime(), datetime.datetime() )
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -118,24 +118,24 @@ class Connection(base.Connection):
|
|||||||
"""
|
"""
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_raw_events(self, event_filter):
|
def get_samples(self, event_filter):
|
||||||
"""Return an iterable of raw event data as created by
|
"""Return an iterable of samples as created by
|
||||||
:func:`ceilometer.meter.meter_message_from_counter`.
|
:func:`ceilometer.meter.meter_message_from_counter`.
|
||||||
"""
|
"""
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_volume_sum(self, event_filter):
|
def get_volume_sum(self, event_filter):
|
||||||
"""Return the sum of the volume field for the events
|
"""Return the sum of the volume field for the samples
|
||||||
described by the query parameters.
|
described by the query parameters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_volume_max(self, event_filter):
|
def get_volume_max(self, event_filter):
|
||||||
"""Return the maximum of the volume field for the events
|
"""Return the maximum of the volume field for the samples
|
||||||
described by the query parameters.
|
described by the query parameters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_event_interval(self, event_filter):
|
def get_event_interval(self, event_filter):
|
||||||
"""Return the min and max timestamp for events
|
"""Return the min and max timestamp for samples
|
||||||
matching the event_filter.
|
matching the event_filter.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ def make_query_from_filter(event_filter, require_meter=True):
|
|||||||
if event_filter.source:
|
if event_filter.source:
|
||||||
q['source'] = event_filter.source
|
q['source'] = event_filter.source
|
||||||
|
|
||||||
# so the events call metadata resource_metadata, so we convert
|
# so the samples call metadata resource_metadata, so we convert
|
||||||
# to that.
|
# to that.
|
||||||
q.update(dict(('resource_%s' % k, v)
|
q.update(dict(('resource_%s' % k, v)
|
||||||
for (k, v) in event_filter.metaquery.iteritems()))
|
for (k, v) in event_filter.metaquery.iteritems()))
|
||||||
@@ -409,7 +409,7 @@ class Connection(base.Connection):
|
|||||||
# to put into it today.
|
# to put into it today.
|
||||||
if start_timestamp or end_timestamp:
|
if start_timestamp or end_timestamp:
|
||||||
# Look for resources matching the above criteria and with
|
# Look for resources matching the above criteria and with
|
||||||
# events in the time range we care about, then change the
|
# samples in the time range we care about, then change the
|
||||||
# resource query to return just those resources by id.
|
# resource query to return just those resources by id.
|
||||||
ts_range = make_timestamp_range(start_timestamp, end_timestamp)
|
ts_range = make_timestamp_range(start_timestamp, end_timestamp)
|
||||||
if ts_range:
|
if ts_range:
|
||||||
@@ -469,18 +469,18 @@ class Connection(base.Connection):
|
|||||||
m['user_id'] = r['user_id']
|
m['user_id'] = r['user_id']
|
||||||
yield m
|
yield m
|
||||||
|
|
||||||
def get_raw_events(self, event_filter):
|
def get_samples(self, event_filter):
|
||||||
"""Return an iterable of raw event data as created by
|
"""Return an iterable of samples as created by
|
||||||
:func:`ceilometer.meter.meter_message_from_counter`.
|
:func:`ceilometer.meter.meter_message_from_counter`.
|
||||||
"""
|
"""
|
||||||
q = make_query_from_filter(event_filter, require_meter=False)
|
q = make_query_from_filter(event_filter, require_meter=False)
|
||||||
events = self.db.meter.find(q)
|
samples = self.db.meter.find(q)
|
||||||
for e in events:
|
for s in samples:
|
||||||
# Remove the ObjectId generated by the database when
|
# Remove the ObjectId generated by the database when
|
||||||
# the event was inserted. It is an implementation
|
# the event was inserted. It is an implementation
|
||||||
# detail that should not leak outside of the driver.
|
# detail that should not leak outside of the driver.
|
||||||
del e['_id']
|
del s['_id']
|
||||||
yield e
|
yield s
|
||||||
|
|
||||||
def get_meter_statistics(self, event_filter, period=None):
|
def get_meter_statistics(self, event_filter, period=None):
|
||||||
"""Return a dictionary containing meter statistics.
|
"""Return a dictionary containing meter statistics.
|
||||||
@@ -524,7 +524,7 @@ class Connection(base.Connection):
|
|||||||
key=operator.itemgetter('period_start'))
|
key=operator.itemgetter('period_start'))
|
||||||
|
|
||||||
def get_volume_sum(self, event_filter):
|
def get_volume_sum(self, event_filter):
|
||||||
"""Return the sum of the volume field for the events
|
"""Return the sum of the volume field for the samples
|
||||||
described by the query parameters.
|
described by the query parameters.
|
||||||
"""
|
"""
|
||||||
q = make_query_from_filter(event_filter)
|
q = make_query_from_filter(event_filter)
|
||||||
@@ -537,7 +537,7 @@ class Connection(base.Connection):
|
|||||||
for r in results['results'])
|
for r in results['results'])
|
||||||
|
|
||||||
def get_volume_max(self, event_filter):
|
def get_volume_max(self, event_filter):
|
||||||
"""Return the maximum of the volume field for the events
|
"""Return the maximum of the volume field for the samples
|
||||||
described by the query parameters.
|
described by the query parameters.
|
||||||
"""
|
"""
|
||||||
q = make_query_from_filter(event_filter)
|
q = make_query_from_filter(event_filter)
|
||||||
@@ -578,8 +578,8 @@ class Connection(base.Connection):
|
|||||||
return (a_min, a_max)
|
return (a_min, a_max)
|
||||||
|
|
||||||
def get_event_interval(self, event_filter):
|
def get_event_interval(self, event_filter):
|
||||||
"""Return the min and max timestamps from events,
|
"""Return the min and max timestamps from samples,
|
||||||
using the event_filter to limit the events seen.
|
using the event_filter to limit the samples seen.
|
||||||
|
|
||||||
( datetime.datetime(), datetime.datetime() )
|
( datetime.datetime(), datetime.datetime() )
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -328,27 +328,27 @@ class Connection(base.Connection):
|
|||||||
m['unit'] = meter.counter_unit
|
m['unit'] = meter.counter_unit
|
||||||
yield m
|
yield m
|
||||||
|
|
||||||
def get_raw_events(self, event_filter):
|
def get_samples(self, event_filter):
|
||||||
"""Return an iterable of raw event data as created by
|
"""Return an iterable of samples as created by
|
||||||
:func:`ceilometer.meter.meter_message_from_counter`.
|
:func:`ceilometer.meter.meter_message_from_counter`.
|
||||||
"""
|
"""
|
||||||
query = model_query(Meter, session=self.session)
|
query = model_query(Meter, session=self.session)
|
||||||
query = make_query_from_filter(query, event_filter,
|
query = make_query_from_filter(query, event_filter,
|
||||||
require_meter=False)
|
require_meter=False)
|
||||||
events = query.all()
|
samples = query.all()
|
||||||
|
|
||||||
for e in events:
|
for s in samples:
|
||||||
# Remove the id generated by the database when
|
# Remove the id generated by the database when
|
||||||
# the event was inserted. It is an implementation
|
# the event was inserted. It is an implementation
|
||||||
# detail that should not leak outside of the driver.
|
# detail that should not leak outside of the driver.
|
||||||
e = row2dict(e)
|
s = row2dict(s)
|
||||||
del e['id']
|
del s['id']
|
||||||
# Replace 'sources' with 'source' to meet the caller's
|
# Replace 'sources' with 'source' to meet the caller's
|
||||||
# expectation, Meter.sources contains one and only one
|
# expectation, Meter.sources contains one and only one
|
||||||
# source in the current implementation.
|
# source in the current implementation.
|
||||||
e['source'] = e['sources'][0]['id']
|
s['source'] = s['sources'][0]['id']
|
||||||
del e['sources']
|
del s['sources']
|
||||||
yield e
|
yield s
|
||||||
|
|
||||||
def _make_volume_query(self, event_filter, counter_volume_func):
|
def _make_volume_query(self, event_filter, counter_volume_func):
|
||||||
"""Returns complex Meter counter_volume query for max and sum."""
|
"""Returns complex Meter counter_volume query for max and sum."""
|
||||||
@@ -372,8 +372,8 @@ class Connection(base.Connection):
|
|||||||
return ({'resource_id': x, 'value': y} for x, y in results)
|
return ({'resource_id': x, 'value': y} for x, y in results)
|
||||||
|
|
||||||
def get_event_interval(self, event_filter):
|
def get_event_interval(self, event_filter):
|
||||||
"""Return the min and max timestamps from events,
|
"""Return the min and max timestamps from samples,
|
||||||
using the event_filter to limit the events seen.
|
using the event_filter to limit the samples seen.
|
||||||
|
|
||||||
( datetime.datetime(), datetime.datetime() )
|
( datetime.datetime(), datetime.datetime() )
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
collector
|
collector
|
||||||
Software service running on the OpenStack infrastructure
|
Software service running on the OpenStack infrastructure
|
||||||
monitoring notifications from other OpenStack components and
|
monitoring notifications from other OpenStack components and
|
||||||
meter events from the ceilometer agent and recording the results
|
samples from the ceilometer agent and recording the results
|
||||||
in the database.
|
in the database.
|
||||||
|
|
||||||
compute agent
|
compute agent
|
||||||
|
|||||||
@@ -327,34 +327,34 @@ class MeterTest(DBTestBase):
|
|||||||
|
|
||||||
class RawEventTest(DBTestBase):
|
class RawEventTest(DBTestBase):
|
||||||
|
|
||||||
def test_get_raw_events_by_user(self):
|
def test_get_samples_by_user(self):
|
||||||
f = storage.EventFilter(user='user-id')
|
f = storage.EventFilter(user='user-id')
|
||||||
results = list(self.conn.get_raw_events(f))
|
results = list(self.conn.get_samples(f))
|
||||||
assert len(results) == 2
|
assert len(results) == 2
|
||||||
for meter in results:
|
for meter in results:
|
||||||
assert meter in [self.msg1, self.msg2]
|
assert meter in [self.msg1, self.msg2]
|
||||||
|
|
||||||
def test_get_raw_events_by_project(self):
|
def test_get_samples_by_project(self):
|
||||||
f = storage.EventFilter(project='project-id')
|
f = storage.EventFilter(project='project-id')
|
||||||
results = list(self.conn.get_raw_events(f))
|
results = list(self.conn.get_samples(f))
|
||||||
assert results
|
assert results
|
||||||
for meter in results:
|
for meter in results:
|
||||||
assert meter in [self.msg1, self.msg2, self.msg3]
|
assert meter in [self.msg1, self.msg2, self.msg3]
|
||||||
|
|
||||||
def test_get_raw_events_by_resource(self):
|
def test_get_samples_by_resource(self):
|
||||||
f = storage.EventFilter(user='user-id', resource='resource-id')
|
f = storage.EventFilter(user='user-id', resource='resource-id')
|
||||||
results = list(self.conn.get_raw_events(f))
|
results = list(self.conn.get_samples(f))
|
||||||
assert results
|
assert results
|
||||||
meter = results[0]
|
meter = results[0]
|
||||||
assert meter is not None
|
assert meter is not None
|
||||||
assert meter == self.msg1
|
assert meter == self.msg1
|
||||||
|
|
||||||
def test_get_events_by_metaquery(self):
|
def test_get_samples_by_metaquery(self):
|
||||||
q = {'metadata.display_name': 'test-server'}
|
q = {'metadata.display_name': 'test-server'}
|
||||||
f = storage.EventFilter(metaquery=q)
|
f = storage.EventFilter(metaquery=q)
|
||||||
got_not_imp = False
|
got_not_imp = False
|
||||||
try:
|
try:
|
||||||
results = list(self.conn.get_raw_events(f))
|
results = list(self.conn.get_samples(f))
|
||||||
assert results
|
assert results
|
||||||
for meter in results:
|
for meter in results:
|
||||||
assert meter in self.msgs
|
assert meter in self.msgs
|
||||||
@@ -362,48 +362,48 @@ class RawEventTest(DBTestBase):
|
|||||||
got_not_imp = True
|
got_not_imp = True
|
||||||
self.assertTrue(got_not_imp)
|
self.assertTrue(got_not_imp)
|
||||||
|
|
||||||
def test_get_raw_events_by_start_time(self):
|
def test_get_samples_by_start_time(self):
|
||||||
f = storage.EventFilter(
|
f = storage.EventFilter(
|
||||||
user='user-id',
|
user='user-id',
|
||||||
start=datetime.datetime(2012, 7, 2, 10, 41),
|
start=datetime.datetime(2012, 7, 2, 10, 41),
|
||||||
)
|
)
|
||||||
results = list(self.conn.get_raw_events(f))
|
results = list(self.conn.get_samples(f))
|
||||||
assert len(results) == 1
|
assert len(results) == 1
|
||||||
assert results[0]['timestamp'] == datetime.datetime(2012, 7, 2, 10, 41)
|
assert results[0]['timestamp'] == datetime.datetime(2012, 7, 2, 10, 41)
|
||||||
|
|
||||||
def test_get_raw_events_by_end_time(self):
|
def test_get_samples_by_end_time(self):
|
||||||
f = storage.EventFilter(
|
f = storage.EventFilter(
|
||||||
user='user-id',
|
user='user-id',
|
||||||
end=datetime.datetime(2012, 7, 2, 10, 41),
|
end=datetime.datetime(2012, 7, 2, 10, 41),
|
||||||
)
|
)
|
||||||
results = list(self.conn.get_raw_events(f))
|
results = list(self.conn.get_samples(f))
|
||||||
length = len(results)
|
length = len(results)
|
||||||
assert length == 1
|
assert length == 1
|
||||||
assert results[0]['timestamp'] == datetime.datetime(2012, 7, 2, 10, 40)
|
assert results[0]['timestamp'] == datetime.datetime(2012, 7, 2, 10, 40)
|
||||||
|
|
||||||
def test_get_raw_events_by_both_times(self):
|
def test_get_samples_by_both_times(self):
|
||||||
f = storage.EventFilter(
|
f = storage.EventFilter(
|
||||||
start=datetime.datetime(2012, 7, 2, 10, 42),
|
start=datetime.datetime(2012, 7, 2, 10, 42),
|
||||||
end=datetime.datetime(2012, 7, 2, 10, 43),
|
end=datetime.datetime(2012, 7, 2, 10, 43),
|
||||||
)
|
)
|
||||||
results = list(self.conn.get_raw_events(f))
|
results = list(self.conn.get_samples(f))
|
||||||
length = len(results)
|
length = len(results)
|
||||||
assert length == 1
|
assert length == 1
|
||||||
assert results[0]['timestamp'] == datetime.datetime(2012, 7, 2, 10, 42)
|
assert results[0]['timestamp'] == datetime.datetime(2012, 7, 2, 10, 42)
|
||||||
|
|
||||||
def test_get_raw_events_by_meter(self):
|
def test_get_samples_by_name(self):
|
||||||
f = storage.EventFilter(user='user-id', meter='no-such-meter')
|
f = storage.EventFilter(user='user-id', meter='no-such-meter')
|
||||||
results = list(self.conn.get_raw_events(f))
|
results = list(self.conn.get_samples(f))
|
||||||
assert not results
|
assert not results
|
||||||
|
|
||||||
def test_get_raw_events_by_meter2(self):
|
def test_get_samples_by_name2(self):
|
||||||
f = storage.EventFilter(user='user-id', meter='instance')
|
f = storage.EventFilter(user='user-id', meter='instance')
|
||||||
results = list(self.conn.get_raw_events(f))
|
results = list(self.conn.get_samples(f))
|
||||||
assert results
|
assert results
|
||||||
|
|
||||||
def test_get_raw_events_by_source(self):
|
def test_get_samples_by_source(self):
|
||||||
f = storage.EventFilter(source='test-1')
|
f = storage.EventFilter(source='test-1')
|
||||||
results = list(self.conn.get_raw_events(f))
|
results = list(self.conn.get_samples(f))
|
||||||
assert results
|
assert results
|
||||||
assert len(results) == 1
|
assert len(results) == 1
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ def show_raw(db, args):
|
|||||||
print u
|
print u
|
||||||
for resource in db.get_resources(user=u):
|
for resource in db.get_resources(user=u):
|
||||||
print ' ', resource['resource_id']
|
print ' ', resource['resource_id']
|
||||||
for event in db.get_raw_events(storage.EventFilter(
|
for event in db.get_samples(storage.EventFilter(
|
||||||
user=u,
|
user=u,
|
||||||
resource=resource['resource_id'],
|
resource=resource['resource_id'],
|
||||||
)):
|
)):
|
||||||
|
|||||||
Reference in New Issue
Block a user