1+ using System . Collections . Concurrent ;
12using System . Diagnostics ;
23using System . Diagnostics . Tracing ;
34
@@ -7,14 +8,14 @@ public class PerformanceCounterService : IDisposable
78{
89 private readonly ILogger < PerformanceCounterService > _logger ;
910 private readonly Timer _metricsTimer ;
10- private readonly Dictionary < string , object > _lastMetrics ;
11+ private readonly ConcurrentDictionary < string , object > _lastMetrics ;
1112 private readonly Process _currentProcess ;
1213 private bool _disposed = false ;
1314
1415 public PerformanceCounterService ( ILogger < PerformanceCounterService > logger )
1516 {
1617 _logger = logger ;
17- _lastMetrics = new Dictionary < string , object > ( ) ;
18+ _lastMetrics = new ConcurrentDictionary < string , object > ( ) ;
1819 _currentProcess = Process . GetCurrentProcess ( ) ;
1920
2021 // 5초마다 메트릭 수집
@@ -73,10 +74,10 @@ private void CollectMetrics(object? state)
7374 }
7475
7576 // 최신 메트릭 캐시
76- _lastMetrics [ "LastUpdate" ] = metrics . Timestamp ;
77- _lastMetrics [ "WorkingMemory" ] = metrics . WorkingSetMemoryMB ;
78- _lastMetrics [ "CpuUsage" ] = metrics . CpuUsagePercent ;
79- _lastMetrics [ "ThreadPoolPending" ] = metrics . ThreadPoolPendingWorkItems ;
77+ _lastMetrics . AddOrUpdate ( "LastUpdate" , metrics . Timestamp , ( k , v ) => metrics . Timestamp ) ;
78+ _lastMetrics . AddOrUpdate ( "WorkingMemory" , metrics . WorkingSetMemoryMB , ( k , v ) => metrics . WorkingSetMemoryMB ) ;
79+ _lastMetrics . AddOrUpdate ( "CpuUsage" , metrics . CpuUsagePercent , ( k , v ) => metrics . CpuUsagePercent ) ;
80+ _lastMetrics . AddOrUpdate ( "ThreadPoolPending" , metrics . ThreadPoolPendingWorkItems , ( k , v ) => metrics . ThreadPoolPendingWorkItems ) ;
8081 }
8182 catch ( Exception ex )
8283 {
0 commit comments