Debian Codegraph @

doc/source/admin/telemetry-dynamic-pollster.rst

raw
1 .. _telemetry_dynamic_pollster:
2
3 Introduction to dynamic pollster subsystem
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 The dynamic pollster feature allows system administrators to
7 create/update REST API pollsters on the fly (without changing code).
8 The system reads YAML configures that are found in
9 ``pollsters_definitions_dirs`` parameter, which has the default at
10 ``/etc/ceilometer/pollsters.d``. Operators can use a single file per
11 dynamic pollster or multiple dynamic pollsters per file.
12
13
14 Current limitations of the dynamic pollster system
15 --------------------------------------------------
16 Currently, the following types of APIs are not supported by the
17 dynamic pollster system:
18
19 * Tenant APIs: Tenant APIs are the ones that need to be polled in a tenant
20 fashion. This feature is "a nice" to have, but is currently not
21 implemented.
22
23
24 The dynamic pollsters system configuration (for OpenStack APIs)
25 ---------------------------------------------------------------
26 Each YAML file in the dynamic pollster feature can use the following
27 attributes to define a dynamic pollster:
28
29 .. warning::
30 Caution: Ceilometer does not accept complex value data structure for
31 ``value`` and ``metadata`` configurations. Therefore, if you are extracting
32 a complex data structure (Object, list, map, or others), you can take
33 advantage of the ``Operations on extracted attributes`` feature to transform
34 the object into a simple value (string or number)
35
36 * ``name``: mandatory field. It specifies the name/key of the dynamic
37 pollster. For instance, a pollster for magnum can use the name
38 ``dynamic.magnum.cluster``;
39
40 * ``sample_type``: mandatory field; it defines the sample type. It must
41 be one of the values: ``gauge``, ``delta``, ``cumulative``;
42
43 * ``unit``: mandatory field; defines the unit of the metric that is
44 being collected. For magnum, for instance, one can use ``cluster`` as
45 the unit or some other meaningful String value;
46
47 * ``value_attribute``: mandatory attribute; defines the attribute in the
48 response from the URL of the component being polled. We also accept
49 nested values dictionaries. To use a nested value one can simply use
50 ``attribute1.attribute2.<asMuchAsNeeded>.lastattribute``. It is also
51 possible to reference the sample itself using ``"." (dot)``; the self
52 reference of the sample is interesting in cases when the attribute might
53 not exist. Therefore, together with the operations options, one can first
54 check if it exist before retrieving it (example:
55 ``". | value['some_field'] if 'some_field' in value else ''"``).
56 In our magnum example, we can use ``status`` as the value attribute;
57
58 * ``endpoint_type``: mandatory field; defines the endpoint type that is
59 used to discover the base URL of the component to be monitored; for
60 magnum, one can use ``container-infra``. Other values are accepted such
61 as ``volume`` for cinder endpoints, ``object-store`` for swift, and so
62 on;
63
64 * ``url_path``: mandatory attribute. It defines the path of the request
65 that we execute on the endpoint to gather data. For example, to gather
66 data from magnum, one can use ``v1/clusters/detail``;
67
68 * ``metadata_fields``: optional field. It is a list of all fields that
69 the response of the request executed with ``url_path`` that we want to
70 retrieve. To use a nested value one can simply use
71 ``attribute1.attribute2.<asMuchAsNeeded>.lastattribute``. As an example,
72 for magnum, one can use the following values:
73
74 .. code-block:: yaml
75
76 metadata_fields:
77 - "labels"
78 - "updated_at"
79 - "keypair"
80 - "master_flavor_id"
81 - "api_address"
82 - "master_addresses"
83 - "node_count"
84 - "docker_volume_size"
85 - "master_count"
86 - "node_addresses"
87 - "status_reason"
88 - "coe_version"
89 - "cluster_template_id"
90 - "name"
91 - "stack_id"
92 - "created_at"
93 - "discovery_url"
94 - "container_version"
95
96 * ``skip_sample_values``: optional field. It defines the values that
97 might come in the ``value_attribute`` that we want to ignore. For
98 magnun, one could for instance, ignore some of the status it has for
99 clusters. Therefore, data is not gathered for clusters in the defined
100 status.
101
102 .. code-block:: yaml
103
104 skip_sample_values:
105 - "CREATE_FAILED"
106 - "DELETE_FAILED"
107
108 * ``value_mapping``: optional attribute. It defines a mapping for the
109 values that the dynamic pollster is handling. This is the actual value
110 that is sent to Gnocchi or other backends. If there is no mapping
111 specified, we will use the raw value that is obtained with the use of
112 ``value_attribute``. An example for magnum, one can use:
113
114 .. code-block:: yaml
115
116 value_mapping:
117 CREATE_IN_PROGRESS: "0"
118 CREATE_FAILED: "1"
119 CREATE_COMPLETE: "2"
120 UPDATE_IN_PROGRESS: "3"
121 UPDATE_FAILED: "4"
122 UPDATE_COMPLETE: "5"
123 DELETE_IN_PROGRESS: "6"
124 DELETE_FAILED: "7"
125 DELETE_COMPLETE: "8"
126 RESUME_COMPLETE: "9"
127 RESUME_FAILED: "10"
128 RESTORE_COMPLETE: "11"
129 ROLLBACK_IN_PROGRESS: "12"
130 ROLLBACK_FAILED: "13"
131 ROLLBACK_COMPLETE: "14"
132 SNAPSHOT_COMPLETE: "15"
133 CHECK_COMPLETE: "16"
134 ADOPT_COMPLETE: "17"
135
136 * ``default_value``: optional parameter. The default value for
137 the value mapping in case the variable value receives data that is not
138 mapped to something in the ``value_mapping`` configuration. This
139 attribute is only used when ``value_mapping`` is defined. Moreover, it
140 has a default of ``-1``.
141
142 * ``metadata_mapping``: optional parameter. The map used to create new
143 metadata fields. The key is a metadata name that exists in the response
144 of the request we make, and the value of this map is the new desired
145 metadata field that will be created with the content of the metadata that
146 we are mapping. The ``metadata_mapping`` can be created as follows:
147
148 .. code-block:: yaml
149
150 metadata_mapping:
151 name: "display_name"
152 some_attribute: "new_attribute_name"
153
154 * ``preserve_mapped_metadata``: optional parameter. It indicates if we
155 preserve the old metadata name when it gets mapped to a new one.
156 The default value is ``True``.
157
158 * ``response_entries_key``: optional parameter. This value is used to define
159 the "key" of the response that will be used to look-up the entries used in
160 the dynamic pollster processing. If no ``response_entries_key`` is informed
161 by the operator, we will use the first we find. Moreover, if the response
162 contains a list, instead of an object where one of its attributes is a list
163 of entries, we use the list directly. Therefore, this option will be
164 ignored when the API is returning the list/array of entries to be processed
165 directly. We also accept nested values dictionaries. To use a nested value
166 one can simply use ``attribute1.attribute2.<asMuchAsNeeded>.lastattribute``
167
168 * ``user_id_attribute``: optional parameter. The default value is ``user_id``.
169 The name of the attribute in the entries that are processed from
170 ``response_entries_key`` elements that will be mapped to ``user_id``
171 attribute that is sent to Gnocchi.
172
173 * ``project_id_attribute``: optional parameter. The default value is
174 ``project_id``. The name of the attribute in the entries that are
175 processed from ``response_entries_key`` elements that will be mapped to
176 ``project_id`` attribute that is sent to Gnocchi.
177
178 * ``resource_id_attribute``: optional parameter. The default value is ``id``.
179 The name of the attribute in the entries that are processed from
180 ``response_entries_key`` elements that will be mapped to ``id`` attribute
181 that is sent to Gnocchi.
182
183 * ``headers``: optional parameter. It is a map (similar to the
184 metadata_mapping) of key and value that can be used to customize the header
185 of the request that is executed against the URL. This configuration works
186 for both OpenStack and non-OpenStack dynamic pollster configuration.
187
188 .. code-block:: yaml
189
190 headers:
191 "x-openstack-nova-api-version": "2.46"
192
193 * ``timeout``: optional parameter. Defines the request timeout for the
194 requests executed by the dynamic pollsters to gather data. The default
195 timeout value is 30 seconds. If it is set to `None`, this means that the
196 request never times out on the client side. Therefore, one might have
197 problems if the server never closes the connection. The pollsters are
198 executed serially, one after the other. Therefore, if the request hangs,
199 all pollsters (including the non-dynamic ones) will stop executing.
200
201 * ``namespaces``: optional parameter. Defines the namespaces (running
202 ceilometer instances) where the pollster will be instantiated. This
203 parameter accepts a single string value or a list of strings. The
204 default value is `central`.
205
206 The complete YAML configuration to gather data from Magnum (that has been used
207 as an example) is the following:
208
209 .. code-block:: yaml
210
211 ---
212
213 - name: "dynamic.magnum.cluster"
214 sample_type: "gauge"
215 unit: "cluster"
216 value_attribute: "status"
217 endpoint_type: "container-infra"
218 url_path: "v1/clusters/detail"
219 metadata_fields:
220 - "labels"
221 - "updated_at"
222 - "keypair"
223 - "master_flavor_id"
224 - "api_address"
225 - "master_addresses"
226 - "node_count"
227 - "docker_volume_size"
228 - "master_count"
229 - "node_addresses"
230 - "status_reason"
231 - "coe_version"
232 - "cluster_template_id"
233 - "name"
234 - "stack_id"
235 - "created_at"
236 - "discovery_url"
237 - "container_version"
238 value_mapping:
239 CREATE_IN_PROGRESS: "0"
240 CREATE_FAILED: "1"
241 CREATE_COMPLETE: "2"
242 UPDATE_IN_PROGRESS: "3"
243 UPDATE_FAILED: "4"
244 UPDATE_COMPLETE: "5"
245 DELETE_IN_PROGRESS: "6"
246 DELETE_FAILED: "7"
247 DELETE_COMPLETE: "8"
248 RESUME_COMPLETE: "9"
249 RESUME_FAILED: "10"
250 RESTORE_COMPLETE: "11"
251 ROLLBACK_IN_PROGRESS: "12"
252 ROLLBACK_FAILED: "13"
253 ROLLBACK_COMPLETE: "14"
254 SNAPSHOT_COMPLETE: "15"
255 CHECK_COMPLETE: "16"
256 ADOPT_COMPLETE: "17"
257
258 We can also replicate and enhance some hardcoded pollsters.
259 For instance, the pollster to gather VPN connections. Currently,
260 it is always persisting `1` for all of the VPN connections it finds.
261 However, the VPN connection can have multiple statuses, and we should
262 normally only bill for active resources, and not resources on `ERROR`
263 states. An example to gather VPN connections data is the following
264 (this is just an example, and one can adapt and configure as he/she
265 desires):
266
267 .. code-block:: yaml
268
269 ---
270
271 - name: "dynamic.network.services.vpn.connection"
272 sample_type: "gauge"
273 unit: "ipsec_site_connection"
274 value_attribute: "status"
275 endpoint_type: "network"
276 url_path: "v2.0/vpn/ipsec-site-connections"
277 metadata_fields:
278 - "name"
279 - "vpnservice_id"
280 - "description"
281 - "status"
282 - "peer_address"
283 value_mapping:
284 ACTIVE: "1"
285 metadata_mapping:
286 name: "display_name"
287 default_value: 0
288
289 * ``response_handlers``: optional parameter. Defines the response
290 handlers used to handle the response. For now, the supported values
291 are:
292
293 ``json``: This handler will interpret the response as a `JSON` and will
294 convert it to a `dictionary` which can be manipulated using the
295 operations options when mapping the attributes:
296
297 .. code-block:: yaml
298
299 ---
300
301 - name: "dynamic.json.response"
302 sample_type: "gauge"
303 [...]
304 response_handlers:
305 - json
306
307 Response to handle:
308
309 .. code-block:: json
310
311 {
312 "test": {
313 "list": [1, 2, 3]
314 }
315 }
316
317 Response handled:
318
319 .. code-block:: python
320
321 {
322 'test': {
323 'list': [1, 2, 3]
324 }
325 }
326
327
328 ``xml``: This handler will interpret the response as an `XML` and will
329 convert it to a `dictionary` which can be manipulated using the
330 operations options when mapping the attributes:
331
332 .. code-block:: yaml
333
334 ---
335
336 - name: "dynamic.json.response"
337 sample_type: "gauge"
338 [...]
339 response_handlers:
340 - xml
341
342 Response to handle:
343
344 .. code-block:: xml
345
346 <test>
347 <list>1</list>
348 <list>2</list>
349 <list>3</list>
350 </test>
351
352 Response handled:
353
354 .. code-block:: python
355
356 {
357 'test': {
358 'list': [1, 2, 3]
359 }
360 }
361
362 ``text``: This handler will interpret the response as a `PlainText` and
363 will convert it to a `dictionary` which can be manipulated using the
364 operations options when mapping the attributes:
365
366 .. code-block:: yaml
367
368 ---
369
370 - name: "dynamic.json.response"
371 sample_type: "gauge"
372 [...]
373 response_handlers:
374 - text
375
376 Response to handle:
377
378 .. code-block:: text
379
380 Plain text response
381
382 Response handled:
383
384 .. code-block:: python
385
386 {
387 'out': "Plain text response"
388 }
389
390 They can be used together or individually. If not defined, the
391 `default` value will be `json`. If you set 2 or more response
392 handlers, the first configured handler will be used to try to
393 handle the response, if it is not possible, a `DEBUG` log
394 message will be displayed, then the next will be used
395 and so on. If no configured handler was able to handle
396 the response, an empty dict will be returned and a `WARNING`
397 log will be displayed to warn operators that the response was
398 not able to be handled by any configured handler.
399
400 The dynamic pollsters system configuration (for non-OpenStack APIs)
401 -------------------------------------------------------------------
402
403 The dynamic pollster system can also be used for non-OpenStack APIs.
404 to configure non-OpenStack APIs, one can use all but one attribute of
405 the Dynamic pollster system. The attribute that is not supported is
406 the ``endpoint_type``. The dynamic pollster system for non-OpenStack APIs
407 is activated automatically when one uses the configurations ``module``.
408
409 The extra parameters (in addition to the original ones) that are available
410 when using the Non-OpenStack dynamic pollster sub-subsystem are the following:
411
412 * ``module``: required parameter. It is the python module name that Ceilometer
413 has to load to use the authentication object when executing requests against
414 the API. For instance, if one wants to create a pollster to gather data from
415 RadosGW, he/she can use the ``awsauth`` python module.
416
417 * ``authentication_object``: mandatory parameter. The name of the class that we
418 can find in the ``module`` that Ceilometer will use as the authentication
419 object in the request. For instance, when using the ``awsauth`` python module
420 to gather data from RadosGW, one can use the authentication object as
421 ``S3Auth``.
422
423 * ``authentication_parameters``: optional parameter. It is a comma separated
424 value that will be used to instantiate the ``authentication_object``. For
425 instance, if we gather data from RadosGW, and we use the ``S3Auth`` class,
426 the ``authentication_parameters`` can be configured as
427 ``<rados_gw_access_key>, rados_gw_secret_key, rados_gw_host_name``.
428
429 * ``barbican_secret_id``: optional parameter. The Barbican secret ID,
430 from which, Ceilometer can retrieve the comma separated values of the
431 ``authentication_parameters``.
432
433 As follows we present an example on how to convert the hard-coded pollster
434 for `radosgw.api.request` metric to the dynamic pollster model:
435
436 .. code-block:: yaml
437
438 ---
439
440 - name: "dynamic.radosgw.api.request"
441 sample_type: "gauge"
442 unit: "request"
443 value_attribute: "total.ops"
444 url_path: "http://rgw.service.stage.i.ewcs.ch/admin/usage"
445 module: "awsauth"
446 authentication_object: "S3Auth"
447 authentication_parameters: "<access_key>,<secret_key>,<rados_gateway_server>"
448 user_id_attribute: "user"
449 project_id_attribute: "user"
450 resource_id_attribute: "user"
451 response_entries_key: "summary"
452
453 We can take that example a bit further, and instead of gathering the `total
454 .ops` variable, which counts for all the requests (even the unsuccessful
455 ones), we can use the `successful_ops`.
456
457 .. code-block:: yaml
458
459 ---
460
461 - name: "dynamic.radosgw.api.request.successful_ops"
462 sample_type: "gauge"
463 unit: "request"
464 value_attribute: "total.successful_ops"
465 url_path: "http://rgw.service.stage.i.ewcs.ch/admin/usage"
466 module: "awsauth"
467 authentication_object: "S3Auth"
468 authentication_parameters: "<access_key>, <secret_key>,<rados_gateway_server>"
469 user_id_attribute: "user"
470 project_id_attribute: "user"
471 resource_id_attribute: "user"
472 response_entries_key: "summary"
473
474 The dynamic pollsters system configuration (for local host commands)
475 --------------------------------------------------------------------
476
477 The dynamic pollster system can also be used for local host commands,
478 these commands must be installed in the system that is running the
479 Ceilometer compute agent.
480 To configure local hosts commands, one can use all but two attributes of
481 the Dynamic pollster system. The attributes that are not supported are
482 the ``endpoint_type`` and ``url_path``. The dynamic pollster system for
483 local host commands is activated automatically when one uses the
484 configuration ``host_command``.
485
486 The extra parameter (in addition to the original ones) that is available
487 when using the local host commands dynamic pollster sub-subsystem is the
488 following:
489
490 * ``host_command``: required parameter. It is the host command that will
491 be executed in the same host the Ceilometer dynamic pollster agent is
492 running. The output of the command will be processed by the pollster and
493 stored in the configured backend.
494
495 As follows we present an example on how to use the local host command:
496
497 .. code-block:: yaml
498
499 ---
500
501 - name: "dynamic.host.command"
502 sample_type: "gauge"
503 unit: "request"
504 value_attribute: "value"
505 response_entries_key: "test"
506 host_command: "echo '<test><user_id>id1_u</user_id><project_id>id1_p</project_id><id>id1</id><meta>meta-data-to-store</meta><value>1</value></test>'"
507 metadata_fields:
508 - "meta"
509 response_handlers:
510 - xml
511
512 To execute multi page host commands, the `next_sample_url_attribute`
513 must generate the next sample command, like the following example:
514
515 .. code-block:: yaml
516
517 ---
518
519 - name: "dynamic.s3.objects.size"
520 sample_type: "gauge"
521 unit: "request"
522 value_attribute: "Size"
523 project_id_attribute: "Owner.ID"
524 user_id_attribute: "Owner.ID"
525 resource_id_attribute: "Key"
526 response_entries_key: "Contents"
527 host_command: "aws s3api list-objects"
528 next_sample_url_attribute: NextToken | 'aws s3api list-objects --starting-token "' + value + '"'
529
530 Operations on extracted attributes
531 ----------------------------------
532
533 The dynamic pollster system can execute Python operations to transform the
534 attributes that are extracted from the JSON response that the system handles.
535
536 One example of use case is the RadosGW that uses <project_id$project_id> as the
537 username (which is normally mapped to the Gnocchi resource_id). With this
538 feature (operations on extracted attributes), one can create configurations in
539 the dynamic pollster to clean/normalize that variable. It is as simple as
540 defining `resource_id_attribute: "user | value.split('$')[0].strip()"`
541
542 The operations are separated by `|` symbol. The first element of the expression
543 is the key to be retrieved from the JSON object. The other elements are
544 operations that can be applied to the `value` variable. The value variable
545 is the variable we use to hold the data being extracted. The previous
546 example can be rewritten as:
547 `resource_id_attribute: "user | value.split ('$') | value[0] | value.strip()"`
548
549 As follows we present a complete configuration for a RadosGW dynamic
550 pollster that is removing the `$` symbol, and getting the first part of the
551 String.
552
553 .. code-block:: yaml
554
555 ---
556
557 - name: "dynamic.radosgw.api.request.successful_ops"
558 sample_type: "gauge"
559 unit: "request"
560 value_attribute: "total.successful_ops"
561 url_path: "http://rgw.service.stage.i.ewcs.ch/admin/usage"
562 module: "awsauth"
563 authentication_object: "S3Auth"
564 authentication_parameters: "<access_key>,<secret_key>,<rados_gateway_server>"
565 user_id_attribute: "user | value.split ('$') | value[0]"
566 project_id_attribute: "user | value.split ('$') | value[0]"
567 resource_id_attribute: "user | value.split ('$') | value[0]"
568 response_entries_key: "summary"
569
570 The Dynamic pollster configuration options that support this feature are the
571 following:
572
573 * value_attribute
574 * response_entries_key
575 * user_id_attribute
576 * project_id_attribute
577 * resource_id_attribute
578
579 Multi metric dynamic pollsters (handling attribute values with list of objects)
580 -------------------------------------------------------------------------------
581
582 The initial idea for this feature comes from the `categories` fields that we
583 can find in the `summary` object of the RadosGW API. Each user has a
584 `categories` attribute in the response; in the `categories` list, we can find
585 the object that presents in a granular fashion the consumption of different
586 RadosGW API operations such as GET, PUT, POST, and may others.
587
588 As follows we present an example of such a JSON response.
589
590 .. code-block:: json
591
592 {
593 "entries": [
594 {
595 "buckets": [
596 {
597 "bucket": "",
598 "categories": [
599 {
600 "bytes_received": 0,
601 "bytes_sent": 40,
602 "category": "list_buckets",
603 "ops": 2,
604 "successful_ops": 2
605 }
606 ],
607 "epoch": 1572969600,
608 "owner": "user",
609 "time": "2019-11-21 00:00:00.000000Z"
610 },
611 {
612 "bucket": "-",
613 "categories": [
614 {
615 "bytes_received": 0,
616 "bytes_sent": 0,
617 "category": "get_obj",
618 "ops": 1,
619 "successful_ops": 0
620 }
621 ],
622 "epoch": 1572969600,
623 "owner": "someOtherUser",
624 "time": "2019-11-21 00:00:00.000000Z"
625 }
626 ]
627 }
628 ]
629 "summary": [
630 {
631 "categories": [
632 {
633 "bytes_received": 0,
634 "bytes_sent": 0,
635 "category": "create_bucket",
636 "ops": 2,
637 "successful_ops": 2
638 },
639 {
640 "bytes_received": 0,
641 "bytes_sent": 2120428,
642 "category": "get_obj",
643 "ops": 46,
644 "successful_ops": 46
645 },
646 {
647 "bytes_received": 0,
648 "bytes_sent": 21484,
649 "category": "list_bucket",
650 "ops": 8,
651 "successful_ops": 8
652 },
653 {
654 "bytes_received": 6889056,
655 "bytes_sent": 0,
656 "category": "put_obj",
657 "ops": 46,
658 "successful_ops": 46
659 }
660 ],
661 "total": {
662 "bytes_received": 6889056,
663 "bytes_sent": 2141912,
664 "ops": 102,
665 "successful_ops": 102
666 },
667 "user": "user"
668 },
669 {
670 "categories": [
671 {
672 "bytes_received": 0,
673 "bytes_sent": 0,
674 "category": "create_bucket",
675 "ops": 1,
676 "successful_ops": 1
677 },
678 {
679 "bytes_received": 0,
680 "bytes_sent": 0,
681 "category": "delete_obj",
682 "ops": 23,
683 "successful_ops": 23
684 },
685 {
686 "bytes_received": 0,
687 "bytes_sent": 5371,
688 "category": "list_bucket",
689 "ops": 2,
690 "successful_ops": 2
691 },
692 {
693 "bytes_received": 3444350,
694 "bytes_sent": 0,
695 "category": "put_obj",
696 "ops": 23,
697 "successful_ops": 23
698 }
699 ],
700 "total": {
701 "bytes_received": 3444350,
702 "bytes_sent": 5371,
703 "ops": 49,
704 "successful_ops": 49
705 },
706 "user": "someOtherUser"
707 }
708 ]
709 }
710
711 In that context, and having in mind that we have APIs with similar data
712 structures, we developed an extension for the dynamic pollster that enables
713 multi-metric processing for a single pollster. It works as follows.
714
715 The pollster name will contain a placeholder for the variable that
716 identifies the "submetric". E.g. `dynamic.radosgw.api.request.{category}`.
717 The placeholder `{category}` indicates the object's attribute that is in the
718 list of objects that we use to load the sub metric name. Then, we must use a
719 special notation in the `value_attribute` configuration to indicate that we are
720 dealing with a list of objects. This is achieved via `[]` (brackets); for
721 instance, in the `dynamic.radosgw.api.request.{category}`, we can use
722 `[categories].ops` as the `value_attribute`. This indicates that the value we
723 retrieve is a list of objects, and when the dynamic pollster processes it, we
724 want it (the pollster) to load the `ops` value for the sub metrics being
725 generated.
726
727 Examples on how to create multi-metric pollster to handle data from RadosGW API
728 are presented as follows:
729
730 .. code-block:: yaml
731
732 ---
733
734 - name: "dynamic.radosgw.api.request.{category}"
735 sample_type: "gauge"
736 unit: "request"
737 value_attribute: "[categories].ops"
738 url_path: "http://rgw.service.stage.i.ewcs.ch/admin/usage"
739 module: "awsauth"
740 authentication_object: "S3Auth"
741 authentication_parameters: "<access_key>, <secret_key>,<rados_gateway_server>"
742 user_id_attribute: "user | value.split('$')[0]"
743 project_id_attribute: "user | value.split('$') | value[0]"
744 resource_id_attribute: "user | value.split('$') | value[0]"
745 response_entries_key: "summary"
746
747 - name: "dynamic.radosgw.api.request.successful_ops.{category}"
748 sample_type: "gauge"
749 unit: "request"
750 value_attribute: "[categories].successful_ops"
751 url_path: "http://rgw.service.stage.i.ewcs.ch/admin/usage"
752 module: "awsauth"
753 authentication_object: "S3Auth"
754 authentication_parameters: "<access_key>, <secret_key>,<rados_gateway_server>"
755 user_id_attribute: "user | value.split('$')[0]"
756 project_id_attribute: "user | value.split('$') | value[0]"
757 resource_id_attribute: "user | value.split('$') | value[0]"
758 response_entries_key: "summary"
759
760 - name: "dynamic.radosgw.api.bytes_sent.{category}"
761 sample_type: "gauge"
762 unit: "request"
763 value_attribute: "[categories].bytes_sent"
764 url_path: "http://rgw.service.stage.i.ewcs.ch/admin/usage"
765 module: "awsauth"
766 authentication_object: "S3Auth"
767 authentication_parameters: "<access_key>, <secret_key>,<rados_gateway_server>"
768 user_id_attribute: "user | value.split('$')[0]"
769 project_id_attribute: "user | value.split('$') | value[0]"
770 resource_id_attribute: "user | value.split('$') | value[0]"
771 response_entries_key: "summary"
772
773 - name: "dynamic.radosgw.api.bytes_received.{category}"
774 sample_type: "gauge"
775 unit: "request"
776 value_attribute: "[categories].bytes_received"
777 url_path: "http://rgw.service.stage.i.ewcs.ch/admin/usage"
778 module: "awsauth"
779 authentication_object: "S3Auth"
780 authentication_parameters: "<access_key>, <secret_key>,<rados_gateway_server>"
781 user_id_attribute: "user | value.split('$')[0]"
782 project_id_attribute: "user | value.split('$') | value[0]"
783 resource_id_attribute: "user | value.split('$') | value[0]"
784 response_entries_key: "summary"
785
786 Handling linked API responses
787 -----------------------------
788 If the consumed API returns a linked response which contains a link to the next
789 response set (page), the Dynamic pollsters can be configured to follow these
790 links and join all linked responses into a single one.
791
792 To enable this behavior the operator will need to configure the parameter
793 `next_sample_url_attribute` that must contain a mapper to the response
794 attribute that contains the link to the next response page. This parameter also
795 supports operations like the others `*_attribute` dynamic pollster's
796 parameters.
797
798 Examples on how to create a pollster to handle linked API responses are
799 presented as follows:
800
801 - Example of a simple linked response:
802
803 - API response:
804
805 .. code-block:: json
806
807 {
808 "server_link": "http://test.com/v1/test-volumes/marker=c3",
809 "servers": [
810 {
811 "volume": [
812 {
813 "name": "a",
814 "tmp": "ra"
815 }
816 ],
817 "id": 1,
818 "name": "a1"
819 },
820 {
821 "volume": [
822 {
823 "name": "b",
824 "tmp": "rb"
825 }
826 ],
827 "id": 2,
828 "name": "b2"
829 },
830 {
831 "volume": [
832 {
833 "name": "c",
834 "tmp": "rc"
835 }
836 ],
837 "id": 3,
838 "name": "c3"
839 }
840 ]
841 }
842
843 - Pollster configuration:
844
845 .. code-block:: yaml
846
847 ---
848
849 - name: "dynamic.linked.response"
850 sample_type: "gauge"
851 unit: "request"
852 value_attribute: "[volume].tmp"
853 url_path: "v1/test-volumes"
854 response_entries_key: "servers"
855 next_sample_url_attribute: "server_link"
856
857 - Example of a complex linked response:
858
859 - API response:
860
861 .. code-block:: json
862
863 {
864 "server_link": [
865 {
866 "href": "http://test.com/v1/test-volumes/marker=c3",
867 "rel": "next"
868 },
869 {
870 "href": "http://test.com/v1/test-volumes/marker=b1",
871 "rel": "prev"
872 }
873 ],
874 "servers": [
875 {
876 "volume": [
877 {
878 "name": "a",
879 "tmp": "ra"
880 }
881 ],
882 "id": 1,
883 "name": "a1"
884 },
885 {
886 "volume": [
887 {
888 "name": "b",
889 "tmp": "rb"
890 }
891 ],
892 "id": 2,
893 "name": "b2"
894 },
895 {
896 "volume": [
897 {
898 "name": "c",
899 "tmp": "rc"
900 }
901 ],
902 "id": 3,
903 "name": "c3"
904 }
905 ]
906 }
907
908 - Pollster configuration:
909
910 .. code-block:: yaml
911
912 ---
913
914 - name: "dynamic.linked.response"
915 sample_type: "gauge"
916 unit: "request"
917 value_attribute: "[volume].tmp"
918 url_path: "v1/test-volumes"
919 response_entries_key: "servers"
920 next_sample_url_attribute: "server_link | filter(lambda v: v.get('rel') == 'next', value) | list(value) | value[0] | value.get('href')"
921
922 OpenStack Dynamic pollsters metadata enrichment with other OpenStack API's data
923 -------------------------------------------------------------------------------
924
925 Sometimes we want/need to add/gather extra metadata for the samples being
926 handled by Ceilometer Dynamic pollsters, such as the project name, domain id,
927 domain name, and other metadata that are not always accessible via the
928 OpenStack component where the sample is gathered.
929
930 For instance, when gathering the status of virtual machines (VMs) from Nova,
931 we only have the `tenant_id`, which must be used as the `project_id`. However,
932 for billing and later invoicing one might need/want the project name, domain
933 id, and other metadata that are available in Keystone (and maybe some others
934 that are scattered over other components). To achieve that, one can use the
935 OpenStack metadata enrichment option. As follows we present an example that
936 shows a dynamic pollster configuration to gather virtual machine (VM) status,
937 and to enrich the data pushed to the storage backend (e.g. Gnocchi) with
938 project name, domain ID, and domain name.
939
940 .. code-block:: yaml
941
942 ---
943
944 - name: "dynamic_pollster.instance.status"
945 next_sample_url_attribute: "server_links | filter(lambda v: v.get('rel') == 'next', value) | list(value) | value[0] | value.get('href') | value.replace('http:', 'https:')"
946 sample_type: "gauge"
947 unit: "server"
948 value_attribute: "status"
949 endpoint_type: "compute"
950 url_path: "/v2.1/servers/detail?all_tenants=true"
951 headers:
952 "Openstack-API-Version": "compute 2.65"
953 project_id_attribute: "tenant_id"
954 metadata_fields:
955 - "status"
956 - "name"
957 - "flavor.vcpus"
958 - "flavor.ram"
959 - "flavor.disk"
960 - "flavor.ephemeral"
961 - "flavor.swap"
962 - "flavor.original_name"
963 - "image | value or { 'id': '' } | value['id']"
964 - "OS-EXT-AZ:availability_zone"
965 - "OS-EXT-SRV-ATTR:host"
966 - "user_id"
967 - "tags | ','.join(value)"
968 - "locked"
969 value_mapping:
970 ACTIVE: "1"
971 default_value: 0
972 metadata_mapping:
973 "OS-EXT-AZ:availability_zone": "dynamic_availability_zone"
974 "OS-EXT-SRV-ATTR:host": "dynamic_host"
975 "flavor.original_name": "dynamic_flavor_name"
976 "flavor.vcpus": "dynamic_flavor_vcpus"
977 "flavor.ram": "dynamic_flavor_ram"
978 "flavor.disk": "dynamic_flavor_disk"
979 "flavor.ephemeral": "dynamic_flavor_ephemeral"
980 "flavor.swap": "dynamic_flavor_swap"
981 "image | value or { 'id': '' } | value['id']": "dynamic_image_ref"
982 "name": "dynamic_display_name"
983 "locked": "dynamic_locked"
984 "tags | ','.join(value)": "dynamic_tags"
985 extra_metadata_fields_cache_seconds: 3600
986 extra_metadata_fields_skip:
987 - value: '1'
988 metadata:
989 dynamic_flavor_vcpus: 4
990 - value: '1'
991 metadata:
992 dynamic_flavor_vcpus: 2
993 extra_metadata_fields:
994 - name: "project_name"
995 endpoint_type: "identity"
996 url_path: "'/v3/projects/' + str(sample['project_id'])"
997 headers:
998 "Openstack-API-Version": "identity latest"
999 value: "name"
1000 extra_metadata_fields_cache_seconds: 1800 # overriding the default cache policy
1001 metadata_fields:
1002 - id
1003 - name: "domain_id"
1004 endpoint_type: "identity"
1005 url_path: "'/v3/projects/' + str(sample['project_id'])"
1006 headers:
1007 "Openstack-API-Version": "identity latest"
1008 value: "domain_id"
1009 metadata_fields:
1010 - id
1011 - name: "domain_name"
1012 endpoint_type: "identity"
1013 url_path: "'/v3/domains/' + str(extra_metadata_captured['domain_id'])"
1014 headers:
1015 "Openstack-API-Version": "identity latest"
1016 value: "name"
1017 metadata_fields:
1018 - id
1019 - name: "operating-system"
1020 host_command: "'get-vm --vm-name ' + str(extra_metadata_by_name['project_name']['metadata']['id'])"
1021 value: "os"
1022
1023
1024 The above example can be used to gather and persist in the backend the
1025 status of VMs. It will persist `1` in the backend as a measure for every
1026 collecting period if the VM's status is `ACTIVE`, and `0` otherwise. This is
1027 quite useful to create hashmap rating rules for running VMs in CloudKitty.
1028 Then, to enrich the resource in the storage backend, we are adding extra
1029 metadata that are collected in Keystone and in the local host via the
1030 `extra_metadata_fields` options. If you have multiples `extra_metadata_fields`
1031 defining the same `metadata_field`, the last not `None` metadata value will
1032 be used.
1033
1034 To operate values in the `extra_metadata_fields`, you can access 3 local
1035 variables:
1036
1037 * ``sample``: it is a dictionary which holds the current data of the root
1038 sample. The root sample is the final sample that will be persisted in the
1039 configured storage backend.
1040
1041 * ``extra_metadata_captured``: it is a dictionary which holds the current
1042 data of all `extra_metadata_fields` processed before this one.
1043 If you have multiples `extra_metadata_fields` defining the same
1044 `metadata_field`, the last not `None` metadata value will be used.
1045
1046 * ``extra_metadata_by_name``: it is a dictionary which holds the data of
1047 all `extra_metadata_fields` processed before this one. No data is
1048 overwritten in this variable. To access an specific `extra_metadata_field`
1049 using this variable, you can do
1050 `extra_metadata_by_name['<extra_metadata_field_name>']['value']` to get
1051 its value, or
1052 `extra_metadata_by_name['<extra_metadata_field_name>']['metadata']['<metadata>']`
1053 to get its metadata.
1054
1055 The metadata enrichment feature has the following options:
1056
1057 * ``extra_metadata_fields_cache_seconds``: optional parameter. Defines the
1058 extra metadata request's response cache. Some requests, such as the ones
1059 executed against Keystone to retrieve extra metadata are rather static.
1060 Therefore, one does not need to constantly re-execute the request. That
1061 is the reason why we cache the response of such requests. By default the
1062 cache time to live (TTL) for responses is `3600` seconds. However, this
1063 value can be increased of decreased.
1064
1065 * ``extra_metadata_fields``: optional parameter. This option is a list of
1066 objects or a single one, where each one of its elements is an
1067 dynamic pollster configuration set. Each one of the extra metadata
1068 definition can have the same options defined in the dynamic pollsters,
1069 including the `extra_metadata_fields` option, so this option is a
1070 multi-level option. When defined, the result of the collected data will
1071 be merged in the final sample resource metadata. If some of the required
1072 dynamic pollster configuration is not set in the `extra_metadata_fields`,
1073 will be used the parent pollster configuration, except the `name`.
1074
1075 * ``extra_metadata_fields_skip``: optional parameter. This option is a list
1076 of objects or a single one, where each one of its elements is a set of
1077 key/value pairs. When defined, if any set of key/value pairs is a subset
1078 of the collected sample, then the extra_metadata_fields gathering of this
1079 sample will be skipped.
1080
1081