IMentorMetricsStore interface
The IMentorMetricsStore interface of Novior.MentorAgent.Abstractions.Interfaces: Optional persistence/source for the admin token & cost dashboard (roadmap…
On this page
Optional persistence/source for the admin token & cost dashboard (roadmap #9). By default MentorAgent keeps metrics only in RAM (they reset when the process restarts). Register a custom implementation beforeAddMentorAgent() to make the dashboard survive restarts or to read aggregated data from an external backend:
// Local durability — persist a JSON/DB snapshot; the dashboard keeps reading live RAM,
// seeded from the last save on startup.
builder.Services.AddSingleton<IMentorMetricsStore, FileMetricsStore>();
// External source — the dashboard reads the aggregate the #8 OpenTelemetry export already
// pushed to Prometheus / Azure Monitor (multi-instance, historical).
builder.Services.AddSingleton<IMentorMetricsStore, PrometheusMetricsStore>();
builder.Services.AddMentorAgent(options => { ... });The two scenarios use different halves of this contract, so each implementation overrides only the methods it needs (the others keep their no-op defaults):
- Local store (file/DB): implements
IMentorMetricsStore.LoadForSeedAsync(restore totals at startup) andIMentorMetricsStore.SaveAsync(persist periodically + on shutdown).IMentorMetricsStore.QueryAsyncreturnsnullso the dashboard serves the live in-RAM snapshot. - External source (Prometheus/Azure Monitor): implements
IMentorMetricsStore.QueryAsyncto query the backend the #8 export already writes to.IMentorMetricsStore.SaveAsyncis a no-op (OpenTelemetry already exports) and there is nothing to seed.
Definition
Section titled “Definition”Namespace: Novior.MentorAgent.Abstractions.Interfaces. Package: Novior.MentorAgent.Abstractions.
public interface IMentorMetricsStore
dotnet add package Novior.MentorAgent.AbstractionsMethods
Section titled “Methods”LoadForSeedAsync
Section titled “LoadForSeedAsync”Task<MentorMetricsSnapshot?> LoadForSeedAsync(CancellationToken ct = default)
Called once at startup so a durable store can restore the previous totals into the in-RAM counters. Return null to start fresh (external sources return null — they serve live via IMentorMetricsStore.QueryAsync instead).
QueryAsync
Section titled “QueryAsync”Task<MentorMetricsSnapshot?> QueryAsync(CancellationToken ct = default)
Called on every dashboard/endpoint read. External sources query the backend and return the authoritative (possibly multi-instance, historical) aggregate. Local/null stores return null, and the caller serves the live in-RAM snapshot instead.
SaveAsync
Section titled “SaveAsync”Task SaveAsync(MentorMetricsSnapshot snapshot, CancellationToken ct = default)
Called periodically and on graceful shutdown with the current snapshot. Durable stores persist it (file/DB); external sources leave the default no-op because #8 OpenTelemetry already exports.
