Skip to content

Commit e25e217

Browse files
committed
Added total session duration metric #16 #19
1 parent 1d14789 commit e25e217

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/NTorSpectator.Observer/Services/SpectatorJob.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using NTorSpectator.Observer.TorIntegration;
23
using NTorSpectator.Services;
34
using NTorSpectator.Services.Models;
@@ -16,6 +17,7 @@ public class SpectatorJob : IJob
1617
{
1718
Buckets = Histogram.LinearBuckets(0.5, 0.5, 20)
1819
});
20+
private static readonly Gauge TotalSessionDuration = Metrics.CreateGauge("observation_session_duration", "Total observation session duration, ms");
1921

2022
private readonly ILogger<SpectatorJob> _logger;
2123
private readonly ISitesCatalogue _sitesCatalogue;
@@ -32,6 +34,8 @@ public SpectatorJob(ILogger<SpectatorJob> logger, ISitesCatalogue sitesCatalogue
3234

3335
public async Task Execute(IJobExecutionContext context)
3436
{
37+
TotalSessionDuration.Set(0);
38+
var sw = Stopwatch.StartNew();
3539
_logger.LogDebug("Starting sites observations");
3640
var sites = await _sitesCatalogue.GetAllSites();
3741
_logger.LogDebug("Got {Count} sites to observe", sites.Count);
@@ -68,6 +72,8 @@ public async Task Execute(IJobExecutionContext context)
6872
}
6973
}
7074
_logger.LogDebug("The queue is finally empty, observations finished");
75+
sw.Stop();
76+
TotalSessionDuration.Set(sw.ElapsedMilliseconds);
7177
}
7278

7379
private record QueuedSite(Site Site, int ObservationsCount);

0 commit comments

Comments
 (0)