Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
Add custom metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
dougludlow committed May 29, 2021
1 parent c07702a commit 2661ae2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/Imagine.Students.Api/Services/TrackedStudentsStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Imagine.Students.Api.Models;
using Prometheus;

namespace Imagine.Students.Api.Services
{
public class TrackedStudentsStore : IStudentsStore
{
private const string MetricName = "student_api_operation_duration_seconds";

private const string MetricDescrption = "student_api_operation_duration_seconds";

private static readonly HistogramConfiguration Config = new HistogramConfiguration
{
StaticLabels = new()
{
{ "class", nameof(TrackedStudentsStore) },
{ "method", nameof(GetStudents) }
}
};

private static readonly Histogram Histogram = Metrics.CreateHistogram(MetricName, MetricDescrption, Config);

private readonly IStudentsStore _store;

public TrackedStudentsStore(IStudentsStore store)
{
_store = store;
}

public async Task<IEnumerable<Student>> GetStudents(Guid classroomId)
{
using (Histogram.NewTimer())
{
return await _store.GetStudents(classroomId);
}
}
}
}
1 change: 1 addition & 0 deletions src/Imagine.Students.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void ConfigureServices(IServiceCollection services)

services.AddTransient<IStudentsStore, StudentsStore>();
services.Decorate<IStudentsStore, BrokenStudentsStore>();
services.Decorate<IStudentsStore, TrackedStudentsStore>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down

0 comments on commit 2661ae2

Please sign in to comment.