Skip to content

Commit b2b133a

Browse files
committed
infra: export hardware statistics through DPDK telemetry socket
Export the statistics available through `grcli show stats hardware` via DPDK telemetry socket. The endpoint for physical ports statistics available on DPDK telemetry socket can be dumped in json format using DPDK usertool dpdk/usertools/dpdk-telemetry.py. Output snippet: --> /grout/stats/xstats { "/grout/stats/xstats": { "p0": { "rx_good_packets": 2, "rx_good_bytes": 750, "rx_multicast_packets": 2, "rx_broadcast_packets": 1, "rx_unknown_protocol_packets": 3, "mac_remote_errors": 1, "rx_size_256_to_511_packets": 3 } } } Signed-off-by: Spoorthi K <spk@redhat.com>
1 parent 8d9fd49 commit b2b133a

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

modules/infra/api/stats.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,67 @@ telemetry_sw_stats_get(const char * /*cmd*/, const char * /*params*/, struct rte
278278
return -1;
279279
}
280280

281+
static int
282+
telemetry_xstats_get(const char * /*cmd*/, const char * /*params*/, struct rte_tel_data *d) {
283+
struct rte_eth_xstat_name *names = NULL;
284+
struct rte_eth_xstat *xstats = NULL;
285+
struct iface *iface = NULL;
286+
unsigned num;
287+
int ret;
288+
289+
rte_tel_data_start_dict(d);
290+
291+
while ((iface = iface_next(GR_IFACE_TYPE_PORT, iface)) != NULL) {
292+
struct iface_info_port *port = (struct iface_info_port *)iface->info;
293+
ret = rte_eth_xstats_get_names(port->port_id, NULL, 0);
294+
if (ret <= 0) {
295+
continue;
296+
}
297+
num = ret;
298+
299+
names = calloc(num, sizeof(*names));
300+
xstats = calloc(num, sizeof(*xstats));
301+
if (names == NULL || xstats == NULL) {
302+
goto err;
303+
}
304+
305+
if (rte_eth_xstats_get_names(port->port_id, names, num) < 0
306+
|| rte_eth_xstats_get(port->port_id, xstats, num) < 0) {
307+
free(names);
308+
free(xstats);
309+
continue;
310+
}
311+
312+
struct rte_tel_data *iface_container = rte_tel_data_alloc();
313+
if (iface_container == NULL) {
314+
goto err;
315+
}
316+
rte_tel_data_start_dict(iface_container);
317+
318+
for (unsigned i = 0; i < num; i++) {
319+
if (xstats[i].value > 0) {
320+
rte_tel_data_add_dict_uint(
321+
iface_container, names[i].name, xstats[i].value
322+
);
323+
}
324+
}
325+
326+
if (rte_tel_data_add_dict_container(d, iface->name, iface_container, 0) != 0) {
327+
rte_tel_data_free(iface_container);
328+
goto err;
329+
}
330+
331+
free(names);
332+
free(xstats);
333+
}
334+
return 0;
335+
336+
err:
337+
free(names);
338+
free(xstats);
339+
return -1;
340+
}
341+
281342
static struct gr_api_handler stats_get_handler = {
282343
.name = "stats get",
283344
.request_type = GR_INFRA_STATS_GET,
@@ -298,4 +359,9 @@ RTE_INIT(infra_stats_init) {
298359
telemetry_sw_stats_get,
299360
"Returns statistics of each graph node. No parameters"
300361
);
362+
rte_telemetry_register_cmd(
363+
"/grout/stats/xstats",
364+
telemetry_xstats_get,
365+
"Returns extended statistics per physical port. No parameters"
366+
);
301367
}

0 commit comments

Comments
 (0)