Worker metrics
A worker pushes its counters as events, so nobody has to poll them with the status command.
WorkerMetrics (Virtufin.Worker.DevKit) handles this.
private WorkerMetrics? _metrics;
public Task StartAsync(IWorkerContext context, CancellationToken stop)
{
_metrics = WorkerMetrics.Start(context, "eventstore",
() => new Dictionary<string, long> { ["events"] = _events, ["rows"] = _rows, ["failed"] = _failed },
stop);
return Task.CompletedTask;
}
public async Task StopAsync(CancellationToken cancellationToken)
{
if (_metrics is not null) await _metrics.DisposeAsync();
}
At every interval, WorkerMetrics reads the counters. If they changed since the last push, it publishes one
CloudEvent:
| Topic | wrk.<worker_type>.metrics, one per worker type |
| ce-type | com.virtufin.<worker_type>.metrics |
| Subject | worker/<worker_id> |
| Data | worker-devkit's WorkerMetrics message (application/x-virtufin-worker-metrics+protobuf): worker_id, counters (name to int64), at |
The schema is registered with the gateway on the first push, so the TUI, the app and the notebooks decode the counters through the registry. In the protobuf JSON mapping a counter (int64) reads as text.
The names come from the core worker entity's metrics event in the naming library (virtufin.core/worker). A
consumer finds them there, never copies them, and subscribes once per worker type.
Configuration
| Config key | Default | Meaning |
|---|---|---|
metricsseconds |
5 |
Seconds between pushes. 0 turns the metrics off. Any other value that is not a non-negative integer fails the start. |
Behavior
- Only changes are pushed. Idle workers publish nothing, so a consumer keeps the last event it received.
- At most one push per interval, however fast the counters change.
- A failed tick (the publish, or counters that throw) is logged as a warning and retried at the next tick, because the counters still differ from the last push.
- An older host: workers resolve
Virtufin.Namingto the WorkManager Runtime's copy. On a Runtime before 0.41.6, which has nometricsevent,Startlogs a warning and returnsnull, and the worker runs without metrics. - Stopping: disposing the
WorkerMetricsstops it, and so does canceling the start'sstoptoken. Disposing waits for any push in flight.