~ubuntu-branches/ubuntu/vivid/ceilometer/vivid

« back to all changes in this revision

Viewing changes to doc/source/webapi/v2.rst

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2014-03-06 14:44:28 UTC
  • mto: (28.1.1 utopic-proposed) (1.2.1)
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: package-import@ubuntu.com-20140306144428-rvphsh4igwyulzf0
Tags: upstream-2014.1~b3
ImportĀ upstreamĀ versionĀ 2014.1~b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
.. rest-controller:: ceilometer.api.controllers.v2:MeterController
23
23
   :webprefix: /v2/meters
24
24
 
 
25
.. autotype:: ceilometer.api.controllers.v2.Meter
 
26
   :members:
 
27
 
 
28
.. autotype:: ceilometer.api.controllers.v2.OldSample
 
29
   :members:
 
30
 
25
31
Samples and Statistics
26
32
======================
27
33
 
28
 
.. autotype:: ceilometer.api.controllers.v2.Meter
29
 
   :members:
30
 
 
31
34
.. autotype:: ceilometer.api.controllers.v2.Sample
32
35
   :members:
33
36
 
54
57
.. autotype:: ceilometer.api.controllers.v2.AlarmCombinationRule
55
58
   :members:
56
59
 
 
60
.. autotype:: ceilometer.api.controllers.v2.AlarmTimeConstraint
 
61
   :members:
 
62
 
57
63
.. autotype:: ceilometer.api.controllers.v2.AlarmChange
58
64
   :members:
59
65
 
60
66
Filtering Queries
61
67
=================
62
 
 
 
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*.
 
72
 
 
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
 
78
all other fields.
 
79
 
 
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
 
83
   queried.
 
84
 
 
85
Simple Query
 
86
++++++++++++
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.
 
92
field of *Sample*).
76
93
 
77
94
.. autotype:: ceilometer.api.controllers.v2.Query
78
95
   :members:
79
96
 
 
97
Complex Query
 
98
+++++++++++++
 
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.
 
104
 
 
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.
 
114
 
 
115
Complex Query supports defining the list of orderby expressions in the form
 
116
of [{"field_name": "asc"}, {"field_name2": "desc"}, ...].
 
117
 
 
118
The number of the returned items can be bounded using the *limit* option.
 
119
 
 
120
The *filter*, *orderby* and *limit* are all optional fields in a query.
 
121
 
 
122
.. rest-controller:: ceilometer.api.controllers.v2:QuerySamplesController
 
123
   :webprefix: /v2/query/samples
 
124
 
 
125
.. rest-controller:: ceilometer.api.controllers.v2:QueryAlarmsController
 
126
   :webprefix: /v2/query/alarms
 
127
 
 
128
.. rest-controller:: ceilometer.api.controllers.v2:QueryAlarmHistoryController
 
129
   :webprefix: /v2/query/alarms/history
 
130
 
 
131
.. autotype:: ceilometer.api.controllers.v2.ComplexQuery
 
132
   :members:
 
133
 
80
134
Links
81
135
=====
82
136
 
100
154
+++++++++++
101
155
Ceilometer API calls:
102
156
 
103
 
.. note:: To successfully query the Ceilometer you must first get a project-specific token from the Keystone service and add it to any API calls that you execute against that project. See the `Openstack credentials documentation <http://docs.openstack.org/api/quick-start/content/index.html#getting-credentials-a00665>`_ for additional details.
 
157
.. note:: To successfully query the Ceilometer you must first get a project-specific token from the Keystone service and add it to any API calls that you execute against that project. See the `OpenStack credentials documentation <http://docs.openstack.org/api/quick-start/content/index.html#getting-credentials-a00665>`_ for additional details.
104
158
 
105
159
A simple query to return a list of available meters::
106
160
 
369
423
 
370
424
This query would only return the last 3 samples.
371
425
 
 
426
Functional example for Complex Query
 
427
++++++++++++++++++++++++++++++++++++
 
428
 
 
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.
 
431
 
 
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::
 
435
 
 
436
    {"and":
 
437
     [{"and":
 
438
      [{"=": {"counter_name": "cpu_util"}},
 
439
       {">": {"counter_volume": 0.23}},
 
440
       {"<": {"counter_volume": 0.26}},
 
441
       {"not": {"=": {"counter_volume": 0.2512}}}]},
 
442
      {"or":
 
443
       [{"and":
 
444
        [{">": {"timestamp": "2013-12-01T18:00:00"}},
 
445
         {"<": {"timestamp": "2013-12-01T18:15:00"}}]},
 
446
        {"and":
 
447
         [{">": {"timestamp": "2013-12-01T18:30:00"}},
 
448
          {"<": {"timestamp": "2013-12-01T18:45:00"}}]}]}]}
 
449
 
 
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
 
453
criteria::
 
454
 
 
455
    [{"counter_volume": "ASC"}, {"timestamp": "DESC"}]
 
456
 
 
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::
 
461
 
 
462
    {
 
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\"}]",
 
465
    "limit" : 4
 
466
    }
 
467
 
 
468
A query request looks like the following with curl::
 
469
 
 
470
    curl -X POST -H 'X-Auth-Token: <inserttokenhere>' -H 'Content-Type: application/json' \
 
471
      -d '<insertyourqueryexpressionhere>' \
 
472
       http://localhost:8777/v2/query/samples
 
473
 
372
474
.. _user-defined-data:
373
475
 
374
476
User-defined data