@@ -126,6 +126,7 @@ func (tp *trackedProc) getUpdate() Update {
126
126
States : tp .metrics .States ,
127
127
Wchans : make (map [string ]int ),
128
128
}
129
+
129
130
if tp .metrics .Wchan != "" {
130
131
u .Wchans [tp .metrics .Wchan ] = 1
131
132
}
@@ -177,26 +178,33 @@ func (t *Tracker) track(groupName string, idinfo IDInfo) {
177
178
t .tracked [idinfo .ID ] = & tproc
178
179
}
179
180
180
- func (t * Tracker ) ignore (id ID , startTime time.Time ) {
181
- // only ignore ID if we didn't set recheck to true
181
+ func (t * Tracker ) shouldRecheck (id ID , startTime time.Time ) bool {
182
182
if t .recheck {
183
183
if t .recheckTimeLimit == 0 {
184
184
// plain -recheck with no time limit:
185
- return
185
+ return true
186
186
}
187
187
if startTime .Add (t .recheckTimeLimit ).After (time .Now ()) {
188
188
// -recheckWithTimeLimit is used and the limit is not reached yet:
189
- return
189
+ return true
190
190
}
191
191
}
192
- t . tracked [ id ] = nil
192
+ return false
193
193
}
194
194
195
- func (tp * trackedProc ) update (metrics Metrics , now time.Time , cerrs * CollectErrors , threads []Thread ) {
195
+ func (t * Tracker ) ignore (id ID , startTime time.Time ) {
196
+ // only ignore ID if we didn't set recheck to true
197
+ if ! t .shouldRecheck (id , startTime ) {
198
+ t .tracked [id ] = nil
199
+ }
200
+ }
201
+
202
+ func (tp * trackedProc ) update (metrics Metrics , static Static , now time.Time , cerrs * CollectErrors , threads []Thread ) {
196
203
// newcounts: resource consumption since last cycle
197
204
newcounts := metrics .Counts
198
205
tp .lastaccum = newcounts .Sub (tp .metrics .Counts )
199
206
tp .metrics = metrics
207
+ tp .static = static
200
208
tp .lastUpdate = now
201
209
if len (threads ) > 1 {
202
210
if tp .threads == nil {
@@ -272,17 +280,18 @@ func (t *Tracker) handleProc(proc Proc, updateTime time.Time) (*IDInfo, CollectE
272
280
}
273
281
}
274
282
283
+ static , err := proc .GetStatic ()
284
+ if err != nil {
285
+ if t .debug {
286
+ log .Printf ("error reading static details for %+v: %v" , procID , err )
287
+ }
288
+ return nil , cerrs
289
+ }
290
+
275
291
var newProc * IDInfo
276
292
if known {
277
- last .update (metrics , updateTime , & cerrs , threads )
293
+ last .update (metrics , static , updateTime , & cerrs , threads )
278
294
} else {
279
- static , err := proc .GetStatic ()
280
- if err != nil {
281
- if t .debug {
282
- log .Printf ("error reading static details for %+v: %v" , procID , err )
283
- }
284
- return nil , cerrs
285
- }
286
295
newProc = & IDInfo {procID , static , metrics , threads }
287
296
if t .debug {
288
297
log .Printf ("found new proc: %s" , newProc )
@@ -459,8 +468,30 @@ func (t *Tracker) Update(iter Iter) (CollectErrors, []Update, error) {
459
468
}
460
469
461
470
tp := []Update {}
462
- for _ , tproc := range t .tracked {
471
+ for procID , tproc := range t .tracked {
463
472
if tproc != nil {
473
+ // Reclassify any proc that may have changed names
474
+ if t .shouldRecheck (procID , tproc .static .StartTime ) {
475
+ nacl := common.ProcAttributes {
476
+ Name : tproc .static .Name ,
477
+ Cmdline : tproc .static .Cmdline ,
478
+ Cgroups : tproc .static .Cgroups ,
479
+ Username : t .lookupUid (tproc .static .EffectiveUID ),
480
+ PID : procID .Pid ,
481
+ StartTime : tproc .static .StartTime ,
482
+ }
483
+
484
+ shouldTrack , gname := t .namer .MatchAndName (nacl )
485
+ if shouldTrack && gname != tproc .groupName {
486
+ if t .debug {
487
+ log .Printf ("moving process %v from group %s to %s" , procID .Pid , tproc .groupName , gname )
488
+ }
489
+ tproc .groupName = gname
490
+ } else if ! shouldTrack {
491
+ t .ignore (procID , tproc .static .StartTime )
492
+ continue
493
+ }
494
+ }
464
495
tp = append (tp , tproc .getUpdate ())
465
496
}
466
497
}
0 commit comments