1
- // Copyright (c) Jupyter Development Team.
2
- // Distributed under the terms of the Modified BSD License.
1
+ // Copyright (c) Jupyter Development Team. Distributed under the
2
+ // terms of the Modified BSD License.
3
3
4
4
import { VDomModel } from '@jupyterlab/apputils' ;
5
5
@@ -52,14 +52,22 @@ export namespace ResourceUsage {
52
52
if ( phase === 'rejected' ) {
53
53
const oldMemoryAvailable = this . _memoryAvailable ;
54
54
const oldCpuAvailable = this . _cpuAvailable ;
55
+ const oldDiskAvailable = this . _diskAvailable ;
56
+
55
57
this . _memoryAvailable = false ;
56
58
this . _cpuAvailable = false ;
59
+ this . _diskAvailable = false ;
60
+
57
61
this . _currentMemory = 0 ;
58
62
this . _memoryLimit = null ;
59
63
this . _cpuLimit = null ;
60
- this . _units = 'B' ;
64
+ this . _memoryUnits = 'B' ;
61
65
62
- if ( oldMemoryAvailable || oldCpuAvailable ) {
66
+ this . _diskUnits = 'B' ;
67
+ this . _diskUsed = 0 ;
68
+ this . _diskTotal = null ;
69
+
70
+ if ( oldMemoryAvailable || oldCpuAvailable || oldDiskAvailable ) {
63
71
this . stateChanged . emit ( ) ;
64
72
}
65
73
return ;
@@ -79,7 +87,7 @@ export namespace ResourceUsage {
79
87
* Whether the metrics server extension is available.
80
88
*/
81
89
get metricsAvailable ( ) : boolean {
82
- return this . _memoryAvailable || this . _cpuAvailable ;
90
+ return this . _memoryAvailable || this . _cpuAvailable || this . _diskAvailable ;
83
91
}
84
92
85
93
/**
@@ -120,8 +128,8 @@ export namespace ResourceUsage {
120
128
/**
121
129
* The units for memory usages and limits.
122
130
*/
123
- get units ( ) : MemoryUnit {
124
- return this . _units ;
131
+ get memoryUnits ( ) : MemoryUnit {
132
+ return this . _memoryUnits ;
125
133
}
126
134
127
135
/**
@@ -131,6 +139,22 @@ export namespace ResourceUsage {
131
139
return this . _currentCpuPercent ;
132
140
}
133
141
142
+ get diskAvailable ( ) : boolean {
143
+ return this . _diskAvailable ;
144
+ }
145
+
146
+ get diskUsed ( ) : number {
147
+ return this . _diskUsed ;
148
+ }
149
+
150
+ get diskTotal ( ) : number | null {
151
+ return this . _diskTotal ;
152
+ }
153
+
154
+ get diskUnits ( ) : MemoryUnit {
155
+ return this . _diskUnits ;
156
+ }
157
+
134
158
/**
135
159
* Get a list of the last metric values.
136
160
*/
@@ -164,26 +188,30 @@ export namespace ResourceUsage {
164
188
if ( value === null ) {
165
189
this . _memoryAvailable = false ;
166
190
this . _cpuAvailable = false ;
191
+ this . _diskAvailable = false ;
167
192
this . _currentMemory = 0 ;
168
193
this . _memoryLimit = null ;
169
- this . _units = 'B' ;
194
+ this . _memoryUnits = 'B' ;
195
+ this . _diskUnits = 'B' ;
196
+ this . _diskUsed = 0 ;
197
+ this . _diskTotal = null ;
170
198
this . _warn = false ;
171
199
return ;
172
200
}
173
201
174
202
const numBytes = value . pss ?? value . rss ;
175
203
const memoryLimits = value . limits . memory ;
176
204
const memoryLimit = memoryLimits ?. pss ?? memoryLimits ?. rss ?? null ;
177
- const [ currentMemory , units ] = convertToLargestUnit ( numBytes ) ;
205
+ const [ currentMemory , memoryUnits ] = convertToLargestUnit ( numBytes ) ;
178
206
const usageWarning = value . limits . memory
179
207
? value . limits . memory . warn
180
208
: false ;
181
209
182
210
this . _memoryAvailable = numBytes !== undefined ;
183
211
this . _currentMemory = currentMemory ;
184
- this . _units = units ;
212
+ this . _memoryUnits = memoryUnits ;
185
213
this . _memoryLimit = memoryLimit
186
- ? memoryLimit / MEMORY_UNIT_LIMITS [ units ]
214
+ ? memoryLimit / MEMORY_UNIT_LIMITS [ memoryUnits ]
187
215
: null ;
188
216
const memoryPercent = this . memoryLimit
189
217
? Math . min ( this . _currentMemory / this . memoryLimit , 1 )
@@ -195,19 +223,34 @@ export namespace ResourceUsage {
195
223
this . _currentCpuPercent =
196
224
value . cpu_percent !== undefined ? value . cpu_percent / 100 : 0 ;
197
225
226
+ const diskUsedBytes = value . disk_used ;
227
+ const diskTotal = value . disk_total ?? null ;
228
+ const [ diskUsed , diskUnits ] = convertToLargestUnit ( diskUsedBytes ) ;
229
+
230
+ this . _diskAvailable = diskTotal ?? false ;
231
+ this . _diskUnits = diskUnits ;
232
+ this . _diskUsed = diskUsed ;
233
+ this . _diskTotal = diskTotal
234
+ ? diskTotal / MEMORY_UNIT_LIMITS [ diskUnits ]
235
+ : null ;
236
+
198
237
this . _values . push ( { memoryPercent, cpuPercent : this . _currentCpuPercent } ) ;
199
238
this . _values . shift ( ) ;
200
239
this . stateChanged . emit ( void 0 ) ;
201
240
}
202
241
203
242
private _memoryAvailable = false ;
204
243
private _cpuAvailable = false ;
244
+ private _diskAvailable = false ;
205
245
private _currentMemory = 0 ;
206
246
private _currentCpuPercent = 0 ;
207
247
private _memoryLimit : number | null = null ;
208
248
private _cpuLimit : number | null = null ;
249
+ private _diskUsed = 0 ;
250
+ private _diskTotal : number | null = null ;
209
251
private _poll : Poll < Private . IMetricRequestResult | null > ;
210
- private _units : MemoryUnit = 'B' ;
252
+ private _memoryUnits : MemoryUnit = 'B' ;
253
+ private _diskUnits : MemoryUnit = 'B' ;
211
254
private _warn = false ;
212
255
private _values : Model . IMetricValue [ ] = [ ] ;
213
256
}
@@ -268,6 +311,8 @@ namespace Private {
268
311
pss ?: number ;
269
312
cpu_percent ?: number ;
270
313
cpu_count ?: number ;
314
+ disk_used ?: number ;
315
+ disk_total ?: number ;
271
316
limits : {
272
317
memory ?: {
273
318
rss : number ;
0 commit comments