|
| 1 | +# Telemetry Data Reporting: Interface Usage Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This toolkit is a framework designed to emit telemetry data, including (but not limited to) traces, metrics, and logs. |
| 6 | +It also provides a user interface to take and organize the data collected from SONiC devices and traffic generateors. |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +## How it works |
| 11 | + |
| 12 | +### Organization of Metric Labels |
| 13 | + |
| 14 | +Each telemetry data point is identified by labels, which are organized into two levels: |
| 15 | + |
| 16 | +#### Test-Level Labels |
| 17 | + |
| 18 | +These labels provide general information applicable to all metrics within a test. Their naming convention begins with "test" and is structured hierarchically using periods ("."). Examples include: |
| 19 | + |
| 20 | +| Label | Value | Description | |
| 21 | +| ----------------------- | ----------------- | ---------------------------------------- | |
| 22 | +| METRIC_LABEL_TESTBED | `test.testbed` | Represents the testbed name or ID. | |
| 23 | +| METRIC_LABEL_TEST_BUILD | `test.os.version` | Specifies the software or build version. | |
| 24 | +| METRIC_LABEL_TEST_CASE | `test.testcase` | Identifies the test case name or ID. | |
| 25 | +| METRIC_LABEL_TEST_FILE | `test.file` | Refers to the test file name. | |
| 26 | +| METRIC_LABEL_TEST_JOBID | `test.job.id` | Denotes the test job ID. | |
| 27 | + |
| 28 | +#### Metric-Specific Labels |
| 29 | + |
| 30 | +These labels are specific to individual metrics and follow a consistent naming convention. Each label begins with "device" and is structured hierarchically using periods ("."). Examples include: |
| 31 | + |
| 32 | +| Label | Value | Description | |
| 33 | +| ------------------------------ | ------------------- | -------------------------------- | |
| 34 | +| METRIC_LABEL_DEVICE_ID | `device.id` | Represents the device ID. | |
| 35 | +| METRIC_LABEL_DEVICE_PORT_ID | `device.port.id` | Specifies the port ID. | |
| 36 | +| METRIC_LABEL_DEVICE_PSU_ID | `device.psu.id` | Identifies the PSU ID. | |
| 37 | +| METRIC_LABEL_DEVICE_PSU_MODEL | `device.psu.model` | Denotes the PSU model. | |
| 38 | +| METRIC_LABEL_DEVICE_PSU_SERIAL | `device.psu.serial` | Refers to the PSU serial number. | |
| 39 | + |
| 40 | +### User interface and backend operations |
| 41 | + |
| 42 | + Frontend: |
| 43 | + The user interface accepts a metric's name, value along with its associated labels. |
| 44 | + |
| 45 | + Backend: |
| 46 | + The framework performs the following operations: |
| 47 | + Creates a data entry for the submitted metric. |
| 48 | + Exports the data entry to a database. |
| 49 | + |
| 50 | + Reporters: |
| 51 | + Metrics collected periodically are handled by the PeriodicMetricsReporter. |
| 52 | + Final status data for test results are handled by the FinalMetricsReporter. |
| 53 | + The framework is designed to support the addition of new reporters and metric types, offering scalability and flexibility. |
| 54 | + |
| 55 | +## How to use |
| 56 | + |
| 57 | +An example of using this tool in Python to report a switch's PSU metrics is provided. |
| 58 | + |
| 59 | +1. Collect test-level information and generate common labels. |
| 60 | + |
| 61 | + ```python |
| 62 | + common_labels = { |
| 63 | + METRIC_LABEL_TESTBED: "TB-XYZ", |
| 64 | + METRIC_LABEL_TEST_BUILD: "2024.1103", |
| 65 | + METRIC_LABEL_TEST_CASE: "mock-case", |
| 66 | + METRIC_LABEL_TEST_FILE: "mock-test.py", |
| 67 | + METRIC_LABEL_TEST_JOBID: "2024_1225_0621" |
| 68 | + } |
| 69 | + ``` |
| 70 | + |
| 71 | +2. Create a metric reporter using the common labels. |
| 72 | + |
| 73 | + ```python |
| 74 | + reporter = TelemetryReporterFactory.create_periodic_metrics_reporter(common_labels) |
| 75 | + ``` |
| 76 | + |
| 77 | +3. Collect device and component information, along with metrics' names and values. |
| 78 | + |
| 79 | + ```python |
| 80 | + metric_labels = {METRIC_LABEL_DEVICE_ID: "switch-A"} |
| 81 | + |
| 82 | + voltage = GaugeMetric( |
| 83 | + name="Voltage", |
| 84 | + description="Power supply unit voltage reading", |
| 85 | + unit="V", |
| 86 | + reporter=reporter |
| 87 | + ) |
| 88 | + |
| 89 | + current = GaugeMetric( |
| 90 | + name="Current", |
| 91 | + description="Power supply unit current reading", |
| 92 | + unit="A", |
| 93 | + reporter=reporter |
| 94 | + ) |
| 95 | + |
| 96 | + power = GaugeMetric( |
| 97 | + name="Power", |
| 98 | + description="Power supply unit power reading", |
| 99 | + unit="W", |
| 100 | + reporter=reporter |
| 101 | + ) |
| 102 | + ``` |
| 103 | + |
| 104 | +4. Generate metric-specific labels and record metrics, one metric at a time. |
| 105 | + |
| 106 | + ```python |
| 107 | + metric_labels[METRIC_LABEL_DEVICE_PSU_ID] = "PSU 1" |
| 108 | + metric_labels[METRIC_LABEL_DEVICE_PSU_MODEL] = "PWR-ABCD" |
| 109 | + metric_labels[METRIC_LABEL_DEVICE_PSU_SERIAL] = "1Z011010112349Q" |
| 110 | + |
| 111 | + voltage.record(metric_labels, 12.09) |
| 112 | + current.record(metric_labels, 18.38) |
| 113 | + power.record(metric_labels, 222.00) |
| 114 | + ``` |
| 115 | + |
| 116 | +5. Report the metrics. |
| 117 | + |
| 118 | + ```python |
| 119 | + reporter.report() |
| 120 | + ``` |
| 121 | + |
| 122 | +6. Access the data entries in the database using tools like **Grafana**. |
| 123 | + |
| 124 | +## Rules |
| 125 | + |
| 126 | +Only labels defined in metrics.py are permitted. |
| 127 | + |
| 128 | +Ensure proper use of labels to maintain consistency and compatibility with the framework. |
0 commit comments