Skip to content

Commit

Permalink
feat(cpu widget): allow user to switch (default) processor core view
Browse files Browse the repository at this point in the history
Using the new CPU_CORES_TOGGLE_MODE env option the user is now able to specify which Processor
core view it want to see. The available options are 'toggle', 'multi-core' and 'average'. The
'toggle' option is default and has the same functionality/effect as before. The 'multi-core' option
and 'average' option switches to the corresponding view while hiding the toggle.
  • Loading branch information
SamirMokiem authored and MauriceNino committed Dec 4, 2023
1 parent 4bef01c commit 4def64e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
9 changes: 9 additions & 0 deletions apps/docs/docs/config/widget-specific/processor.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@ Read the Processor load every x milliseconds.

- type: `number`
- default: `1000`

## `DASHDOT_CPU_SHOW_ALL_CORES`

Switches the Processor core view depending on the selected option. The `toggle` option allows you to switch the view from the dashboard, other options hide the toggle from the dashboard.

The available options are: `toggle`, `multi-core`, `single-core`.

- type: `string`
- default: `toggle`
1 change: 1 addition & 0 deletions apps/server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const CONFIG: Config = {
cpu_widget_min_width: numNull(penv('CPU_WIDGET_MIN_WIDTH')) ?? 500,
cpu_shown_datapoints: numNull(penv('CPU_SHOWN_DATAPOINTS')) ?? 20,
cpu_poll_interval: numNull(penv('CPU_POLL_INTERVAL')) ?? 1000,
cpu_show_all_cores: penv('CPU_SHOW_ALL_CORES') ?? 'toggle' as any,

storage_widget_items_per_page:
numNull(penv('STORAGE_WIDGET_ITEMS_PER_PAGE')) ?? 3,
Expand Down
21 changes: 15 additions & 6 deletions apps/view/src/widgets/cpu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Config, CpuInfo, CpuLoad } from '@dash/common';
import { faMicrochip } from '@fortawesome/free-solid-svg-icons';
import { Variants } from 'framer-motion';
import { FC } from 'react';
import { FC, useEffect } from 'react';
import { YAxis } from 'recharts';
import { useTheme } from 'styled-components';
import { DefaultAreaChart } from '../components/chart-components';
Expand Down Expand Up @@ -187,6 +187,14 @@ export const CpuWidget: FC<CpuWidgetProps> = ({ load, data, config }) => {
const [multiCore, setMulticore] = useSetting('multiCore', false);
const frequency = override.cpu_frequency ?? data.frequency;

useEffect(() => {
if (config.cpu_show_all_cores === 'multi-core') {
setMulticore(true);
} else if (config.cpu_show_all_cores === 'single-core') {
setMulticore(false);
}
}, []);

return (
<HardwareInfoContainer
color={theme.colors.cpuPrimary}
Expand All @@ -210,11 +218,12 @@ export const CpuWidget: FC<CpuWidgetProps> = ({ load, data, config }) => {
infosPerPage={7}
icon={faMicrochip}
extraContent={
<WidgetSwitch
label='Show All Cores'
checked={multiCore}
onChange={() => setMulticore(!multiCore)}
/>
config.cpu_show_all_cores === 'toggle' ?
<WidgetSwitch
label='Show All Cores'
checked={multiCore}
onChange={() => setMulticore(!multiCore)}
/> : undefined
}
>
<CpuChart
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export type Config = {
cpu_widget_min_width: number;
cpu_shown_datapoints: number;
cpu_poll_interval: number;
cpu_show_all_cores: 'toggle' | 'multi-core' | 'single-core';

// Storage Widget
storage_widget_items_per_page: number;
Expand Down

0 comments on commit 4def64e

Please sign in to comment.