Path: redb-route/redb.Route/Abstractions/IEndpointStatistics.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Abstractions/IEndpointStatistics.cs
----
namespace redb.Route.Abstractions;
///
/// Health status of an endpoint based on recent error rate and activity.
///
public enum EndpointHealthStatus
{
/// Everything is operating normally.
Healthy,
/// There are issues, but endpoint is operational.
Warning,
/// High error rate detected.
Critical,
/// Endpoint is not running.
Failed
}
///
/// Optional statistics interface for endpoints that track message counts.
/// Not part of — consumers/services check via endpoint is IEndpointStatistics stats.
/// Counters use for thread safety.
///
public interface IEndpointStatistics
{
/// Number of messages received (consumed) by this endpoint.
long MessagesIn { get; }
/// Number of messages sent (produced) by this endpoint.
long MessagesOut { get; }
/// Number of errors during processing.
long Errors { get; }
/// Number of warnings during processing.
long Warnings { get; }
///
/// Bytes that entered the endpoint (estimated from message bodies): what a consumer received,
/// and what a producer got back in reply.
///
long BytesIn { get; }
///
/// Bytes that left the endpoint: what a producer sent, and what a consumer wrote back as a
/// reply. Counterpart of , so the two together describe an endpoint's
/// volume in both directions rather than lumping it into one number.
///
long BytesOut { get; }
///
/// Requests shed by an admission limit (e.g. maxConcurrentRequests) BEFORE a pipeline
/// ran: the transport answered 429/503 and no exchange was created, so these are counted in
/// neither nor .
///
long Rejected { get; }
///
/// Exchanges abandoned by a cooperative cancellation: the caller's token was cancelled while
/// the pipeline ran (a closed dashboard mid-poll, an aborted HTTP request). Unlike
/// these ARE counted in — the exchange had
/// entered the pipeline — but never in : the route did nothing wrong, and
/// counting them there turned healthy routes red under nothing but polling churn. An
/// thrown while the caller's token is still live is
/// an internal failure and stays in . A consumer endpoint's completed
/// count is therefore MessagesIn - Errors - Cancelled.
///
long Cancelled { get; }
///
/// Requests the transport refused as the caller's fault and answered with the protocol's own error: malformed or
/// oversized, not authenticated, not what the agreement allows (an AS4 ebMS error, a SOAP Sender fault). No
/// exchange was created, so like they are counted in neither nor
/// , and they do not feed : a partner sending what the endpoint cannot
/// accept is not a failure of the route. A rise is still worth a look: a partner's broken configuration, or our
/// key or agreement changed under it. says why the last one was refused.
/// The refusal members have default implementations (none counted) so that an implementation written before them
/// still compiles; EndpointBase counts them.
///
long Refused => 0;
///
/// Connections or links of this endpoint that were lost while a route ran and came back, as its connection supervisors
/// () report them. Default implementation: none counted, so that an
/// implementation written before it still compiles; EndpointBase counts them.
///
long Reconnects => 0;
/// Timestamp of the last refusal, or null if none.
DateTime? LastRefusalTime => null;
/// Why the last request was refused, or empty string.
string LastRefusalMessage => string.Empty;
/// Timestamp of the last message activity (in or out), or null if no activity yet.
DateTime? LastActivity { get; }
/// Timestamp when the endpoint started tracking statistics.
DateTime StartTime { get; }
/// Duration the endpoint has been tracking statistics.
TimeSpan Uptime { get; }
/// Average processing time over the last 100 messages.
TimeSpan AverageProcessingTime { get; }
/// Messages per second over a 60-second sliding window.
double ThroughputPerSecond { get; }
/// Timestamp of the last error, or null if no errors.
DateTime? LastErrorTime { get; }
/// Message text of the last error, or empty string.
string LastErrorMessage { get; }
/// Timestamp of the last warning, or null if no warnings.
DateTime? LastWarningTime { get; }
/// Message text of the last warning, or empty string.
string LastWarningMessage { get; }
/// Health status computed from error rate and activity.
EndpointHealthStatus HealthStatus { get; }
/// Human-readable reason for the current health status.
string HealthReason { get; }
/// Resets all counters to zero.
void ResetStatistics();
/// Record an incoming message (consumed). Thread-safe.
void RecordMessageIn();
/// Record an outgoing message (produced). Thread-safe.
void RecordMessageOut();
/// Record a processing error. Thread-safe.
void RecordError();
/// Record a processing error with exception details. Thread-safe.
void RecordError(Exception exception);
/// Record a processing warning. Thread-safe.
void RecordWarning();
/// Record a processing warning with message. Thread-safe.
void RecordWarning(string message);
/// Record processing time of a single message. Thread-safe.
void RecordProcessingTime(TimeSpan duration);
/// Record a request shed by an admission limit before the pipeline ran. Thread-safe.
void RecordRejected();
/// Record an exchange abandoned by a cooperative cancellation. Thread-safe.
void RecordCancelled();
/// Record a request refused as the caller's fault, with the reason (see ). Thread-safe.
void RecordRefused(string reason) { }
/// Record incoming bytes (message body size). Thread-safe.
void RecordBytesIn(long bytes);
/// Record outgoing bytes (message body size). Thread-safe.
void RecordBytesOut(long bytes);
}