xref: /dpdk/doc/guides/prog_guide/telemetry_lib.rst (revision 24cd1b529f35f106d323ebdd4df0203261824dcc)
1..  SPDX-License-Identifier: BSD-3-Clause
2    Copyright(c) 2020 Intel Corporation.
3
4Telemetry Library
5=================
6
7The Telemetry library provides an interface to retrieve information from a
8variety of DPDK libraries. The library provides this information via socket
9connection, taking requests from a connected client and replying with the JSON
10response containing the requested telemetry information.
11
12Telemetry is enabled to run by default when running a DPDK application, and the
13telemetry information from enabled libraries is made available. Libraries are
14responsible for registering their own commands, and providing the callback
15function that will format the library specific stats into the correct data
16format, when requested.
17
18
19Registering Commands
20--------------------
21
22Libraries and applications must register commands to make their information
23available via the Telemetry library. This involves providing a string command
24in the required format ("/library/command"), and the callback function that
25will handle formatting the information when required. An example showing ethdev
26commands being registered is shown below:
27
28.. code-block:: c
29
30    rte_telemetry_register_cmd("/ethdev/list", handle_port_list);
31    rte_telemetry_register_cmd("/ethdev/xstats", handle_port_xstats);
32
33
34Formatting JSON response
35------------------------
36
37The callback function provided by the library must format its telemetry
38information in the required data format. The Telemetry library provides a data
39utilities API to build up the response. For example, the ethdev library provides a
40list of available ethdev ports in a formatted data response, constructed using the
41following functions to build up the list:
42
43.. code-block:: c
44
45    rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
46        RTE_ETH_FOREACH_DEV(port_id)
47            rte_tel_data_add_array_int(d, port_id);
48
49The data structure is then formatted into a JSON response before sending.
50The resulting response shows the port list data provided above by the handler
51function in ethdev, placed in a JSON reply by telemetry:
52
53.. code-block:: console
54
55    {"/ethdev/list": [0, 1]}
56
57For more information on the range of data functions available in the API,
58please refer to the docs.
59