Skip to content

Commit

Permalink
feat: ignore internal nics fixes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
tilsche committed Jun 1, 2023
1 parent 6405c3c commit a6a0485
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions metricq_source_sysinfo/sysinfo_source.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import socket
import re

import psutil
from metricq import IntervalSource, Timedelta, Timestamp, logging, rpc_handler
Expand All @@ -8,6 +9,8 @@

logger = logging.get_logger("SysinfoSource")

# Ignore internal nics, especially from docker
_NIC_IGNORE_PATTERN = re.compile(r"^(lo|br|docker|veth)")

class SysinfoSource(IntervalSource):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -58,6 +61,8 @@ async def _on_config(self, **config):
self.prev_net_io = psutil.net_io_counters(pernic=True, nowrap=True)
self.prev_timestamp = Timestamp.now()
for nic_name in self.prev_net_io.keys():
if _NIC_IGNORE_PATTERN.match(nic_name):
continue
for sr in "sent", "recv":
meta[f"net.{nic_name}.{sr}.bytes"] = {
"rate": rate,
Expand Down

0 comments on commit a6a0485

Please sign in to comment.