Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds custom config to show/hide host usage info #210

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion jupyter_resource_usage/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ async def get(self, matched_part=None, *args, **kwargs):
)
return

config = self.settings["jupyter_resource_usage_display_config"]

kernel_id = matched_part
km = self.kernel_manager
lkm = km.pinned_superclass.get_kernel(km, kernel_id)
Expand All @@ -114,7 +116,6 @@ async def get(self, matched_part=None, *args, **kwargs):

control_channel = client.control_channel
usage_request = session.msg("usage_request", {})

control_channel.send(usage_request)
poller = zmq.asyncio.Poller()
control_socket = control_channel.socket
Expand All @@ -137,6 +138,7 @@ async def get(self, matched_part=None, *args, **kwargs):
res = await res
if res:
res["kernel_id"] = kernel_id
res["content"].update({"host_usage_flag": config.show_host_usage})
out = json.dumps(res, default=date_default)
client.stop_channels()
self.write(out)
7 changes: 7 additions & 0 deletions jupyter_resource_usage/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,10 @@ def _cpu_limit_default(self):
Set to False in order to disable reporting of Prometheus style metrics.
""",
).tag(config=True)

show_host_usage = Bool(
default_value=True,
help="""
Set to True in order to show host cpu and host virtual memory info.
""",
).tag(config=True)
99 changes: 50 additions & 49 deletions packages/labextension/src/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Usage = {
pid: number;
host_cpu_percent: number;
cpu_count: number;
host_usage_flag: boolean;
host_virtual_memory: {
active: number;
available: number;
Expand Down Expand Up @@ -302,56 +303,56 @@ const KernelUsage = (props: {
{formatForDisplay(usage.kernel_memory)}
</div>
<hr className="jp-KernelUsage-section-separator"></hr>
<h4 className="jp-KernelUsage-section-separator">
{props.trans.__('Host CPU')}
</h4>
{usage.host_cpu_percent && (
<div className="jp-KernelUsage-separator">
{props.trans._n(
'%2%% used on %1 CPU',
'%2%% used on %1 CPUs',
usage.cpu_count,
usage.host_cpu_percent.toFixed(1)
{usage?.host_usage_flag ? (
<>
<h4 className="jp-KernelUsage-section-separator">
{props.trans.__('Host CPU')}
</h4>
{usage.host_cpu_percent && (
<div className="jp-KernelUsage-separator">
{props.trans._n(
'%2%% used on %1 CPU',
'%2%% used on %1 CPUs',
usage.cpu_count,
usage.host_cpu_percent.toFixed(1)
)}
</div>
)}
</div>
)}
<h4 className="jp-KernelUsage-section-separator">
{props.trans.__('Host Virtual Memory')}
</h4>
<div className="jp-KernelUsage-separator">
{props.trans.__('Active:')}{' '}
{formatForDisplay(usage.host_virtual_memory.active)}
</div>
<div className="jp-KernelUsage-separator">
{props.trans.__('Available:')}{' '}
{formatForDisplay(usage.host_virtual_memory.available)}
</div>
<div className="jp-KernelUsage-separator">
{props.trans.__('Free:')}{' '}
{formatForDisplay(usage.host_virtual_memory.free)}
</div>
<div className="jp-KernelUsage-separator">
{props.trans.__('Inactive:')}{' '}
{formatForDisplay(usage.host_virtual_memory.inactive)}
</div>
{usage.host_virtual_memory.percent && (
<div className="jp-KernelUsage-separator">
{props.trans.__('Percent used:')}{' '}
{usage.host_virtual_memory.percent.toFixed(1)}%
</div>
)}
<div className="jp-KernelUsage-separator">
{props.trans.__('Total:')}{' '}
{formatForDisplay(usage.host_virtual_memory.total)}
</div>
<div className="jp-KernelUsage-separator">
{props.trans.__('Used:')}{' '}
{formatForDisplay(usage.host_virtual_memory.used)}
</div>
<div className="jp-KernelUsage-separator">
{props.trans.__('Wired:')}{' '}
{formatForDisplay(usage.host_virtual_memory.wired)}
</div>
<h4 className="jp-KernelUsage-section-separator">
{props.trans.__('Host Virtual Memory')}
</h4>
<div className="jp-KernelUsage-separator">
{props.trans.__('Active:')}{' '}
{formatForDisplay(usage.host_virtual_memory.active)}
</div>
<div className="jp-KernelUsage-separator">
{props.trans.__('Available:')}{' '}
{formatForDisplay(usage.host_virtual_memory.available)}
</div>
<div className="jp-KernelUsage-separator">
{props.trans.__('Free:')}{' '}
{formatForDisplay(usage.host_virtual_memory.free)}
</div>
<div className="jp-KernelUsage-separator">
{props.trans.__('Inactive:')}{' '}
{formatForDisplay(usage.host_virtual_memory.inactive)}
</div>
{usage.host_virtual_memory.percent && (
<div className="jp-KernelUsage-separator">
{props.trans.__('Percent used:')}{' '}
{usage.host_virtual_memory.percent.toFixed(1)}%
</div>
)}
<div className="jp-KernelUsage-separator">
{props.trans.__('Total:')}{' '}
{formatForDisplay(usage.host_virtual_memory.total)}
</div>
<div className="jp-KernelUsage-separator">
{props.trans.__('Wired:')}{' '}
{formatForDisplay(usage.host_virtual_memory.wired)}
</div>
</>
) : null}
</>
) : blankStateReason?.reason === 'loading' ? (
<div className="jp-KernelUsage-separator">
Expand Down