@@ -76,6 +76,7 @@ export class ChildProcessTracker {
76
76
cpu : 50 ,
77
77
elapsed : 30 * 1000 , // 30 seconds
78
78
}
79
+ static readonly logger = getLogger ( 'childProcess' )
79
80
#processByPid: Map < number , ChildProcess > = new Map < number , ChildProcess > ( )
80
81
#pids: PollingSet < number >
81
82
@@ -94,28 +95,34 @@ export class ChildProcessTracker {
94
95
95
96
private async monitor ( ) {
96
97
this . cleanUp ( )
97
- getLogger ( ) . debug ( `Active running processes size: ${ this . #pids. size } ` )
98
+ ChildProcessTracker . logger . debug ( `Active running processes size: ${ this . #pids. size } ` )
98
99
99
100
for ( const pid of this . #pids. values ( ) ) {
100
101
await this . checkProcessUsage ( pid )
101
102
}
102
103
}
103
104
104
105
private async checkProcessUsage ( pid : number ) : Promise < void > {
105
- if ( this . #pids. has ( pid ) ) {
106
- const stats = await this . getUsage ( pid )
107
- getLogger ( ) . debug ( `stats for ${ pid } : %O` , stats )
106
+ if ( ! this . #pids. has ( pid ) ) {
107
+ ChildProcessTracker . logger . warn ( `ChildProcess: Missing process with id ${ pid } ` )
108
+ return
109
+ }
110
+ const stats = await this . getUsage ( pid )
111
+ if ( stats ) {
112
+ ChildProcessTracker . logger . debug ( `stats for ${ pid } : %O` , stats )
108
113
if ( stats . memory > ChildProcessTracker . thresholds . memory ) {
109
- getLogger ( ) . warn ( `Process ${ pid } exceeded memory threshold: ${ stats . memory } ` )
114
+ ChildProcessTracker . logger . warn (
115
+ `ChildProcess: Process ${ pid } exceeded memory threshold: ${ stats . memory } `
116
+ )
110
117
}
111
118
if ( stats . cpu > ChildProcessTracker . thresholds . cpu ) {
112
- getLogger ( ) . warn ( `Process ${ pid } exceeded cpu threshold: ${ stats . cpu } ` )
119
+ ChildProcessTracker . logger . warn ( `ChildProcess: Process ${ pid } exceeded cpu threshold: ${ stats . cpu } ` )
113
120
}
114
121
if ( stats . elapsed > ChildProcessTracker . thresholds . elapsed ) {
115
- getLogger ( ) . warn ( `Process ${ pid } exceeded time threshold: ${ stats . elapsed } ` )
122
+ ChildProcessTracker . logger . warn (
123
+ `ChildProcess: Process ${ pid } exceeded time threshold: ${ stats . elapsed } `
124
+ )
116
125
}
117
- } else {
118
- getLogger ( ) . warn ( `Missing process with id ${ pid } ` )
119
126
}
120
127
}
121
128
0 commit comments