@@ -14,13 +14,30 @@ define([
14
14
. attr ( 'title' , 'Actively used Memory (updates every 5s)' )
15
15
)
16
16
) ;
17
+ $ ( '#maintoolbar-container' ) . append (
18
+ $ ( '<div>' ) . attr ( 'id' , 'jupyter-resource-usage-display-cpu' )
19
+ . addClass ( 'btn-group' )
20
+ . addClass ( 'jupyter-resource-usage-hide' )
21
+ . addClass ( 'pull-right' ) . append (
22
+ $ ( '<strong>' ) . text ( ' CPU: ' )
23
+ ) . append (
24
+ $ ( '<span>' ) . attr ( 'id' , 'jupyter-resource-usage-cpu' )
25
+ . attr ( 'title' , 'Actively used CPU (updates every 5s)' )
26
+ )
27
+ ) ;
17
28
// FIXME: Do something cleaner to get styles in here?
18
29
$ ( 'head' ) . append (
19
30
$ ( '<style>' ) . html ( '.jupyter-resource-usage-warn { background-color: #FFD2D2; color: #D8000C; }' )
20
31
) ;
32
+ $ ( 'head' ) . append (
33
+ $ ( '<style>' ) . html ( '.jupyter-resource-usage-hide { display: none; }' )
34
+ ) ;
21
35
$ ( 'head' ) . append (
22
36
$ ( '<style>' ) . html ( '#jupyter-resource-usage-display { padding: 2px 8px; }' )
23
37
) ;
38
+ $ ( 'head' ) . append (
39
+ $ ( '<style>' ) . html ( '#jupyter-resource-usage-display-cpu { padding: 2px 8px; }' )
40
+ ) ;
24
41
}
25
42
26
43
function humanFileSize ( size ) {
@@ -54,6 +71,29 @@ define([
54
71
}
55
72
56
73
$ ( '#jupyter-resource-usage-mem' ) . text ( display ) ;
74
+
75
+ // Handle CPU display
76
+ var cpuPercent = data [ 'cpu_percent' ] ;
77
+ if ( cpuPercent ) {
78
+ // Remove hide CSS class if the metrics API gives us a CPU percent to display
79
+ $ ( '#jupyter-resource-usage-display-cpu' ) . removeClass ( 'jupyter-resource-usage-hide' ) ;
80
+ var maxCpu = data [ 'cpu_count' ] ;
81
+ var limits = data [ 'limits' ] ;
82
+ // Display CPU usage as "{percent}% ({usedCpu} / {maxCPU})" e.g. "123% (1 / 8)"
83
+ var percentString = parseFloat ( cpuPercent ) . toFixed ( 0 ) ;
84
+ var usedCpu = Math . round ( parseFloat ( cpuPercent ) / 100 ) . toString ( ) ;
85
+ var display = `${ percentString } % (${ usedCpu } / ${ maxCpu } )` ;
86
+ // Handle limit warning
87
+ if ( limits [ 'cpu' ] ) {
88
+ if ( limits [ 'cpu' ] [ 'warn' ] ) {
89
+ $ ( '#jupyter-resource-usage-display-cpu' ) . addClass ( 'jupyter-resource-usage-warn' ) ;
90
+ } else {
91
+ $ ( '#jupyter-resource-usage-display-cpu' ) . removeClass ( 'jupyter-resource-usage-warn' ) ;
92
+ }
93
+ }
94
+
95
+ $ ( '#jupyter-resource-usage-cpu' ) . text ( display ) ;
96
+ }
57
97
}
58
98
} ) ;
59
99
} ;
0 commit comments