The statistics writer records DHCP message rates, relayed traffic and active leases per protocol and scope #116

Open
opened 2026-10-31 12:42:09 -04:00 by claude · 0 comments
Owner
  • Draft: PQ-38
  • Priority: high
  • Agent: coder
  • Depends on: #112, #113, #114, #115
  • Decisions: Q-PQ-12, R2-STATS-NODE, R2-DHCP-RELAY

Why

#113, #114 and #115 produce the numbers; this writes them as series next to the DNS ones, under this node's id.

What changes

  • In src/dotnet/src/Ninlil.Dns.Server.Statistics, which gains references to Ninlil.Dhcp.Common and Ninlil.Dhcp.Data.Abstractions:
    • On each flush, Drain() the IDhcpMessageCounters (resolved with GetService) and add counters, categories dhcp-v4 and dhcp-v6, minute and hour rows like the DNS counters:
      • local engine: received.<TYPE>, sent.<TYPE>, sent.NONE;
      • relay: relay.request.forwarded, relay.reply.forwarded, relay.dropped.
    • On each flush, call CountActiveByScopeAsync and set gauges leases.active (per protocol) and leases.active.scope.<scope> (per scope). The minute row gets the sample; the hour row gets the latest sample of the hour.
  • A protocol's mode is Off, Local or Relay: Local when Dhcpv4ProtocolOptions.Enable (or Dhcpv6ProtocolOptions.Enable) is set and the relay option is not, Relay when both are set (src/dotnet/src/Ninlil.Web/Startup/DhcpServiceRegistration.cs:48-76). Put this rule in one helper (DhcpProtocolModeResolver) that #118 reuses.
    • Lease gauges are written only for a protocol in Local mode (a relay node holds no leases).
    • Counters are written whenever the drain holds counts, so a mode switch never loses the last minute.
  • Retention from #112 covers these rows; StatisticsOptions.Enable = false stops them too. No new option.

Acceptance

  • Test fails first in src/dotnet/tests/Ninlil.Dns.Server.Statistics.Tests: with fake counters reporting 3 DISCOVER and 2 OFFER, a flush adds dhcp-v4 received.DISCOVER = 3 and sent.OFFER = 2.
  • Test: fake counters reporting 4 relayed requests and 4 relayed replies on DHCPv6 add dhcp-v6 relay.request.forwarded = 4 and relay.reply.forwarded = 4.
  • Test: with a fake lease repository reporting 5 active leases in one DHCPv4 scope and DHCPv4 in Local mode, a flush sets leases.active = 5 and the scope's gauge to 5; in Relay mode no lease gauge is written.
  • Test: with DHCPv4 Off and no counts, no dhcp-v4 rows are written.
  • src/dotnet/tests/Ninlil.Web.Tests passes (DI wiring). No schema, API or option change.

Source

  • Owner decision 2026-10-31 (Q-PQ-12): "DHCP stats series + charts, e.g. pool utilisation, leases over time, offers/acks/naks".
  • Owner decision 2026-10-31, round 2 (R2-DHCP-RELAY): "count relayed too".
- **Draft:** PQ-38 - **Priority:** high - **Agent:** coder - **Depends on:** #112, #113, #114, #115 - **Decisions:** Q-PQ-12, R2-STATS-NODE, R2-DHCP-RELAY ### Why #113, #114 and #115 produce the numbers; this writes them as series next to the DNS ones, under this node's id. ### What changes - In `src/dotnet/src/Ninlil.Dns.Server.Statistics`, which gains references to `Ninlil.Dhcp.Common` and `Ninlil.Dhcp.Data.Abstractions`: - On each flush, `Drain()` the `IDhcpMessageCounters` (resolved with `GetService`) and add counters, categories `dhcp-v4` and `dhcp-v6`, minute and hour rows like the DNS counters: - local engine: `received.<TYPE>`, `sent.<TYPE>`, `sent.NONE`; - relay: `relay.request.forwarded`, `relay.reply.forwarded`, `relay.dropped`. - On each flush, call `CountActiveByScopeAsync` and set gauges `leases.active` (per protocol) and `leases.active.scope.<scope>` (per scope). The minute row gets the sample; the hour row gets the latest sample of the hour. - A protocol's mode is `Off`, `Local` or `Relay`: `Local` when `Dhcpv4ProtocolOptions.Enable` (or `Dhcpv6ProtocolOptions.Enable`) is set and the relay option is not, `Relay` when both are set (`src/dotnet/src/Ninlil.Web/Startup/DhcpServiceRegistration.cs:48-76`). Put this rule in one helper (`DhcpProtocolModeResolver`) that #118 reuses. - Lease gauges are written only for a protocol in `Local` mode (a relay node holds no leases). - Counters are written whenever the drain holds counts, so a mode switch never loses the last minute. - Retention from #112 covers these rows; `StatisticsOptions.Enable = false` stops them too. No new option. ### Acceptance - [ ] Test fails first in `src/dotnet/tests/Ninlil.Dns.Server.Statistics.Tests`: with fake counters reporting 3 DISCOVER and 2 OFFER, a flush adds `dhcp-v4` `received.DISCOVER = 3` and `sent.OFFER = 2`. - [ ] Test: fake counters reporting 4 relayed requests and 4 relayed replies on DHCPv6 add `dhcp-v6` `relay.request.forwarded = 4` and `relay.reply.forwarded = 4`. - [ ] Test: with a fake lease repository reporting 5 active leases in one DHCPv4 scope and DHCPv4 in `Local` mode, a flush sets `leases.active = 5` and the scope's gauge to 5; in `Relay` mode no lease gauge is written. - [ ] Test: with DHCPv4 `Off` and no counts, no `dhcp-v4` rows are written. - [ ] `src/dotnet/tests/Ninlil.Web.Tests` passes (DI wiring). No schema, API or option change. ### Source - Owner decision 2026-10-31 (Q-PQ-12): "DHCP stats series + charts, e.g. pool utilisation, leases over time, offers/acks/naks". - Owner decision 2026-10-31, round 2 (R2-DHCP-RELAY): "count relayed too".
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#116
No description provided.