Skip to content

Commit

Permalink
Fix typing, apply simplifications and flatten code
Browse files Browse the repository at this point in the history
  • Loading branch information
jorund1 committed Dec 4, 2024
1 parent 3e65bbc commit 82345ce
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 94 deletions.
21 changes: 7 additions & 14 deletions python/nav/dhcp/generic_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
#




#TODO: rename from DhcpMetricSource to DhcpCollector



# TODO: rename from DhcpMetricSource to DhcpCollector


"""
Expand Down Expand Up @@ -48,23 +43,23 @@
from nav.metrics.templates import metric_path_for_subnet_dhcp



class DhcpMetricKey(Enum):
"""
Specifies what kind of value a DHCP metric represents.
TOTAL: value is the maximum possible amount of active leases in the
subnet
ASSIGNED: value is the current amount of active leases in the subnet
DECLINED: value is the amount of DHCP-maintained addresses in use by an
entity unknown to the server and thus not available for
assignment. (Should ideally always be zero)
For more detailed info on DECLINED, see e.g.
https://kea.readthedocs.io/en/kea-2.2.0/arm/dhcp6-srv.html#duplicate-addresses-dhcpdecline-support
"""

TOTAL = "total"
ASSIGNED = "assigned"
DECLINED = "declined"
Expand All @@ -75,7 +70,7 @@ def __str__(self):

@dataclass(frozen=True)
class DhcpMetric:
timestamp: datetime
timestamp: float
subnet_prefix: IP
key: DhcpMetricKey
value: int
Expand All @@ -88,16 +83,14 @@ class DhcpMetricSource:
graphite server. Subclasses need to implement `fetch_metrics`.
"""

def fetch_metrics(self) -> Iterator[DhcpMetric]:
def fetch_metrics(self) -> list[DhcpMetric]:
"""
Fetch DhcpMetrics having keys `TOTAL` and `ASSIGNED` for each subnet of the
DHCP server at current point of time.
"""
raise NotImplementedError

def fetch_metrics_to_graphite(
self, host=None, port=None
):
def fetch_metrics_to_graphite(self, host=None, port=None):
"""
Fetch metrics describing total amount of addresses
(DhcpMetricKey.TOTAL) and amount of addresses that have been
Expand Down
Loading

0 comments on commit 82345ce

Please sign in to comment.