[06/12] usertools: add new telemetry python script

Message ID 20200319171907.60891-7-ciara.power@intel.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series update and simplify telemetry library. |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Power, Ciara March 19, 2020, 5:19 p.m. UTC
  From: Bruce Richardson <bruce.richardson@intel.com>

This patch adds a python script that can be used with the new telemetry
socket. It connects as a client to the socket, and allows the user send
a command and see the JSON response.

The example usage below shows the script connecting to the new telemetry
socket, and sending two basic ethdev commands entered by the user.
The response for each command is shown below the user input.

Connecting to /var/run/dpdk/rte/dpdk_telemetry.19707
--> /
{"/": ["/", "/ethdev/list", "/ethdev/stats"]}
--> /ethdev/list
{"/ethdev/list": [0, 1]}
--> /ethdev/stats,0
{"/ethdev/stats": {"rx_good_packets": 0, "tx_good_packets": 0,
<snip>
 "tx_priority7_xon_to_xoff_packets": 0}}

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Ciara Power <ciara.power@intel.com>

---
This is a temporary script for testing purposes. Later versions
of the patchset will include a production ready version, which may
be merged into the existing dpdk_telemetry script.
---
 usertools/test_new_telemetry.py | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100755 usertools/test_new_telemetry.py
  

Patch

diff --git a/usertools/test_new_telemetry.py b/usertools/test_new_telemetry.py
new file mode 100755
index 000000000..23e879122
--- /dev/null
+++ b/usertools/test_new_telemetry.py
@@ -0,0 +1,30 @@ 
+#! /usr/bin/python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2020 Intel Corporation
+
+import socket
+import os
+import glob
+import json
+
+def handle_socket(path):
+    print("Connecting to " + path)
+    try:
+        fd.connect(path)
+    except OSError:
+        return
+    text = input('--> ')
+    while (text != "quit"):
+        fd.send(text.encode())
+        reply = json.loads(fd.recv(1024 * 12).decode())
+        print(json.dumps(reply))
+        text = input('--> ')
+    fd.close()
+
+fd = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+# Path to sockets for processes run as a root user
+for f in glob.glob('/var/run/dpdk/*/dpdk_telemetry.*'):
+  handle_socket(f)
+# Path to sockets for processes run as a regular user
+for f in glob.glob('/run/user/%d/dpdk/*/dpdk_telemetry.*' % os.getuid()):
+  handle_socket(f)