ncode.randomness.beacon.pulses
- Attributes
ncode.randomness.beacon,ncode.randomness.outcome(accepted,unchanged,unavailable,not_found,invalid,stale,rolled_back)- Counts
- one per fetch
GuidesMonitor the beacons
Report beacon health to a readiness probe, read each beacon's state, and chart the pulses and reseeds.
A beacon is an external service, so it can be down while your application is fine: the generator keeps drawing from the operating system’s source, and mixes beacon pulses in when they arrive. You still want to know when a beacon stops answering. This page shows how to report beacon health to a readiness probe, how to read each beacon’s state, how to chart the pulses and reseeds, and what to watch for.
AddRandomnessBeacons registers one health check, named randomness-beacons, on the health checks builder. Tag it ready so a readiness probe runs it.
var section = builder.Configuration.GetSection("Randomness");builder.Services.AddRandomness(section).AddCurbyBeacon();builder.Services.AddHealthChecks().AddRandomnessBeacons("ready");
using var host = builder.Build();var health = host.Services.GetRequiredService<HealthCheckService>();var report = await health.CheckHealthAsync( check => check.Tags.Contains("ready"), cancellationToken);// report.Status: Healthy, or Degraded while a beacon is unavailable;// never UnhealthyThe check is Healthy while every beacon works, and Degraded while a beacon is unavailable. It is never Unhealthy, because the generator keeps working without a beacon. It is Healthy with the message “Beacons are offline by configuration.” when the mode is Offline.
IBeaconStatus lists every registered beacon’s state. RandomnessHost.BeaconStatus returns it, and it resolves from dependency injection too.
var status = randomness.BeaconStatus;foreach (var beacon in status.Beacons){ var failures = beacon.ConsecutiveFailures; lines.Add($"{beacon.Name}: {beacon.Health}, failures {failures}");}Health is Pending until a fetch finishes, Healthy when the last fetch gave a verified, fresh or unchanged pulse, and Unavailable when it failed or its pulse was refused. LastPulse, LastError and LastAttempt say what the beacon last returned, what went wrong and when it tried. WaitForPulseAsync waits until a pulse is mixed in, for a policy that demands beacon entropy before it draws.
The generator publishes two counters from the meter NCode.Randomness (RandomnessDiagnostics.MeterName), created through IMeterFactory, so subscribe to it with OpenTelemetry or MeterListener.
ncode.randomness.beacon.pulsesncode.randomness.beacon, ncode.randomness.outcome (accepted, unchanged, unavailable, not_found, invalid, stale, rolled_back)ncode.randomness.generator.reseedsncode.randomness.reseed.reason (beacon, interval, volume)Outbound calls to a beacon are measured by System.Net.Http’s own instruments on each adapter’s named client. Metrics and Traces is the full catalog.
An outage is logged once when it starts and once when it ends, so a log search finds each outage without a line for every failed fetch.
AddRandomnessBeacons() and map every check to the liveness endpoint.ready, as AddRandomnessBeacons("ready") does, and run only that tag in the readiness probe, because a beacon is an external dependency.Degraded.
Degraded as not ready.Degraded to 200, and alert on the metrics instead.WaitForPulseAsync with no timeout.
await status.WaitForPulseAsync(CancellationToken.None).CancellationTokenSource with a timeout.