@@ -14,13 +14,26 @@ 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 ( 'pull-right' ) . append (
21
+ $ ( '<strong>' ) . text ( ' CPU: ' )
22
+ ) . append (
23
+ $ ( '<span>' ) . attr ( 'id' , 'jupyter-resource-usage-cpu' )
24
+ . attr ( 'title' , 'Actively used CPU (updates every 5s)' )
25
+ )
26
+ ) ;
17
27
// FIXME: Do something cleaner to get styles in here?
18
28
$ ( 'head' ) . append (
19
29
$ ( '<style>' ) . html ( '.jupyter-resource-usage-warn { background-color: #FFD2D2; color: #D8000C; }' )
20
30
) ;
21
31
$ ( 'head' ) . append (
22
32
$ ( '<style>' ) . html ( '#jupyter-resource-usage-display { padding: 2px 8px; }' )
23
33
) ;
34
+ $ ( 'head' ) . append (
35
+ $ ( '<style>' ) . html ( '#jupyter-resource-usage-display-cpu { padding: 2px 8px; }' )
36
+ ) ;
24
37
}
25
38
26
39
function humanFileSize ( size ) {
@@ -56,6 +69,28 @@ define([
56
69
$ ( '#jupyter-resource-usage-mem' ) . text ( display ) ;
57
70
}
58
71
} ) ;
72
+ $ . getJSON ( {
73
+ url : utils . get_body_data ( 'baseUrl' ) + 'api/metrics/v1' ,
74
+ success : function ( data ) {
75
+ var cpuPercent = data [ 'cpu_percent' ] ;
76
+ var maxCpu = data [ 'cpu_count' ] ;
77
+ var limits = data [ 'limits' ] ;
78
+ var display = parseFloat ( cpuPercent ) . toFixed ( 0 ) + "% (" ;
79
+
80
+ if ( limits [ 'cpu' ] ) {
81
+ if ( limits [ 'cpu' ] [ 'cpu' ] ) {
82
+ display += ( Math . round ( parseFloat ( cpuPercent ) / 100 ) ) . toString ( ) + " / " + maxCpu + ")" ;
83
+ }
84
+ if ( limits [ 'cpu' ] [ 'warn' ] ) {
85
+ $ ( '#jupyter-resource-usage-display-cpu' ) . addClass ( 'jupyter-resource-usage-warn' ) ;
86
+ } else {
87
+ $ ( '#jupyter-resource-usage-display-cpu' ) . removeClass ( 'jupyter-resource-usage-warn' ) ;
88
+ }
89
+ }
90
+
91
+ $ ( '#jupyter-resource-usage-cpu' ) . text ( display ) ;
92
+ }
93
+ } ) ;
59
94
} ;
60
95
61
96
var load_ipython_extension = function ( ) {
0 commit comments