c524a6e09c7c8f8e15212475ce9da592602c76ee
[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=yaml/host.yaml --config=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 .. _Setup VES Test Collector:
321
322 Setup VES Test Collector
323 ------------------------
324
325 .. note:: Test Collector setup is required only for VES application testing
326    purposes.
327
328 Install dependencies:
329
330 .. code:: bash
331
332     $ sudo pip install jsonschema
333
334 Clone VES Test Collector:
335
336 .. code:: bash
337
338     $ git clone https://github.com/att/evel-test-collector.git ~/evel-test-collector
339
340 Modify VES Test Collector config file to point to existing log directory and
341 schema file:
342
343 .. code:: bash
344
345     $ sed -i.back 's/^\(log_file[ ]*=[ ]*\).*/\1collector.log/' ~/evel-test-collector/config/collector.conf
346     $ sed -i.back 's/^\(schema_file[ ]*=.*\)event_format_updated.json$/\1CommonEventFormat.json/' ~/evel-test-collector/config/collector.conf
347
348 Start VES Test Collector:
349
350 .. code:: bash
351
352     $ cd ~/evel-test-collector/code/collector
353     $ nohup python ./collector.py --config ../../config/collector.conf > collector.stdout.log &
354
355
356 VES application configuration description
357 -----------------------------------------
358
359 **Details of the Vendor Event Listener REST service**
360
361 REST resources are defined with respect to a ``ServerRoot``::
362
363     ServerRoot = https://{Domain}:{Port}/{optionalRoutingPath}
364
365 REST resources are of the form::
366
367     {ServerRoot}/eventListener/v{apiVersion}`
368     {ServerRoot}/eventListener/v{apiVersion}/{topicName}`
369     {ServerRoot}/eventListener/v{apiVersion}/eventBatch`
370
371 Within the VES directory (``3rd_party/collectd-ves-app/ves_app/config``) there is a
372 configuration file called ``ves_app_conf.conf``. The description of the
373 configuration options are described below:
374
375 **Domain** *"host"*
376   VES domain name. It can be IP address or hostname of VES collector
377   (default: ``127.0.0.1``)
378
379 **Port** *port*
380   VES port (default: ``30000``)
381
382 **Path** *"path"*
383   Used as the "optionalRoutingPath" element in the REST path (default: ``vendor_event_listener``)
384
385 **Topic** *"path"*
386   Used as the "topicName" element in the REST  path (default: ``example_vnf``)
387
388 **UseHttps** *true|false*
389   Allow application to use HTTPS instead of HTTP (default: ``false``)
390
391 **Username** *"username"*
392   VES collector user name (default: empty)
393
394 **Password** *"passwd"*
395   VES collector password (default: empty)
396
397 **SendEventInterval** *interval*
398   This configuration option controls how often (sec) collectd data is sent to
399   Vendor Event Listener (default: ``20``)
400
401 **ApiVersion** *version*
402   Used as the "apiVersion" element in the REST path (default: ``3``)
403
404 **KafkaPort** *port*
405   Kafka Port (Default ``9092``)
406
407 **KafkaBroker** *host*
408   Kafka Broker domain name. It can be an IP address or hostname of local or remote server
409   (default: ``localhost``)
410
411
412 VES YAML configuration format
413 -----------------------------
414
415 The format of the VES message is generated by the VES application based on the
416 YAML schema configuration file provided by user via ``--events-schema``
417 command-line option of the application.
418
419 .. note:: Use ``--help`` option of VES application to see the
420     description of all available options
421
422 .. note:: The detailed installation guide of the VES application is described in
423     the `VES Application User Guide`_.
424
425 The message defined by YAML schema should correspond to format defined in
426 `VES shema definition`_.
427
428 .. warning:: This section doesn't explain the YAML language itself, so the
429     knowledge of the YAML language is required before continue reading it!
430
431 Since, the VES message output is a JSON format, it's recommended to understand
432 how YAML document is converted to JSON before starting to create a new YAML
433 definition for the VES. E.g.:
434
435 The following YAML document:
436
437 .. code:: yaml
438
439     ---
440     additionalMeasurements:
441       plugin: somename
442       instance: someinstance
443
444 will be converted to JSON like this:
445
446 .. code:: json
447
448     {
449       "additionalMeasurements": {
450         "instance": "someinstance",
451         "plugin": "somename"
452       }
453     }
454
455 .. note:: The `YAML syntax` section of `PyYAML documentation`_ can be used
456     as a reference for this.
457
458
459 VES message types
460 -----------------
461
462 The VES agent can generate two type of messages which are sent to the VES
463 collector. Each message type must be specified in the YAML configuration file
464 using a specific YAML tag.
465
466 Measurements
467   This type is used to send a message defined in YAML configuration to the VES
468   collector with a specified interval (default is 20 sec and it's configurable
469   via command line option of the application). This type can be specified in
470   the configuration using ``!Measurements`` tag. For instance:
471
472   .. code:: yaml
473
474       ---
475       # My comments
476       My Host Measurements: !Measurements
477         ... # message definition
478
479 Events
480   This type is used to send a message defined in YAML configuration to the VES
481   collector when collectd notification is received from Kafka bus (collectd
482   ``write_kafka`` plugin). This type can be specified in the configuration
483   using ``!Events`` tag. For instance:
484
485   .. code:: yaml
486
487       ---
488       # My comments
489       My Events: !Events
490         ... # event definition
491
492
493 Collectd metrics in VES
494 -----------------------
495
496 The VES application caches collectd metrics received via Kafka bus. The data
497 is stored in a table format. It's important to know it before mapping collectd
498 metric values to message defined in YAML configuration file.
499
500 VES collectd metric cache example:
501
502 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
503 |   host    |  plugin   |  plugin_instance   |  type     |  type_instace  |       time        | value  | ds_name | interval |
504 +===========+===========+====================+===========+================+===================+========+=========+==========+
505 | localhost | cpu       |                    | percent   | user           | 1509535512.30567  | 16     | value   | 10       |
506 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
507 | localhost | memory    |                    | memory    | free           | 1509535573.448014 | 798456 | value   | 10       |
508 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
509 | localhost | interface |                    | eth0      | if_packets     | 1509544183.956496 | 253    | rx      | 10       |
510 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
511 | 7ec333e7  | virt      | Ubuntu-12.04.5-LTS | percent   | virt_cpu_total | 1509544402.378035 | 0.2    | value   | 10       |
512 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
513 | 7ec333e7  | virt      | Ubuntu-12.04.5-LTS | memory    | rss            | 1509544638.55119  | 123405 | value   | 10       |
514 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
515 | 7ec333e7  | virt      | Ubuntu-12.04.5-LTS | if_octets | vnet1          | 1509544646.27108  | 67     | tx      | 10       |
516 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
517 | cc659a52  | virt      | Ubuntu-16.04       | percent   | virt_cpu_total | 1509544745.617207 | 0.3    | value   | 10       |
518 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
519 | cc659a52  | virt      | Ubuntu-16.04       | memory    | rss            | 1509544754.329411 | 4567   | value   | 10       |
520 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
521 | cc659a52  | virt      | Ubuntu-16.04       | if_octets | vnet0          | 1509544760.720381 | 0      | rx      | 10       |
522 +-----------+-----------+--------------------+-----------+----------------+-------------------+--------+---------+----------+
523
524 It's possible from YAML configuration file to refer to any field of any row of
525 the table via special YAML tags like ``ValueItem`` or ``ArrayItem``. See the
526 `Collectd metric reference`_ reference for more details.
527
528 .. note:: The `collectd data types file`_ contains map of ``type`` to
529     ``ds_name`` field. It can be used to get possible value for ``ds_name``
530     field. See the `collectd data types description`_ for more details on
531     collectd data types.
532
533
534 Aging of collectd metric
535 ~~~~~~~~~~~~~~~~~~~~~~~~
536
537 If the metric will not be updated by the collectd during the double metric
538 interval time, it will be removed (aged) from VES internal cache.
539
540
541 VES YAML references
542 -------------------
543
544 There are four type of references supported by the YAML format: System,
545 Config, Collectd metric and Collectd notification. The format of the reference
546 is the following:
547
548 .. code:: yaml
549
550     "{<ref type>.<attribute name>}"
551
552 .. note:: Possible values for ``<ref type>`` and ``<attribute name>`` are
553     described in farther sections.
554
555
556 System reference
557 ~~~~~~~~~~~~~~~~
558
559 This reference is used to get system statistics like time, date etc. The system
560 reference (``<ref type>`` = ``system``) can be used in any place of the YAML
561 configuration file. This type of reference provides the following attributes:
562
563 ``hostname``
564   The name of the host where VES application is running.
565
566 ``id``
567   Unique ID during VES application runtime.
568
569 ``time``
570   Current time in seconds since the Epoch. For example ``1509641411.631951``.
571
572 ``date``
573   Current date in ISO 8601 format, ``YYYY-MM-DD``. For instance ``2017-11-02``.
574
575
576 For example:
577
578 .. code:: yaml
579
580     Date: "{system.date}"
581
582
583 Config reference
584 ~~~~~~~~~~~~~~~~
585
586 This reference is used to get VES configuration described in `VES application
587 configuration description`_ sectoin. The reference (``<ref type>`` = ``config``)
588 can be used in any place of the YAML configuration file. This type of reference
589 provides the following attributes:
590
591 ``interval``
592   Measurements dispatch interval. It referenses to ``SendEventInterval``
593   configuration of the VES application.
594
595
596 For example:
597
598 .. code:: yaml
599
600     Interval: "{config.interval}"
601
602
603 Collectd metric reference
604 ~~~~~~~~~~~~~~~~~~~~~~~~~
605
606 This reference is used to get the attribute value of collectd metric from the
607 VES cache. The reference (``<ref type>`` = ``vl``) can be used ONLY inside
608 ``Measurements``, ``ValueItem`` and ``ArrayItem`` tags. Using the reference
609 inside a helper tag is also allowed if the helper tag is located inside the
610 tag where the reference is allowed (e.g.: ``ArrayItem``). The
611 ``<attribute name>`` name corresponds to the table field name described in
612 `Collectd metrics in VES`_ section. For example:
613
614 .. code:: yaml
615
616     name: "{vl.type}-{vl.type_instance}"
617
618
619 Collectd notification reference
620 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
621
622 This reference is used to get the attribute value of received collectd
623 notification. The reference (``<ref type>`` = ``n``) can be used ONLY inside
624 ``Events`` tag. Using the reference inside a helper tag is also allowed if
625 the helper tag is located inside the ``Events`` tag. This type of reference
626 provides the following attributes:
627
628 ``host``
629   The hostname of received collectd notification.
630
631 ``plugin``
632   The plugin name of received collectd notification.
633
634 ``plugin_instance``
635   The plugin instance of the received collectd notification.
636
637 ``type``
638   The type name of the received collectd notification.
639
640 ``type_instance``
641   The type instance of the received collectd notification.
642
643 ``severity``
644   The severity of the received collectd notification.
645
646 ``message``
647   The message of the received collectd notification.
648
649
650 .. note:: The exact value for each attribute depends on the collectd plugin
651   which may generate the notification. Please refer to the
652   `collectd plugin description`_ document to get more details on the specific
653   collectd plugin.
654
655 YAML config example:
656
657 .. code:: yaml
658
659     sourceId: "{n.plugin_instance}"
660
661
662 Collectd metric mapping YAML tags
663 ---------------------------------
664
665 This section describes the YAML tags used to map collectd metric values in the
666 YAML configuration file.
667
668
669 Measurements tag
670 ~~~~~~~~~~~~~~~~
671
672 This tag is a YAML map which is used to define the VES measurement message. It's
673 allowed to be used multiple times in the document (e.g.: you can define multiple
674 VES messages in one YAML document). This tag works in the same way as `ArrayItem
675 tag`_ does and all keys have the same description/rules.
676
677
678 ValueItem tag
679 ~~~~~~~~~~~~~
680
681 This tag is used to select a collectd metric and get its attribute value using
682 `Collectd metric reference`_. The type of this tag is a YAML array of maps with
683 the possible keys described below.
684
685 ``SELECT`` (required)
686   Is a YAML map which describes the select metric criteria. Each key name of the
687   map must correspond to the table field name described in `Collectd metrics in VES`_
688   section.
689
690 ``VALUE`` (optional)
691   Describes the value to be assigned. If not provided, the default
692   ``!Number "{vl.value}"`` expression is used.
693
694 ``DEFAULT`` (optional)
695   Describes the default value which will be assigned if no metric is selected
696   by ``SELECT`` criteria.
697
698
699 ValueItem tag description example:
700
701 .. code:: yaml
702
703     memoryFree: !ValueItem
704       - SELECT:
705           plugin: memory
706           type: memory
707           type_instance: rss
708       - VALUE: !Bytes2Kibibytes "{vl.value}"
709       - DEFAULT: 0
710
711 The tag process workflow is described on the figure below.
712
713 .. figure:: value-item-parse-workflow.png
714
715     YAML ValueItem tag process workflow
716
717
718 ArrayItem tag
719 ~~~~~~~~~~~~~
720
721 This tag is used to select a list of collectd metrics and generate a YAML array
722 of YAML items described by ``ITEM-DESC`` key. If no collectd metrics are
723 selected by the given criteria, the empty array will be returned.
724
725 ``SELECT`` (optional)
726   Is a YAML map which describes the select metrics criteria. Each key name of
727   the map must correspond to the table field name described in `Collectd
728   metrics in VES`_ section. The value of the key may be regular expression. To
729   enable regular expression in the value, the YAML string containing ``/`` char
730   at the beginning and at the end should be used. For example:
731
732   .. code:: yaml
733
734       plugin: "/^(?!virt).*$/" # selected all metrics except ``virt`` plugin
735
736   The VES application uses the python RE library to work with regular
737   expression specified in the YAML configuration. Please refer to `python
738   regular expression syntax`_ documentation for more details on a syntax
739   used by the VES.
740
741   Multiple ``SELECT`` keys are allowed by the tag. If nor ``SELECT`` or
742   ``INDEX-KEY`` key is specified, the VES error is generated.
743
744 ``INDEX-KEY`` (optional)
745   Is a YAML array which describes the unique fields to be selected by the tag.
746   Each element of array is a YAML string which should be one of the table field
747   name described in `Collectd metrics in VES`_ section. Please note, if this
748   key is used, only fields specified by the key can be used as a collectd
749   reference in the ``ITEM-DESC`` key.
750
751 ``ITEM-DESC`` (required)
752   Is a YAML map which describes each element of the YAML array generated by
753   the tag. Using ``ArrayItem`` tags and other `Helper YAML tags`_ are also
754   allowed in the definition of the key.
755
756 In the example below, the ArrayItem tag is used to generate an array of
757 ``ITEM-DESC`` items for each collectd metrics except ``virt`` plugin with
758 unique ``plugin``, ``plugin_instance`` attribute values.
759
760 .. code:: yaml
761
762     Measurements: !ArrayItem
763       - SELECT:
764           plugin: "/^(?!virt).*$/"
765       - INDEX-KEY:
766           - plugin
767           - plugin_instance
768       - ITEM-DESC:
769           name: !StripExtraDash "{vl.plugin}-{vl.plugin_instance}"
770
771 The tag process workflow is described on the figure below.
772
773 .. figure:: array-item-parse-workflow.png
774
775     YAML ArrayItem tag process workflow
776
777
778 Collectd event mapping YAML tags
779 --------------------------------
780
781 This section describes the YAML tags used to map the collectd notification to
782 the VES event message in the YAML configuration file.
783
784
785 Events tag
786 ~~~~~~~~~~
787
788 This tag is a YAML map which is used to define the VES event message. It's
789 allowed to be used multiple times in the document (e.g.: you can map multiple
790 collectd notification into VES message in one YAML document). The possible
791 keys of the tag are described below.
792
793 ``CONDITION`` (optional)
794   Is a YAML map which describes the select metric criteria. Each key name of
795   the map must correspond to the name of attribute provided by `Collectd
796   notification reference`_. If no such key provided, any collectd notification
797   will map the defined YAML message.
798
799 ``ITEM-DESC`` (required)
800   Is a YAML map which describes the message generated by this tag. Only `Helper
801   YAML tags`_ are allowed in the definition of the key.
802
803 The example of the VES event message which will be generate by the VES
804 application when collectd notification of the ``virt`` plugin is triggered
805 is described below.
806
807 .. code:: yaml
808
809     ---
810     Virt Event: !Events
811       - ITEM-DESC:
812           event:
813             commonEventHeader:
814               domain: fault
815               eventType: Notification
816               sourceId: &event_sourceId "{n.plugin_instance}"
817               sourceName: *event_sourceId
818               lastEpochMicrosec: !Number "{n.time}"
819               startEpochMicrosec: !Number "{n.time}"
820             faultFields:
821               alarmInterfaceA: !StripExtraDash "{n.plugin}-{n.plugin_instance}"
822               alarmCondition: "{n.severity}"
823               faultFieldsVersion: 1.1
824       - CONDITION:
825           plugin: virt
826
827
828 Helper YAML tags
829 ----------------
830
831 This section describes the YAML tags used as utilities for formatting the output
832 message. The YAML configuration process workflow is described on the figure
833 below.
834
835 .. figure:: parse-work-flow.png
836
837     YAML configuration process workflow
838
839
840 Convert string to number tag
841 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
842
843 The ``!Number`` tag is used in YAML configuration file to convert string value into
844 the number type. For instance:
845
846 .. code:: yaml
847
848     lastEpochMicrosec: !Number "3456"
849
850 The output of the tag will be the JSON number.
851
852 .. code:: json
853
854     {
855       lastEpochMicrosec: 3456
856     }
857
858
859 Convert bytes to Kibibytes tag
860 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
861
862 The ``!Bytes2Kibibytes`` tag is used in YAML configuration file to convert
863 bytes into kibibytes (1 kibibyte = 1024 bytes). For instance:
864
865 .. code:: yaml
866
867     memoryConfigured: !Bytes2Kibibytes 4098
868     memoryConfigured: !Bytes2Kibibytes "1024"
869
870 The output of the tag will be the JSON number.
871
872 .. code:: json
873
874     {
875       memoryConfigured: 4
876       memoryConfigured: 1
877     }
878
879
880 Convert one value to another tag
881 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
882
883 The ``!MapValue`` tag is used in YAML configuration file to map one value
884 into another value defined in the configuration. For instance:
885
886 .. code:: yaml
887
888     Severity: !MapValue
889       VALUE: Failure
890       TO:
891         Failure: Critical
892         Error: Warnign
893
894 The output of the tag will be the mapped value.
895
896 .. code:: json
897
898     {
899       Severity: Critical
900     }
901
902
903 Strip extra dash tag
904 ~~~~~~~~~~~~~~~~~~~~
905
906 The ``!StripExtraDash`` tag is used in YAML configuration file to strip extra
907 dashes in the string (dashes at the beginning, at the end and double dashes).
908 For example:
909
910 .. code:: yaml
911
912     name: !StripExtraDash string-with--extra-dashes-
913
914 The output of the tag will be the JSON string with extra dashes removed.
915
916 .. code:: json
917
918     {
919       name: string-with-extra-dashes
920     }
921
922
923 Limitations
924 -----------
925
926 #. Only one document can be defined in the same YAML configuration file.
927
928 #. The collectd notification is not supported by `Kafka collectd plugin`_. Due to
929    this limitation, the collectd notifications cannot be received by the VES
930    application and the defined YAML event will not be generated and sent to the
931    VES collector. Please note, that VES YAML format already supports the events
932    definition and the format is descibed in the document.
933
934
935 .. _collectd: http://collectd.org/
936 .. _Kafka: https://kafka.apache.org/
937 .. _`VES`: https://wiki.opnfv.org/display/fastpath/VES+plugin+updates
938 .. _`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
939 .. _`PyYAML documentation`: https://pyyaml.org/wiki/PyYAMLDocumentation
940 .. _`collectd plugin description`: https://github.com/collectd/collectd/blob/master/src/collectd.conf.pod
941 .. _`collectd data types file`: https://github.com/collectd/collectd/blob/master/src/types.db
942 .. _`collectd data types description`: https://github.com/collectd/collectd/blob/master/src/types.db.pod
943 .. _`python regular expression syntax`: https://docs.python.org/2/library/re.html#regular-expression-syntax
944 .. _`Kafka collectd plugin`: https://collectd.org/wiki/index.php/Plugin:Write_Kafka