@@ -14,13 +14,26 @@ define([
1414 . attr ( 'title' , 'Actively used Memory (updates every 5s)' )
1515 )
1616 ) ;
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+ ) ;
1727 // FIXME: Do something cleaner to get styles in here?
1828 $ ( 'head' ) . append (
1929 $ ( '<style>' ) . html ( '.jupyter-resource-usage-warn { background-color: #FFD2D2; color: #D8000C; }' )
2030 ) ;
2131 $ ( 'head' ) . append (
2232 $ ( '<style>' ) . html ( '#jupyter-resource-usage-display { padding: 2px 8px; }' )
2333 ) ;
34+ $ ( 'head' ) . append (
35+ $ ( '<style>' ) . html ( '#jupyter-resource-usage-display-cpu { padding: 2px 8px; }' )
36+ ) ;
2437 }
2538
2639 function humanFileSize ( size ) {
@@ -56,6 +69,28 @@ define([
5669 $ ( '#jupyter-resource-usage-mem' ) . text ( display ) ;
5770 }
5871 } ) ;
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+ } ) ;
5994 } ;
6095
6196 var load_ipython_extension = function ( ) {
0 commit comments