public sealed class NetworkMetricsWhat a dedicated server is asked how it is doing, published where anything can read it.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
Instrumented with System.Diagnostics.Metrics, which is not a third choice alongside OpenTelemetry and Prometheus — it is OpenTelemetry's metrics API in .NET. The BCL types are the specification's API surface; the SDK is only needed to export. So this file takes no dependency at all, and a server that already has an OpenTelemetry pipeline gets every number below by adding "Vixen.Net" to its meter list. Vixen.Net.Telemetry is there for a server that does not, and is a separate package for exactly that reason: the runtime library must not drag an exporter into a game that never asked for one.
The game publishes and the meter reads, rather than the meter reaching into the game. Observable instruments are called back on the SDK's collection thread, and the things worth reporting live in a session, a replication server and a router that are all single-threaded frame code — so a callback that walked Session.Players would eventually walk it while a player was joining, which is an exception on a background thread in a process whose whole point is to stay up. Sample is called once a tick from the loop that owns those objects and copies what it finds into plain fields; the callbacks read the fields. That is thread-safe by construction rather than by locking, and it costs a few dozen bytes of copying a tick.
Counters are cumulative and gauges are current, which is the contract the collector relies on. Everything sourced from a running total is an ObservableCounter, so a scrape that is missed loses resolution rather than data — the next one still carries the whole. Rates are the collector's job and deliberately not computed here; a metric that has already been differenced cannot be re-aggregated across three servers.
Fields and properties (5)
public const string MeterNameThe meter's name, which is what a collector is configured with.
public NetworkSession? SessionThe session to read players and the tick from.
public ReplicationServer? ReplicationThe replication server to read record counts from.
public RpcRouter? RpcThe router to read call outcomes from.
public BandwidthLedger? LedgerThe ledger to read bandwidth from.
Methods (5)
public NetworkMetrics(string? version = null)Creates the meter and registers every instrument.
public void Sample()Reads everything attached, once, from the thread that owns it.
public void RecordTick(TimeSpan elapsed)Records how long a tick took.
public void RecordSnapshot(int bytes)Records how large a snapshot was.
public void Dispose()Closes the meter, so nothing collects from it again.
Used by (4)
- CollectorVixen.Net.Tests
- NetworkMetricsTestsVixen.Net.Tests
- NetworkTelemetryVixen.Net.Telemetry
- NetworkTelemetryTestsVixen.Net.Telemetry.Tests