1
+ using System . Diagnostics ;
1
2
using NTorSpectator . Observer . TorIntegration ;
2
3
using NTorSpectator . Services ;
3
4
using NTorSpectator . Services . Models ;
@@ -16,6 +17,7 @@ public class SpectatorJob : IJob
16
17
{
17
18
Buckets = Histogram . LinearBuckets ( 0.5 , 0.5 , 20 )
18
19
} ) ;
20
+ private static readonly Gauge TotalSessionDuration = Metrics . CreateGauge ( "observation_session_duration" , "Total observation session duration, ms" ) ;
19
21
20
22
private readonly ILogger < SpectatorJob > _logger ;
21
23
private readonly ISitesCatalogue _sitesCatalogue ;
@@ -32,6 +34,8 @@ public SpectatorJob(ILogger<SpectatorJob> logger, ISitesCatalogue sitesCatalogue
32
34
33
35
public async Task Execute ( IJobExecutionContext context )
34
36
{
37
+ TotalSessionDuration . Set ( 0 ) ;
38
+ var sw = Stopwatch . StartNew ( ) ;
35
39
_logger . LogDebug ( "Starting sites observations" ) ;
36
40
var sites = await _sitesCatalogue . GetAllSites ( ) ;
37
41
_logger . LogDebug ( "Got {Count} sites to observe" , sites . Count ) ;
@@ -68,6 +72,8 @@ public async Task Execute(IJobExecutionContext context)
68
72
}
69
73
}
70
74
_logger . LogDebug ( "The queue is finally empty, observations finished" ) ;
75
+ sw . Stop ( ) ;
76
+ TotalSessionDuration . Set ( sw . ElapsedMilliseconds ) ;
71
77
}
72
78
73
79
private record QueuedSite ( Site Site , int ObservationsCount ) ;
0 commit comments