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