Fix docs
[barometer.git] / docs / release / userguide / collectd.ves.userguide.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. http://creativecommons.org/licenses/by/4.0
3 .. (c) OPNFV, Intel Corporation and others.
4
5 ==========================
6 VES Application User Guide
7 ==========================
8
9 The Barometer repository contains a python based application for VES (VNF Event
10 Stream) which receives the `collectd`_ specific metrics via `Kafka`_ bus,
11 normalizes the metric data into the VES message format and sends it into the VES
12 collector.
13
14 The application currently supports pushing platform relevant metrics through the
15 additional measurements field for VES.
16
17 Collectd has a ``write_kafka`` plugin that sends collectd metrics and values to
18 a Kafka Broker. The VES message formatting application, ves_app.py, receives metrics from
19 the Kafka broker, normalises the data to VES message format for forwarding to VES collector.
20 The VES message formatting application will be simply referred to as the "VES application"
21 within this userguide
22
23 The VES application can be run in host mode (baremetal), hypervisor mode (on a host with a hypervisor
24 and VMs running) or guest mode(within a VM). The main software blocks that are required to run the
25 VES application demo are:
26
27         1. Kafka
28         2. Collectd
29         3. VES Application
30         4. VES Collector
31
32 Install Kafka Broker
33 --------------------
34
35 1. Dependencies: install JAVA & Zookeeper.
36
37    Ubuntu 16.04:
38
39     .. code:: bash
40
41         $ sudo apt-get install default-jre
42         $ sudo apt-get install zookeeperd
43         $ sudo apt-get install python-pip
44
45    CentOS:
46
47     .. code:: bash
48
49         $ sudo yum update -y
50         $ sudo yum install java-1.8.0-openjdk
51         $ sudo yum install epel-release
52         $ sudo yum install python-pip
53         $ sudo yum install zookeeper
54         $ sudo yum install telnet
55         $ sudo yum install wget
56
57     .. note:: You may need to add the repository that contains zookeeper.
58       To do so, follow the step below and try to install `zookeeper` again
59       using steps above. Otherwise, skip next step.
60
61     .. code:: bash
62
63         $ sudo yum install
64         https://archive.cloudera.com/cdh5/one-click-install/redhat/7/x86_64/cloudera-cdh-5-0.x86_64.rpm
65
66     Start zookeeper:
67
68     .. code:: bash
69
70         $ sudo zookeeper-server start
71
72     if you get the error message like ``ZooKeeper data directory is missing at /var/lib/zookeeper``
73     during the start of zookeeper, initialize zookeeper data directory using
74     the command below and start zookeeper again, otherwise skip the next step.
75
76     .. code:: bash
77
78        $ sudo /usr/lib/zookeeper/bin/zkServer-initialize.sh
79         No myid provided, be sure to specify it in /var/lib/zookeeper/myid if using non-standalone
80
81 2. Test if Zookeeper is running as a daemon.
82
83     .. code:: bash
84
85         $ telnet localhost 2181
86
87     Type 'ruok' & hit enter.
88     Expected response is 'imok' which means that Zookeeper is up running.
89
90 3. Install Kafka
91
92     .. note:: VES doesn't work with version 0.9.4 of kafka-python. The
93         recommended/tested version is 1.3.3.
94
95     .. code:: bash
96
97         $ sudo pip install kafka-python
98         $ wget "https://archive.apache.org/dist/kafka/1.0.0/kafka_2.11-1.0.0.tgz"
99         $ tar -xvzf kafka_2.11-1.0.0.tgz
100         $ sed -i -- 's/#delete.topic.enable=true/delete.topic.enable=true/' kafka_2.11-1.0.0/config/server.properties
101         $ sudo nohup kafka_2.11-1.0.0/bin/kafka-server-start.sh \
102           kafka_2.11-1.0.0/config/server.properties > kafka_2.11-1.0.0/kafka.log 2>&1 &
103
104     .. note:: If Kafka server fails to start, please check if the platform IP
105         address is associated with the hostname in the static host lookup
106         table. If it doesn't exist, use the following command to add it.
107
108     .. code:: bash
109
110         $ echo "$(ip route get 8.8.8.8 | awk '{print $NF; exit}') $HOSTNAME" | sudo tee -a /etc/hosts
111
112 4. Test the Kafka Installation
113
114     To test if the installation worked correctly there are two scripts, producer and consumer scripts.
115     These will allow you to see messages pushed to broker and receive from broker.
116
117     Producer (Publish "Hello World"):
118
119     .. code:: bash
120
121         $ echo "Hello, World" | kafka_2.11-1.0.0/bin/kafka-console-producer.sh \
122           --broker-list localhost:9092 --topic TopicTest > /dev/null
123
124     Consumer (Receive "Hello World"):
125
126     .. code:: bash
127
128         $ kafka_2.11-1.0.0/bin/kafka-console-consumer.sh --zookeeper \
129           localhost:2181 --topic TopicTest --from-beginning --max-messages 1 --timeout-ms 3000
130
131
132 Install collectd
133 ----------------
134
135 Install development tools:
136
137    Ubuntu 16.04:
138
139     .. code:: bash
140
141         $ sudo apt-get install build-essential bison autotools-dev autoconf
142         $ sudo apt-get install pkg-config flex libtool
143
144    CentOS:
145
146     .. code:: bash
147
148         $ sudo yum group install 'Development Tools'
149
150 .. The libkafka installed via the package manager may not work with collectd
151    (due to compilation issue). Thus, it's recommented to use the library installed
152    from sources using latest stable version of libkafka.
153
154 Install Apache Kafka C/C++ client library:
155
156 .. code:: bash
157
158     $ git clone https://github.com/edenhill/librdkafka.git ~/librdkafka
159     $ cd ~/librdkafka
160     $ git checkout -b v0.9.5 v0.9.5
161     $ ./configure --prefix=/usr
162     $ make
163     $ sudo make install
164
165 Build collectd with Kafka support:
166
167 .. code:: bash
168
169     $ git clone https://github.com/collectd/collectd.git ~/collectd
170     $ cd ~/collectd
171     $ ./build.sh
172     $ ./configure --with-librdkafka=/usr --without-perl-bindings --enable-perl=no
173     $ make && sudo make install
174
175 .. note::
176
177    If installing from git repository ``collectd.conf`` configuration file will be located in
178    directory ``/opt/collectd/etc/``. If installing from via a package manager ``collectd.conf``
179    configuration file will be located in directory ``/etc/collectd/``
180
181 Configure and start collectd. Modify Collectd configuration file ``collectd.conf``
182 as following:
183
184 - Within a VM: `Setup VES application (guest mode)`_
185 - On Host with VMs: `Setup VES application (hypervisor mode)`_
186 - No Virtualization: `Setup VES application (host mode)`_
187
188 Start collectd process as a service as described in :ref:`install-collectd-as-a-service`.
189
190 Setup VES application (guest mode)
191 ----------------------------------
192
193 In this mode Collectd runs from within a VM and sends metrics to the VES collector.
194
195 .. figure:: ves-app-guest-mode.png
196
197     VES guest mode setup
198
199 Install dependencies:
200
201 .. code:: bash
202
203     $ sudo pip install pyyaml python-kafka
204
205 Clone Barometer repo and start the VES application:
206
207 .. code:: bash
208
209     $ git clone https://gerrit.opnfv.org/gerrit/barometer
210     $ cd barometer/3rd_party/collectd-ves-app/ves_app
211     $ nohup python ves_app.py --events-schema=guest.yaml --config=ves_app_config.conf > ves_app.stdout.log &
212
213
214 Modify Collectd configuration file ``collectd.conf`` as following:
215
216 .. include:: collectd-ves-guest.conf
217       :code: bash
218
219
220 Start collectd process as a service as described in :ref:`install-collectd-as-a-service`.
221
222 .. note::
223
224     The above configuration is used for a localhost. The VES application can be
225     configured to use remote VES collector and remote Kafka server. To do
226     so, the IP addresses/host names needs to be changed in ``collector.conf``
227     and ``ves_app_config.conf`` files accordingly.
228
229
230 Setup VES application (hypervisor mode)
231 ----------------------------------------
232
233 This mode is used to collect hypervisor statistics about guest VMs and to send
234 those metrics into the VES collector. Also, this mode collects host statistics
235 and send them as part of the guest VES message.
236
237 .. figure:: ves-app-hypervisor-mode.png
238
239     VES hypervisor mode setup
240
241 Running the VES in hypervisor mode looks like steps described in
242 `Setup VES application (guest mode)`_ but with the following exceptions:
243
244 - The ``hypervisor.yaml`` configuration file should be used instead of ``guest.yaml``
245   file when VES application is running.
246
247 - Collectd should be running on hypervisor machine only.
248
249 - Addition ``libvirtd`` dependencies needs to be installed on  where
250   collectd daemon is running. To install those dependencies, see :ref:`virt-plugin`
251   section of Barometer user guide.
252
253 - The next (minimum) configuration needs to be provided to collectd to be able
254   to generate the VES message to VES collector.
255
256 .. note::
257    At least one VM instance should be up and running by hypervisor on the host.
258
259 .. include:: collectd-ves-hypervisor.conf
260       :code: bash
261
262
263 Start collectd process as a service as described in :ref:`install-collectd-as-a-service`.
264
265 .. note::
266
267     The above configuration is used for a localhost. The VES application can be
268     configured to use remote VES collector and remote Kafka server. To do
269     so, the IP addresses/host names needs to be changed in ``collector.conf``
270     and ``ves_app_config.conf`` files accordingly.
271
272
273 .. note:: The list of the plugins can be extented depends on your needs.
274
275
276 Setup VES application (host mode)
277 ----------------------------------
278
279 This mode is used to collect platform wide metrics and to send those metrics into the VES collector.
280 It is most suitable for running within a baremetal platform.
281
282 Install dependencies:
283
284 .. code:: bash
285
286     $ sudo pip install pyyaml
287
288 Clone Barometer repo and start the VES application:
289
290 .. code:: bash
291
292     $ git clone https://gerrit.opnfv.org/gerrit/barometer
293     $ cd barometer/3rd_party/collectd-ves-app/ves_app
294     $ nohup python ves_app.py --events-schema=host.yaml --config=ves_app_config.conf > ves_app.stdout.log &
295
296
297 .. figure:: ves-app-host-mode.png
298
299     VES Native mode setup
300
301 Modify collectd configuration file ``collectd.conf`` as following:
302
303 .. include:: collectd-ves-host.conf
304                     :code: bash
305
306 Start collectd process as a service as described in :ref:`install-collectd-as-a-service`.
307
308 .. note::
309
310     The above configuration is used for a localhost. The VES application can be
311     configured to use remote VES collector and remote Kafka server. To do
312     so, the IP addresses/host names needs to be changed in ``collector.conf``
313     and ``ves_app_config.conf`` files accordingly.
314
315
316 .. note:: The list of the plugins can be extented depends on your needs.
317
318
319
320 Setup VES Test Collector
321 ------------------------
322
323 .. note:: Test Collector setup is required only for VES application testing
324    purposes.
325
326 Install dependencies:
327
328 .. code:: bash
329
330     $ sudo pip install jsonschema
331
332 Clone VES Test Collector:
333
334 .. code:: bash
335
336     $ git clone https://github.com/att/evel-test-collector.git ~/evel-test-collector
337
338 Modify VES Test Collector config file to point to existing log directory and
339 schema file:
340
341 .. code:: bash
342
343     $ sed -i.back 's/^\(log_file[ ]*=[ ]*\).*/\1collector.log/' ~/evel-test-collector/config/collector.conf
344     $ sed -i.back 's/^\(schema_file[ ]*=.*\)event_format_updated.json$/\1CommonEventFormat.json/' ~/evel-test-collector/config/collector.conf
345
346 Start VES Test Collector:
347
348 .. code:: bash
349
350     $ cd ~/evel-test-collector/code/collector
351     $ nohup python ./collector.py --config ../../config/collector.conf > collector.stdout.log &
352
353
354 VES application configuration description
355 -----------------------------------------
356
357 **Details of the Vendor Event Listener REST service**
358
359 REST resources are defined with respect to a ``ServerRoot``::
360
361     ServerRoot = https://{Domain}:{Port}/{optionalRoutingPath}
362
363 REST resources are of the form::
364
365     {ServerRoot}/eventListener/v{apiVersion}`
366     {ServerRoot}/eventListener/v{apiVersion}/{topicName}`
367     {ServerRoot}/eventListener/v{apiVersion}/eventBatch`
368
369 Within the VES directory (``3rd_party/collectd-ves-app/ves_app``) there is a
370 configuration file called ``ves_app_conf.conf``. The description of the
371 configuration options are described below:
372
373 **Domain** *"host"*
374   VES domain name. It can be IP address or hostname of VES collector
375   (default: ``127.0.0.1``)
376
377 **Port** *port*
378   VES port (default: ``30000``)
379
380 **Path** *"path"*
381   Used as the "optionalRoutingPath" element in the REST path (default: ``vendor_event_listener``)
382
383 **Topic** *"path"*
384   Used as the "topicName" element in the REST  path (default: ``example_vnf``)
385
386 **UseHttps** *true|false*
387   Allow application to use HTTPS instead of HTTP (default: ``false``)
388
389 **Username** *"username"*
390   VES collector user name (default: empty)
391
392 **Password** *"passwd"*
393   VES collector password (default: empty)
394
395 **SendEventInterval** *interval*
396   This configuration option controls how often (sec) collectd data is sent to
397   Vendor Event Listener (default: ``20``)
398
399 **ApiVersion** *version*
400   Used as the "apiVersion" element in the REST path (default: ``3``)
401
402 **KafkaPort** *port*
403   Kafka Port (Default ``9092``)
404
405 **KafkaBroker** *host*
406   Kafka Broker domain name. It can be an IP address or hostname of local or remote server
407   (default: ``localhost``)
408
409
410 VES YAML configuration format
411 -----------------------------
412
413 The format of the VES message is generated by the VES application based on the
414 YAML schema configuration file provided by user via ``--events-schema``
415 command-line option of the application.
416
417 .. note:: Use ``--help`` option of VES application to see the
418     description of all available options
419
420 .. note:: The detailed installation guide of the VES application is described in
421     the `VES Application User Guide`_.
422
423 The message defined by YAML schema should correspond to format defined in
424 `VES shema definition`_.
425
426 .. warning:: This section doesn't explain the YAML language itself, so the
427     knowledge of the YAML language is required before continue reading it!
428
429 Since, the VES message output is a JSON format, it's recommended to understand
430 how YAML document is converted to JSON before starting to create a new YAML
431 definition for the VES. E.g.:
432
433 The following YAML document:
434
435 .. code:: yaml
436
437     ---
438     additionalMeasurements:
439       plugin: somename
440       instance: someinstance
441
442 will be converted to JSON like this:
443
444 .. code:: json
445
446     {
447       "additionalMeasurements": {
448         "instance": "someinstance",
449         "plugin": "somename"
450       }
451     }
452
453 .. note:: The `YAML syntax` section of `PyYAML documentation`_ can be used
454     as a reference for this.
455
456
457 VES message types
458 -----------------
459
460 The VES agent can generate two type of messages which are sent to the VES
461 collector. Each message type must be specified in the YAML configuration file
462 using a specific YAML tag.
463
464 Measurements
465   This type is used to send a message defined in YAML configuration to the VES
466   collector with a specified interval (default is 20 sec and it's configurable
467   via command line option of the application). This type can be specified in
468   the configuration using ``!Measurements`` tag. For instance:
469
470   .. code:: yaml
471
472       ---
473       # My comments
474       My Host Measurements: !Measurements
475         ... # message definition
476
477 Events
478   This type is used to send a message defined in YAML configuration to the VES
479   collector when collectd notification is received from Kafka bus (collectd
480   ``write_kafka`` plugin). This type can be specified in the configuration
481   using ``!Events`` tag. For instance:
482
483   .. code:: yaml
484
485       ---
486       # My comments
487       My Events: !Events
488         ... # event definition
489
490
491 Collectd metrics in VES
492 -----------------------
493
494 The VES application caches collectd metrics received via Kafka bus. The data
495 is stored in a table format. It's important to know it before mapping collectd
496 metric values to message defined in YAML configuration file.
497
498 VES collectd metric cache example:
499
500 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
501 |   host    |  plugin   |  plugin_instance   |  type     |  type_instace  |       time        | value  | ds_name | interval |
502 +===========+===========+====================+===========+================+===================+========+=========+==========+
503 | localhost | cpu       |                    | percent   | user           | 1509535512.30567  | 16     | value   | 10       |
504 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
505 | localhost | memory    |                    | memory    | free           | 1509535573.448014 | 798456 | value   | 10       |
506 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
507 | localhost | interface |                    | eth0      | if_packets     | 1509544183.956496 | 253    | rx      | 10       |
508 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
509 | 7ec333e7  | virt      | Ubuntu-12.04.5-LTS | percent   | virt_cpu_total | 1509544402.378035 | 0.2    | value   | 10       |
510 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
511 | 7ec333e7  | virt      | Ubuntu-12.04.5-LTS | memory    | rss            | 1509544638.55119  | 123405 | value   | 10       |
512 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
513 | 7ec333e7  | virt      | Ubuntu-12.04.5-LTS | if_octets | vnet1          | 1509544646.27108  | 67     | tx      | 10       |
514 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
515 | cc659a52  | virt      | Ubuntu-16.04       | percent   | virt_cpu_total | 1509544745.617207 | 0.3    | value   | 10       |
516 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
517 | cc659a52  | virt      | Ubuntu-16.04       | memory    | rss            | 1509544754.329411 | 4567   | value   | 10       |
518 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
519 | cc659a52  | virt      | Ubuntu-16.04       | if_octets | vnet0          | 1509544760.720381 | 0      | rx      | 10       |
520 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
521
522 It's possible from YAML configuration file to refer to any field of any row of
523 the table via special YAML tags like ``ValueItem`` or ``ArrayItem``. See the
524 `Collectd metric reference`_ reference for more details.
525
526 .. note:: The `collectd data types file`_ contains map of ``type`` to
527     ``ds_name`` field. It can be used to get possible value for ``ds_name``
528     field. See the `collectd data types description`_ for more details on
529     collectd data types.
530
531
532 Aging of collectd metric
533 ~~~~~~~~~~~~~~~~~~~~~~~~
534
535 If the metric will not be updated by the collectd during the double metric
536 interval time, it will be removed (aged) from VES internal cache.
537
538
539 VES YAML references
540 -------------------
541
542 There are four type of references supported by the YAML format: System,
543 Config, Collectd metric and Collectd notification. The format of the reference
544 is the following:
545
546 .. code:: yaml
547
548     "{<ref type>.<attribute name>}"
549
550 .. note:: Possible values for ``<ref type>`` and ``<attribute name>`` are
551     described in farther sections.
552
553
554 System reference
555 ~~~~~~~~~~~~~~~~
556
557 This reference is used to get system statistics like time, date etc. The system
558 reference (``<ref type>`` = ``system``) can be used in any place of the YAML
559 configuration file. This type of reference provides the following attributes:
560
561 ``hostname``
562   The name of the host where VES application is running.
563
564 ``id``
565   Unique ID during VES application runtime.
566
567 ``time``
568   Current time in seconds since the Epoch. For example ``1509641411.631951``.
569
570 ``date``
571   Current date in ISO 8601 format, ``YYYY-MM-DD``. For instance ``2017-11-02``.
572
573
574 For example:
575
576 .. code:: yaml
577
578     Date: "{system.date}"
579
580
581 Config reference
582 ~~~~~~~~~~~~~~~~
583
584 This reference is used to get VES configuration described in `VES application
585 configuration description`_ sectoin. The reference (``<ref type>`` = ``config``)
586 can be used in any place of the YAML configuration file. This type of reference
587 provides the following attributes:
588
589 ``interval``
590   Measurements dispatch interval. It referenses to ``SendEventInterval``
591   configuration of the VES application.
592
593
594 For example:
595
596 .. code:: yaml
597
598     Interval: "{config.interval}"
599
600
601 Collectd metric reference
602 ~~~~~~~~~~~~~~~~~~~~~~~~~
603
604 This reference is used to get the attribute value of collectd metric from the
605 VES cache. The reference (``<ref type>`` = ``vl``) can be used ONLY inside
606 ``Measurements``, ``ValueItem`` and ``ArrayItem`` tags. Using the reference
607 inside a helper tag is also allowed if the helper tag is located inside the
608 tag where the reference is allowed (e.g.: ``ArrayItem``). The
609 ``<attribute name>`` name corresponds to the table field name described in
610 `Collectd metrics in VES`_ section. For example:
611
612 .. code:: yaml
613
614     name: "{vl.type}-{vl.type_instance}"
615
616
617 Collectd notification reference
618 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
619
620 This reference is used to get the attribute value of received collectd
621 notification. The reference (``<ref type>`` = ``n``) can be used ONLY inside
622 ``Events`` tag. Using the reference inside a helper tag is also allowed if
623 the helper tag is located inside the ``Events`` tag. This type of reference
624 provides the following attributes:
625
626 ``host``
627   The hostname of received collectd notification.
628
629 ``plugin``
630   The plugin name of received collectd notification.
631
632 ``plugin_instance``
633   The plugin instance of the received collectd notification.
634
635 ``type``
636   The type name of the received collectd notification.
637
638 ``type_instance``
639   The type instance of the received collectd notification.
640
641 ``severity``
642   The severity of the received collectd notification.
643
644 ``message``
645   The message of the received collectd notification.
646
647
648 .. note:: The exact value for each attribute depends on the collectd plugin
649   which may generate the notification. Please refer to the
650   `collectd plugin description`_ document to get more details on the specific
651   collectd plugin.
652
653 YAML config example:
654
655 .. code:: yaml
656
657     sourceId: "{n.plugin_instance}"
658
659
660 Collectd metric mapping YAML tags
661 ---------------------------------
662
663 This section describes the YAML tags used to map collectd metric values in the
664 YAML configuration file.
665
666
667 Measurements tag
668 ~~~~~~~~~~~~~~~~
669
670 This tag is a YAML map which is used to define the VES measurement message. It's
671 allowed to be used multiple times in the document (e.g.: you can define multiple
672 VES messages in one YAML document). This tag works in the same way as `ArrayItem
673 tag`_ does and all keys have the same description/rules.
674
675
676 ValueItem tag
677 ~~~~~~~~~~~~~
678
679 This tag is used to select a collectd metric and get its attribute value using
680 `Collectd metric reference`_. The type of this tag is a YAML array of maps with
681 the possible keys described below.
682
683 ``SELECT`` (required)
684   Is a YAML map which describes the select metric criteria. Each key name of the
685   map must correspond to the table field name described in `Collectd metrics in VES`_
686   section.
687
688 ``VALUE`` (optional)
689   Describes the value to be assigned. If not provided, the default
690   ``!Number "{vl.value}"`` expression is used.
691
692 ``DEFAULT`` (optional)
693   Describes the default value which will be assigned if no metric is selected
694   by ``SELECT`` criteria.
695
696
697 ValueItem tag description example:
698
699 .. code:: yaml
700
701     memoryFree: !ValueItem
702       - SELECT:
703           plugin: memory
704           type: memory
705           type_instance: rss
706       - VALUE: !Bytes2Kibibytes "{vl.value}"
707       - DEFAULT: 0
708
709 The tag process workflow is described on the figure below.
710
711 .. figure:: value-item-parse-workflow.png
712
713     YAML ValueItem tag process workflow
714
715
716 ArrayItem tag
717 ~~~~~~~~~~~~~
718
719 This tag is used to select a list of collectd metrics and generate a YAML array
720 of YAML items described by ``ITEM-DESC`` key. If no collectd metrics are
721 selected by the given criteria, the empty array will be returned.
722
723 ``SELECT`` (optional)
724   Is a YAML map which describes the select metrics criteria. Each key name of
725   the map must correspond to the table field name described in `Collectd
726   metrics in VES`_ section. The value of the key may be regular expression. To
727   enable regular expression in the value, the YAML string containing ``/`` char
728   at the beginning and at the end should be used. For example:
729
730   .. code:: yaml
731
732       plugin: "/^(?!virt).*$/" # selected all metrics except ``virt`` plugin
733
734   The VES application uses the python RE library to work with regular
735   expression specified in the YAML configuration. Please refer to `python
736   regular expression syntax`_ documentation for more details on a syntax
737   used by the VES.
738
739   Multiple ``SELECT`` keys are allowed by the tag. If nor ``SELECT`` or
740   ``INDEX-KEY`` key is specified, the VES error is generated.
741
742 ``INDEX-KEY`` (optional)
743   Is a YAML array which describes the unique fields to be selected by the tag.
744   Each element of array is a YAML string which should be one of the table field
745   name described in `Collectd metrics in VES`_ section. Please note, if this
746   key is used, only fields specified by the key can be used as a collectd
747   reference in the ``ITEM-DESC`` key.
748
749 ``ITEM-DESC`` (required)
750   Is a YAML map which describes each element of the YAML array generated by
751   the tag. Using ``ArrayItem`` tags and other `Helper YAML tags`_ are also
752   allowed in the definition of the key.
753
754 In the example below, the ArrayItem tag is used to generate an array of
755 ``ITEM-DESC`` items for each collectd metrics except ``virt`` plugin with
756 unique ``plugin``, ``plugin_instance`` attribute values.
757
758 .. code:: yaml
759
760     Measurements: !ArrayItem
761       - SELECT:
762           plugin: "/^(?!virt).*$/"
763       - INDEX-KEY:
764           - plugin
765           - plugin_instance
766       - ITEM-DESC:
767           name: !StripExtraDash "{vl.plugin}-{vl.plugin_instance}"
768
769 The tag process workflow is described on the figure below.
770
771 .. figure:: array-item-parse-workflow.png
772
773     YAML ArrayItem tag process workflow
774
775
776 Collectd event mapping YAML tags
777 --------------------------------
778
779 This section describes the YAML tags used to map the collectd notification to
780 the VES event message in the YAML configuration file.
781
782
783 Events tag
784 ~~~~~~~~~~
785
786 This tag is a YAML map which is used to define the VES event message. It's
787 allowed to be used multiple times in the document (e.g.: you can map multiple
788 collectd notification into VES message in one YAML document). The possible
789 keys of the tag are described below.
790
791 ``CONDITION`` (optional)
792   Is a YAML map which describes the select metric criteria. Each key name of
793   the map must correspond to the name of attribute provided by `Collectd
794   notification reference`_. If no such key provided, any collectd notification
795   will map the defined YAML message.
796
797 ``ITEM-DESC`` (required)
798   Is a YAML map which describes the message generated by this tag. Only `Helper
799   YAML tags`_ are allowed in the definition of the key.
800
801 The example of the VES event message which will be generate by the VES
802 application when collectd notification of the ``virt`` plugin is triggered
803 is described below.
804
805 .. code:: yaml
806
807     ---
808     Virt Event: !Events
809       - ITEM-DESC:
810           event:
811             commonEventHeader:
812               domain: fault
813               eventType: Notification
814               sourceId: &event_sourceId "{n.plugin_instance}"
815               sourceName: *event_sourceId
816               lastEpochMicrosec: !Number "{n.time}"
817               startEpochMicrosec: !Number "{n.time}"
818             faultFields:
819               alarmInterfaceA: !StripExtraDash "{n.plugin}-{n.plugin_instance}"
820               alarmCondition: "{n.severity}"
821               faultFieldsVersion: 1.1
822       - CONDITION:
823           plugin: virt
824
825
826 Helper YAML tags
827 ----------------
828
829 This section describes the YAML tags used as utilities for formatting the output
830 message. The YAML configuration process workflow is described on the figure
831 below.
832
833 .. figure:: parse-work-flow.png
834
835     YAML configuration process workflow
836
837
838 Convert string to number tag
839 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
840
841 The ``!Number`` tag is used in YAML configuration file to convert string value into
842 the number type. For instance:
843
844 .. code:: yaml
845
846     lastEpochMicrosec: !Number "3456"
847
848 The output of the tag will be the JSON number.
849
850 .. code:: json
851
852     {
853       lastEpochMicrosec: 3456
854     }
855
856
857 Convert bytes to Kibibytes tag
858 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
859
860 The ``!Bytes2Kibibytes`` tag is used in YAML configuration file to convert
861 bytes into kibibytes (1 kibibyte = 1024 bytes). For instance:
862
863 .. code:: yaml
864
865     memoryConfigured: !Bytes2Kibibytes 4098
866     memoryConfigured: !Bytes2Kibibytes "1024"
867
868 The output of the tag will be the JSON number.
869
870 .. code:: json
871
872     {
873       memoryConfigured: 4
874       memoryConfigured: 1
875     }
876
877
878 Convert one value to another tag
879 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
880
881 The ``!MapValue`` tag is used in YAML configuration file to map one value
882 into another value defined in the configuration. For instance:
883
884 .. code:: yaml
885
886     Severity: !MapValue
887       VALUE: Failure
888       TO:
889         Failure: Critical
890         Error: Warnign
891
892 The output of the tag will be the mapped value.
893
894 .. code:: json
895
896     {
897       Severity: Critical
898     }
899
900
901 Strip extra dash tag
902 ~~~~~~~~~~~~~~~~~~~~
903
904 The ``!StripExtraDash`` tag is used in YAML configuration file to strip extra
905 dashes in the string (dashes at the beginning, at the end and double dashes).
906 For example:
907
908 .. code:: yaml
909
910     name: !StripExtraDash string-with--extra-dashes-
911
912 The output of the tag will be the JSON string with extra dashes removed.
913
914 .. code:: json
915
916     {
917       name: string-with-extra-dashes
918     }
919
920
921 Limitations
922 -----------
923
924 #. Only one document can be defined in the same YAML configuration file.
925
926 #. The collectd notification is not supported by `Kafka collectd plugin`_. Due to
927    this limitation, the collectd notifications cannot be received by the VES
928    application and the defined YAML event will not be generated and sent to the
929    VES collector. Please note, that VES YAML format already supports the events
930    definition and the format is descibed in the document.
931
932
933 .. _collectd: http://collectd.org/
934 .. _Kafka: https://kafka.apache.org/
935 .. _`VES`: https://wiki.opnfv.org/display/fastpath/VES+plugin+updates
936 .. _`VES shema definition`: https://gerrit.onap.org/r/gitweb?p=demo.git;a=tree;f=vnfs/VES5.0/evel/evel-test-collector/docs/att_interface_definition;hb=refs/heads/master
937 .. _`PyYAML documentation`: https://pyyaml.org/wiki/PyYAMLDocumentation
938 .. _`collectd plugin description`: https://github.com/collectd/collectd/blob/master/src/collectd.conf.pod
939 .. _`collectd data types file`: https://github.com/collectd/collectd/blob/master/src/types.db
940 .. _`collectd data types description`: https://github.com/collectd/collectd/blob/master/src/types.db.pod
941 .. _`python regular expression syntax`: https://docs.python.org/2/library/re.html#regular-expression-syntax
942 .. _`Kafka collectd plugin`: https://collectd.org/wiki/index.php/Plugin:Write_Kafka