@@ -99,8 +99,8 @@ impl ProcessCollector {
9999 . unwrap ( ) ;
100100 // proc_start_time init once because it is immutable
101101 if let Ok ( boot_time) = procfs:: boot_time_secs ( ) {
102- if let Ok ( p ) = procfs:: process:: Process :: myself ( ) {
103- start_time. set ( p . stat . starttime as i64 / * CLK_TCK + boot_time as i64 ) ;
102+ if let Ok ( stat ) = procfs:: process:: Process :: myself ( ) . and_then ( |p| p . stat ( ) ) {
103+ start_time. set ( stat. starttime as i64 / * CLK_TCK + boot_time as i64 ) ;
104104 }
105105 }
106106 descs. extend ( start_time. desc ( ) . into_iter ( ) . cloned ( ) ) ;
@@ -156,25 +156,27 @@ impl Collector for ProcessCollector {
156156 }
157157 }
158158
159- // memory
160- self . vsize . set ( p. stat . vsize as i64 ) ;
161- self . rss . set ( p. stat . rss * * PAGESIZE ) ;
159+ let mut cpu_total_mfs = None ;
160+ if let Ok ( stat) = p. stat ( ) {
161+ // memory
162+ self . vsize . set ( stat. vsize as i64 ) ;
163+ self . rss . set ( ( stat. rss as i64 ) * * PAGESIZE ) ;
162164
163- // cpu
164- let cpu_total_mfs = {
165- let total = ( p. stat . utime + p. stat . stime ) / * CLK_TCK as u64 ;
165+ // cpu
166+ let total = ( stat. utime + stat. stime ) / * CLK_TCK as u64 ;
166167 let past = self . cpu_total . get ( ) ;
167168 self . cpu_total . inc_by ( total - past) ;
169+ cpu_total_mfs = Some ( self . cpu_total . collect ( ) ) ;
168170
169- self . cpu_total . collect ( )
170- } ;
171-
172- // threads
173- self . threads . set ( p. stat . num_threads ) ;
171+ // threads
172+ self . threads . set ( stat. num_threads ) ;
173+ }
174174
175175 // collect MetricFamilys.
176176 let mut mfs = Vec :: with_capacity ( METRICS_NUMBER ) ;
177- mfs. extend ( cpu_total_mfs) ;
177+ if let Some ( cpu) = cpu_total_mfs {
178+ mfs. extend ( cpu) ;
179+ }
178180 mfs. extend ( self . open_fds . collect ( ) ) ;
179181 mfs. extend ( self . max_fds . collect ( ) ) ;
180182 mfs. extend ( self . vsize . collect ( ) ) ;
0 commit comments