Skip to content

Commit

Permalink
chore: hide localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgiga1993 committed May 13, 2024
1 parent a885699 commit 5de214b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pollect/sources/K8sNamespaceTrafficSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, config):
self.known_networks.append(NamedNetworks(name, network['cidrs']))

# Add catch-any as last item
self.known_networks.append(NamedNetworks('localhost', ['127.0.0.1'], hide=True))
self.known_networks.append(NamedNetworks('other', ['0.0.0.0/0'], catch_all=True))
self._metrics = NamespacesMetrics(self.known_networks)

Expand Down Expand Up @@ -77,6 +78,9 @@ def _probe(self) -> Optional[ValueSet] or List[ValueSet]:
for value in self._metrics.metrics.values():
namespace = value.namespace
for network, metrics in value.metrics.items():
if network.hide:
continue

net_name = network.name
assert isinstance(metrics, NetworkMetrics)
values.add(Value(label_values=[namespace, net_name, 'received'], value=metrics.received_bytes))
Expand Down
5 changes: 3 additions & 2 deletions pollect/sources/helper/NetworkStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ def contains(self, ip: int):

class NamedNetworks:

def __init__(self, name: str, subnets: List[str], catch_all: bool = False):
def __init__(self, name: str, subnets: List[str], catch_all: bool = False, hide: bool = False):
self.name = name
self.hide = hide
self.catch_all = catch_all
self._subnets: List[Subnet] = []
for subnet in subnets:
self._subnets.append(Subnet(subnet))
self.catch_all = catch_all

def contains(self, ip: int):
for net in self._subnets:
Expand Down

0 comments on commit 5de214b

Please sign in to comment.