Metron is simple metrics library.
- Create model which inherits from Model. Model contains Guid Id and DateTimeOffset CreatedAt properties which initialized at parameterless constructor.
public sealed class UserLoggedIn : Model
{
public string Username { get; set; }
}
- Initialize repository which implements IModelRepository
public sealed class InMemoryRepository : IModelRepository<UserLoggedIn>
{
private readonly List<UserLoggedIn> _items;
public InMemoryRepository()
{
_items = new List<UserLoggedIn>();
}
public Task Add(UserLoggedIn model, CancellationToken cancellationToken = default)
{
_items.Add(model);
return Task.CompletedTask;
}
public Task<IReadOnlyCollection<UserLoggedIn>> Get(CancellationToken cancellationToken = default)
=> Task.FromResult<IReadOnlyCollection<UserLoggedIn>>(_items);
}
- Initialize Metron instance with created repository.
var repository = new InMemoryRepository();
var metron = new Metron(repository);
- Use metron instance to write and get metrics.
var item = new UserLoggedIn { Username = "root" };
await metron.Add(item);
var items = metron.Get(CancellationToken.None);
DI extensions for Metron.
Avaliable containers:
- Autofac
Readme in progress
Repositories for Metron.
Avaliable repositories:
- MongoDb
Readme in progress