@@ -17,10 +17,9 @@ public class DotNetStatsCollector : IOnDemandCollector
1717 private Gauge _workingSet ;
1818 private Gauge _privateMemorySize ;
1919 private Counter _cpuTotal ;
20-
2120 private Gauge _startTime ;
22-
2321 private Gauge _numThreads ;
22+ private Gauge _pid ;
2423
2524 public DotNetStatsCollector ( )
2625 {
@@ -44,21 +43,24 @@ public void RegisterMetrics()
4443 _virtualMemorySize = Metrics . CreateGauge ( "process_windows_virtual_bytes" , "Process virtual memory size" ) ;
4544 _workingSet = Metrics . CreateGauge ( "process_windows_working_set" , "Process working set" ) ;
4645 _privateMemorySize = Metrics . CreateGauge ( "process_windows_private_bytes" , "Process private memory size" ) ;
47- // _openHandles = Metrics.CreateGauge("process_windows_open_handles", "Number of open handles");
4846 _numThreads = Metrics . CreateGauge ( "process_windows_num_threads" , "Total number of threads" ) ;
47+ _pid = Metrics . CreateGauge ( "process_windows_processid" , "Process ID" ) ;
4948
5049 // .net specific metrics
5150 _totalMemory = Metrics . CreateGauge ( "dotnet_totalmemory" , "Total known allocated memory" ) ;
5251 _perfErrors = Metrics . CreateCounter ( "dotnet_collection_errors_total" , "Total number of errors that occured during collections" ) ;
5352
5453 var epoch = new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
5554 _startTime . Set ( ( _process . StartTime . ToUniversalTime ( ) - epoch ) . TotalSeconds ) ;
55+ _pid . Set ( _process . Id ) ;
5656 }
5757
5858 public void UpdateMetrics ( )
5959 {
6060 try
6161 {
62+ _process . Refresh ( ) ;
63+
6264 for ( var gen = 0 ; gen <= GC . MaxGeneration ; gen ++ )
6365 {
6466 var collectionCount = _collectionCounts [ gen ] ;
@@ -70,7 +72,6 @@ public void UpdateMetrics()
7072 _workingSet . Set ( _process . WorkingSet64 ) ;
7173 _privateMemorySize . Set ( _process . PrivateMemorySize64 ) ;
7274 _cpuTotal . Inc ( _process . TotalProcessorTime . TotalSeconds - _cpuTotal . Value ) ;
73-
7475 _numThreads . Set ( _process . Threads . Count ) ;
7576 }
7677 catch ( Exception )
0 commit comments