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