@@ -3,29 +3,75 @@ import {
3
3
JupyterFrontEnd ,
4
4
JupyterFrontEndPlugin ,
5
5
} from '@jupyterlab/application' ;
6
+
7
+ import { IToolbarWidgetRegistry } from '@jupyterlab/apputils' ;
8
+
9
+ import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
10
+
6
11
import { INotebookTracker } from '@jupyterlab/notebook' ;
12
+
7
13
import { LabIcon } from '@jupyterlab/ui-components' ;
14
+
8
15
import { ICommandPalette } from '@jupyterlab/apputils' ;
16
+
9
17
import { IConsoleTracker } from '@jupyterlab/console' ;
10
- import { KernelUsagePanel } from './panel' ;
11
- import tachometer from '../style/tachometer.svg' ;
12
18
13
19
import { IStatusBar } from '@jupyterlab/statusbar' ;
14
20
15
21
import { ITranslator } from '@jupyterlab/translation' ;
16
22
17
- import { MemoryUsage } from './memoryUsage' ;
23
+ import { JSONObject } from '@lumino/coreutils' ;
24
+
25
+ import { KernelUsagePanel } from './panel' ;
26
+
27
+ import tachometer from '../style/tachometer.svg' ;
28
+
29
+ import { ResourceUsage } from './model' ;
30
+
31
+ import { ResourceUsageStatus } from './resourceUsage' ;
32
+
18
33
import { KernelWidgetTracker } from './tracker' ;
19
34
35
+ import { CpuView } from './cpuView' ;
36
+
37
+ import { MemoryView } from './memoryView' ;
38
+
39
+ /**
40
+ * Disable system monitor panels by default.
41
+ */
42
+ const DEFAULT_ENABLE_SYSTEM_MONITOR = false ;
43
+
44
+ /**
45
+ * The default refresh rate.
46
+ */
47
+ const DEFAULT_REFRESH_RATE = 5000 ;
48
+
49
+ /**
50
+ * The default memory label.
51
+ */
52
+ const DEFAULT_MEMORY_LABEL = 'Mem: ' ;
53
+
54
+ /**
55
+ * The default CPU label.
56
+ */
57
+ const DEFAULT_CPU_LABEL = 'CPU: ' ;
58
+
59
+ /**
60
+ * An interface for resource settings.
61
+ */
62
+ interface IResourceSettings extends JSONObject {
63
+ label : string ;
64
+ }
65
+
20
66
namespace CommandIDs {
21
67
export const getKernelUsage = 'kernel-usage:get' ;
22
68
}
23
69
24
70
/**
25
71
* Initialization data for the jupyter-resource-usage extension.
26
72
*/
27
- const memoryStatusPlugin : JupyterFrontEndPlugin < void > = {
28
- id : '@jupyter-server/resource-usage:memory- status-item' ,
73
+ const resourceStatusPlugin : JupyterFrontEndPlugin < void > = {
74
+ id : '@jupyter-server/resource-usage:status-item' ,
29
75
autoStart : true ,
30
76
requires : [ IStatusBar , ITranslator ] ,
31
77
activate : (
@@ -34,9 +80,9 @@ const memoryStatusPlugin: JupyterFrontEndPlugin<void> = {
34
80
translator : ITranslator
35
81
) => {
36
82
const trans = translator . load ( 'jupyter-resource-usage' ) ;
37
- const item = new MemoryUsage ( trans ) ;
83
+ const item = new ResourceUsageStatus ( trans ) ;
38
84
39
- statusBar . registerStatusItem ( memoryStatusPlugin . id , {
85
+ statusBar . registerStatusItem ( resourceStatusPlugin . id , {
40
86
item,
41
87
align : 'left' ,
42
88
rank : 2 ,
@@ -46,6 +92,54 @@ const memoryStatusPlugin: JupyterFrontEndPlugin<void> = {
46
92
} ,
47
93
} ;
48
94
95
+ /**
96
+ * Initialization data for the jupyterlab-system-monitor extension.
97
+ */
98
+ const systemMonitorPlugin : JupyterFrontEndPlugin < void > = {
99
+ id : '@jupyter-server/resource-usage:topbar-item' ,
100
+ autoStart : true ,
101
+ requires : [ IToolbarWidgetRegistry ] ,
102
+ optional : [ ISettingRegistry ] ,
103
+ activate : async (
104
+ app : JupyterFrontEnd ,
105
+ toolbarRegistry : IToolbarWidgetRegistry ,
106
+ settingRegistry : ISettingRegistry
107
+ ) => {
108
+ let enablePlugin = DEFAULT_ENABLE_SYSTEM_MONITOR ;
109
+ let refreshRate = DEFAULT_REFRESH_RATE ;
110
+ let cpuLabel = DEFAULT_CPU_LABEL ;
111
+ let memoryLabel = DEFAULT_MEMORY_LABEL ;
112
+
113
+ if ( settingRegistry ) {
114
+ const settings = await settingRegistry . load ( systemMonitorPlugin . id ) ;
115
+ enablePlugin = settings . get ( 'enable' ) . composite as boolean ;
116
+ refreshRate = settings . get ( 'refreshRate' ) . composite as number ;
117
+ const cpuSettings = settings . get ( 'cpu' ) . composite as IResourceSettings ;
118
+ cpuLabel = cpuSettings . label ;
119
+ const memorySettings = settings . get ( 'memory' )
120
+ . composite as IResourceSettings ;
121
+ memoryLabel = memorySettings . label ;
122
+ }
123
+
124
+ const model = new ResourceUsage . Model ( { refreshRate } ) ;
125
+ await model . refresh ( ) ;
126
+
127
+ if ( enablePlugin && model . cpuAvailable ) {
128
+ toolbarRegistry . addFactory ( 'TopBar' , 'cpu' , ( ) => {
129
+ const cpu = CpuView . createCpuView ( model , cpuLabel ) ;
130
+ return cpu ;
131
+ } ) ;
132
+ }
133
+
134
+ if ( enablePlugin && model . memoryAvailable ) {
135
+ toolbarRegistry . addFactory ( 'TopBar' , 'memory' , ( ) => {
136
+ const memory = MemoryView . createMemoryView ( model , memoryLabel ) ;
137
+ return memory ;
138
+ } ) ;
139
+ }
140
+ } ,
141
+ } ;
142
+
49
143
const kernelUsagePlugin : JupyterFrontEndPlugin < void > = {
50
144
id : '@jupyter-server/resource-usage:kernel-panel-item' ,
51
145
autoStart : true ,
@@ -101,7 +195,8 @@ const kernelUsagePlugin: JupyterFrontEndPlugin<void> = {
101
195
} ;
102
196
103
197
const plugins : JupyterFrontEndPlugin < any > [ ] = [
104
- memoryStatusPlugin ,
198
+ resourceStatusPlugin ,
199
+ systemMonitorPlugin ,
105
200
kernelUsagePlugin ,
106
201
] ;
107
202
export default plugins ;
0 commit comments