Skip to content

IPv6-safe connection metrics + opt-in per-connection traffic + IPv4/IPv6 totals#313

Open
ABHIRAMSHIBU wants to merge 4 commits into
akpw:mainfrom
ABHIRAMSHIBU:feat/ipv6-connection-traffic
Open

IPv6-safe connection metrics + opt-in per-connection traffic + IPv4/IPv6 totals#313
ABHIRAMSHIBU wants to merge 4 commits into
akpw:mainfrom
ABHIRAMSHIBU:feat/ipv6-connection-traffic

Conversation

@ABHIRAMSHIBU
Copy link
Copy Markdown
Contributor

Changes

  1. IPv6-safe connection parsing — both /ip/firewall/connection/ and /ipv6/firewall/connection/ are now polled and merged. The previous
    src-address.split(':')[0] truncated IPv6 addresses at the first colon, producing nonsense labels. Replaced with proper [host]:port /
    host:port normalization that handles both families.

  2. New per-family totals (always on, backward compatible):

    • mktxp_ip_connections_total — combined (unchanged behavior)
    • mktxp_ipv4_connections_total — IPv4-only
    • mktxp_ipv6_connections_total — IPv6-only

    Invariant: ip_total == ipv4_total + ipv6_total.

  3. New opt-in per-connection traffic metrics (connection_traffic = False by default):

    • mktxp_connection_upload_bytes (from orig-bytes)
    • mktxp_connection_download_bytes (from repl-bytes)
    • mktxp_connection_total_bytes

  Module-level helpers added in earlier commits broke the convention
  followed by every other *_ds.py file (class on the first non-import
  line). Move them as @staticmethod onto IPConnectionDatasource — the
  sibling Stats/Traffic datasources call them via the same cross-class
  pattern already used for BaseDSProcessor.trimmed_records.

  Also drops the unused _count_connection_records wrapper.

  No behavior change. 8/8 focused tests pass; 215/215 full suite passes.
@ABHIRAMSHIBU ABHIRAMSHIBU changed the title Connection Traffic: IPv6 Support IPv6-safe connection metrics + opt-in per-connection traffic + IPv4/IPv6 totals Apr 26, 2026
   CollectorHandler.collect() returned with no yield when a scrape landed
    inside minimal_collect_interval, so every mktxp_* series went missing for
    that request while up{} stayed 1. Concurrent scrapers, or a single
    Prometheus scrape overlapping a slow collection (e.g. connection_traffic
    = True), surfaced as phantom 'down' gaps in dashboards.

    Materialise each successful collection, cache it under a Lock, and yield
    from the cache on within-MCI calls. Empty collections don't clobber the
    cache. ProbeCollectorHandler unchanged — /probe semantics intentionally
    raise on deferral.

    Verified on a live RouterOS target: 12 back-to-back 1s-cadence scrapes
    all returned ~1.1k mktxp_* lines (mix of fresh ~0.5–4.2s collects and
    ~8ms cache replays). Previously 4 of 5 scrapes returned only the 1.8KB
    process-metric stub.

    2/2 new tests pass; 211/211 full suite passes.
@akpw
Copy link
Copy Markdown
Owner

akpw commented May 10, 2026

@ABHIRAMSHIBU thanks for the PR, it looks good overall. a few comments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants