54
57
.. autotype:: ceilometer.api.controllers.v2.AlarmCombinationRule
60
.. autotype:: ceilometer.api.controllers.v2.AlarmTimeConstraint
57
63
.. autotype:: ceilometer.api.controllers.v2.AlarmChange
68
Ceilometer's REST API currently supports two types of queries. The Simple
69
Query functionality provides simple filtering on several fields of the
70
*Sample* type. Complex Query provides the possibility to specify queries
71
with logical and comparison operators on the fields of *Sample*.
73
You may also apply filters based on the values of one or more of the
74
*resource_metadata* field, which you can identify by using *metadata.<field>*
75
syntax in either type of query. Note, however, that given the free-form
76
nature of *resource_metadata* field, there is no practical or consistent way
77
to validate the query fields under *metadata* domain like it is done for
80
.. note:: The API call will return HTTP 200 OK status for both of the
81
following cases: when a query with *metadata.<field>* does not match its
82
value, and when *<field>* itself does not exist in any of the records being
63
87
Many of the endpoints above accept a query filter argument, which
64
88
should be a list of Query data structures. Whatever the endpoint you
65
89
want to apply a filter on, you always filter on the fields of the *Sample*
66
90
type (for example, if you apply a filter on a query for statistics,
67
91
you won't target *duration_start* field of *Statistics*, but *timestamp*
68
field of *Sample*). You may also apply filters based on the values of one
69
or more of the *resource_metadata* field, in which case you should target
70
*metadata.<field>*. Notice, however, that given the free-form nature of
71
*resource_metadata* field, there is no practical or consistent way to
72
validate the query fields under *metadata* domain like it is done for all other
73
fields. In other words, the API call will return HTTP 200 in both scenarios:
74
when a query with *metadata.<field>* does not match its value, and when
75
*<field>* itself does not exist in any of the records being queried.
77
94
.. autotype:: ceilometer.api.controllers.v2.Query
99
The filter expressions of the Complex Query feature operate on the fields
100
of *Sample*, *Alarm* and *AlarmChange*. The following comparison operators are
101
supported: *=*, *!=*, *<*, *<=*, *>*, *>=* and *in*; and the following logical
102
operators can be used: *and* *or* and *not*. The field names are validated
103
against the database models.
105
.. note:: The *not* operator has different meaning in Mongo DB and in SQL DB engine.
106
If the *not* operator is applied on a non existent metadata field then
107
the result depends on the DB engine. For example if
108
{"not": {"metadata.nonexistent_field" : "some value"}} filter is used in a query
109
the Mongo DB will return every Sample object as *not* operator evaluated true
110
for every Sample where the given field does not exists. See more in the Mongod DB doc.
111
In the other hand SQL based DB engine will return empty result as the join operation
112
on the metadata table will return zero row as the on clause of the join which
113
tries to match on the metadata field name is never fulfilled.
115
Complex Query supports defining the list of orderby expressions in the form
116
of [{"field_name": "asc"}, {"field_name2": "desc"}, ...].
118
The number of the returned items can be bounded using the *limit* option.
120
The *filter*, *orderby* and *limit* are all optional fields in a query.
122
.. rest-controller:: ceilometer.api.controllers.v2:QuerySamplesController
123
:webprefix: /v2/query/samples
125
.. rest-controller:: ceilometer.api.controllers.v2:QueryAlarmsController
126
:webprefix: /v2/query/alarms
128
.. rest-controller:: ceilometer.api.controllers.v2:QueryAlarmHistoryController
129
:webprefix: /v2/query/alarms/history
131
.. autotype:: ceilometer.api.controllers.v2.ComplexQuery
370
424
This query would only return the last 3 samples.
426
Functional example for Complex Query
427
++++++++++++++++++++++++++++++++++++
429
This example demonstrates how complex query filter expressions can be generated and sent
430
to the /v2/query/samples endpoint of Ceilometer API using POST request.
432
To check for *cpu_util* samples reported between 18:00-18:15 or between 18:30 - 18:45
433
on a particular date (2013-12-01), where the utilization is between 23 and 26 percent,
434
but not exactly 25.12 percent, the following filter expression can be created::
438
[{"=": {"counter_name": "cpu_util"}},
439
{">": {"counter_volume": 0.23}},
440
{"<": {"counter_volume": 0.26}},
441
{"not": {"=": {"counter_volume": 0.2512}}}]},
444
[{">": {"timestamp": "2013-12-01T18:00:00"}},
445
{"<": {"timestamp": "2013-12-01T18:15:00"}}]},
447
[{">": {"timestamp": "2013-12-01T18:30:00"}},
448
{"<": {"timestamp": "2013-12-01T18:45:00"}}]}]}]}
450
Different sorting criteria can be defined for the query filter, for example the results
451
can be ordered in an ascending order by the *counter_volume* and descending order based on
452
the *timestamp*. The following order by expression has to be created for specifying this
455
[{"counter_volume": "ASC"}, {"timestamp": "DESC"}]
457
As the current implementation accepts only string values as query filter and order by
458
definitions, the above defined expressions have to be converted to string values.
459
By adding a limit criteria to the request, which maximizes the number of returned samples
460
to four, the query looks like the following::
463
"filter" : "{\"and\":[{\"and\": [{\"=\": {\"counter_name\": \"cpu_util\"}}, {\">\": {\"counter_volume\": 0.23}}, {\"<\": {\"counter_volume\": 0.26}}, {\"not\": {\"=\": {\"counter_volume\": 0.2512}}}]}, {\"or\": [{\"and\": [{\">\": {\"timestamp\": \"2013-12-01T18:00:00\"}}, {\"<\": {\"timestamp\": \"2013-12-01T18:15:00\"}}]}, {\"and\": [{\">\": {\"timestamp\": \"2013-12-01T18:30:00\"}}, {\"<\": {\"timestamp\": \"2013-12-01T18:45:00\"}}]}]}]}",
464
"orderby" : "[{\"counter_volume\": \"ASC\"}, {\"timestamp\": \"DESC\"}]",
468
A query request looks like the following with curl::
470
curl -X POST -H 'X-Auth-Token: <inserttokenhere>' -H 'Content-Type: application/json' \
471
-d '<insertyourqueryexpressionhere>' \
472
http://localhost:8777/v2/query/samples
372
474
.. _user-defined-data:
374
476
User-defined data