Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding interface status to the interface endpoint. #1236

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Changelog
+++++++++

3.1.2 - 01/XX/2025
3.1.2 - 01/14/2025
==================
**Updates**
- Added interface status to the interface endpoint. [GH:#1220] (Blake Bahner)
- Reworked the interface endpoint to be more efficient. [GH:#1001] (Blake Bahner)
- Updated Python to 3.13.1 on Windows builds to resolve some CVEs. (Blake Bahner)

**Bug Fixes**
Expand Down
34 changes: 23 additions & 11 deletions agent/listener/psapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,29 @@ def make_mount_other_nodes(partition):
return ParentNode(safe_mountpoint, children=[dvn, fstype, opts])


def make_if_nodes(if_name):
x = ps.net_io_counters(pernic=True)
def make_if_nodes(if_name, io_counters, if_stats):

bytes_sent = RunnableNode("bytes_sent", method=lambda: (x[if_name].bytes_sent, "B"))
bytes_recv = RunnableNode("bytes_recv", method=lambda: (x[if_name].bytes_recv, "B"))
bytes_sent = RunnableNode("bytes_sent", method=lambda: (io_counters[if_name].bytes_sent, "B"))
bytes_recv = RunnableNode("bytes_recv", method=lambda: (io_counters[if_name].bytes_recv, "B"))
packets_sent = RunnableNode(
"packets_sent", method=lambda: (x[if_name].packets_sent, "packets")
"packets_sent", method=lambda: (io_counters[if_name].packets_sent, "packets")
)
packets_recv = RunnableNode(
"packets_recv", method=lambda: (x[if_name].packets_recv, "packets")
"packets_recv", method=lambda: (io_counters[if_name].packets_recv, "packets")
)
errin = RunnableNode("errin", method=lambda: (x[if_name].errin, "errors"))
errout = RunnableNode("errout", method=lambda: (x[if_name].errout, "errors"))
dropin = RunnableNode("dropin", method=lambda: (x[if_name].dropin, "packets"))
dropout = RunnableNode("dropout", method=lambda: (x[if_name].dropout, "packets"))
errin = RunnableNode("errin", method=lambda: (io_counters[if_name].errin, "errors"))
errout = RunnableNode("errout", method=lambda: (io_counters[if_name].errout, "errors"))
dropin = RunnableNode("dropin", method=lambda: (io_counters[if_name].dropin, "packets"))
dropout = RunnableNode("dropout", method=lambda: (io_counters[if_name].dropout, "packets"))

if if_name in if_stats:
if if_stats[if_name].isup:
status = "up"
else:
status = "down"
else:
status = "unknown"
statusNode = RunnableNode("status", method=lambda: (status, ""))

return RunnableParentNode(
if_name,
Expand All @@ -235,6 +243,7 @@ def make_if_nodes(if_name):
dropout,
bytes_sent,
errout,
statusNode,
],
)

Expand Down Expand Up @@ -419,8 +428,11 @@ def get_disk_node(config):


def get_interface_node():
io_counters = ps.net_io_counters(pernic=True)
if_stats = ps.net_if_stats()

if_children = [
make_if_nodes(x) for x in list(ps.net_io_counters(pernic=True).keys())
make_if_nodes(if_name, io_counters, if_stats) for if_name in io_counters.keys()
]
return ParentNode("interface", children=if_children)

Expand Down