diff --git a/README.md b/README.md index 61fa9d44d..1c38e17d1 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,9 @@ and are available for both AMD64 and ARM devices. ``` > Note: The `--privileged` flag is needed to correctly determine the memory info. + +> Note: If you want to display the host OS information, you need to create a volume +> mount for `/etc/os-release:/etc/os-release:ro` You can configure your Docker-installed dashboard via environment variables inside the container. @@ -131,6 +134,7 @@ Variable | Description | Type | Default Value `DASHDOT_PORT` | The port where the express backend is running (the backend serves the frontend, so it is the same port for both) | number | `3001` `DASHDOT_DISABLE_TILT` | If you want to disable the tilt effect when hovering over the widgets with your mouse | boolean | `false` `DASHDOT_DISABLE_HOST` | If you want to hide the host part in the server widget (e.g. `dash.mauz.io` -> `dash.`) | boolean | `false` +`DASHDOT_ENABLE_CPU_TEMP` | If you want to show the CPU temperature in the graph. This will probably not work on a VPS, so you need to try it on your own if this works. For home servers it might work just fine | boolean | `true` `DASHDOT_OS_WIDGET_ENABLE` | To show/hide the OS widget | boolean | `true` `DASHDOT_OS_WIDGET_GROW` | To adjust the relative size of the OS widget | number | `1` `DASHDOT_CPU_WIDGET_ENABLE` | To show/hide the Processor widget | boolean | `true` diff --git a/backend/src/config.ts b/backend/src/config.ts index f65aae0c9..093bd4c8d 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -13,6 +13,7 @@ export const CONFIG: Config = { port: numOrUndefined(penv('PORT')) ?? 3001, disable_tilt: penv('DISABLE_TILT') === 'true', disable_host: penv('DISABLE_HOST') === 'true', + enable_cpu_temps: penv('ENABLE_CPU_TEMPS') === 'true', os_widget_enable: penv('OS_WIDGET_ENABLE') !== 'false', os_widget_grow: numOrUndefined(penv('OS_WIDGET_GROW')) ?? 1, diff --git a/backend/src/dynamic-info.ts b/backend/src/dynamic-info.ts index 44aa7e3b8..f266a46e9 100644 --- a/backend/src/dynamic-info.ts +++ b/backend/src/dynamic-info.ts @@ -1,7 +1,8 @@ import { CpuLoad, RamLoad, StorageLoad } from 'dashdot-shared'; import { interval, mergeMap, Observable, ReplaySubject } from 'rxjs'; -import si from 'systeminformation'; +import si, { Systeminformation } from 'systeminformation'; import { CONFIG } from './config'; +import { getStaticServerInfo } from './static-info'; const createBufferedInterval = ( bufferSize: number, @@ -25,10 +26,20 @@ export const cpuObs = createBufferedInterval( CONFIG.cpu_shown_datapoints, CONFIG.cpu_poll_interval, async (): Promise => { - const cpuLoad = (await si.currentLoad()).cpus; + const staticInfo = await getStaticServerInfo(); + const loads = (await si.currentLoad()).cpus; - return cpuLoad.map((load, i) => ({ - load: load.load, + let temps: Systeminformation.CpuTemperatureData['cores'] = []; + if (CONFIG.enable_cpu_temps) { + const threadsPerCore = staticInfo.cpu.threads / staticInfo.cpu.cores; + temps = (await si.cpuTemperature()).cores.flatMap(temp => + Array(threadsPerCore).fill(temp) + ); + } + + return loads.map(({ load }, i) => ({ + load, + temp: temps[i], core: i, })); } diff --git a/docker-compose.yml b/docker-compose.yml index 0e289c174..4dd2ce77d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,10 +26,11 @@ services: restart: unless-stopped privileged: true environment: - - DASHDOT_OVERRIDE_OS=Ubuntu 1.2.3 - DASHDOT_DISABLE_TILT=true + - DASHDOT_ENABLE_CPU_TEMPS=true ports: - '3001:3001' volumes: - ./backend:/app/backend - - ./common:/app/common + - ./shared:/app/shared + - /etc/os-release:/etc/os-release:ro diff --git a/frontend/src/utils/calculations.ts b/frontend/src/utils/calculations.ts index a8f3835db..7656dc19b 100644 --- a/frontend/src/utils/calculations.ts +++ b/frontend/src/utils/calculations.ts @@ -1,13 +1,15 @@ export const byteToGb = (byte: number, commas = 1): number => { - return ( - Math.round((byte / 1024 / 1024 / 1024) * Math.pow(10, commas)) / - Math.pow(10, commas) - ); + return toCommas(byte / 1024 / 1024 / 1024, commas); }; export const byteToMb = (byte: number, commas = 1): number => { - return ( - Math.round((byte / 1024 / 1024) * Math.pow(10, commas)) / - Math.pow(10, commas) - ); + return toCommas(byte / 1024 / 1024, commas); +}; + +export const toCommas = (num: number, commas = 1): number => { + return Math.round(num * Math.pow(10, commas)) / Math.pow(10, commas); +}; + +export const toFixedCommas = (num: number, commas = 1): string => { + return num.toFixed(commas); }; diff --git a/frontend/src/widgets/cpu.tsx b/frontend/src/widgets/cpu.tsx index 59d6f3524..f43130639 100644 --- a/frontend/src/widgets/cpu.tsx +++ b/frontend/src/widgets/cpu.tsx @@ -8,6 +8,7 @@ import { FC, useState } from 'react'; import styled, { useTheme } from 'styled-components'; import HardwareInfoContainer from '../components/hardware-info-container'; import ThemedText from '../components/text'; +import { toFixedCommas } from '../utils/calculations'; const CpuSwitchContainer = styled.div` position: absolute; @@ -21,6 +22,14 @@ const CpuSwitchContainer = styled.div` gap: 15px; `; +const TempContainer = styled.div` + position: absolute; + left: 25px; + top: 25px; + z-index: 2; + color: ${({ theme }) => theme.colors.text}AA; +`; + type CpuWidgetProps = { load: CpuLoad[]; loading: boolean; @@ -88,6 +97,10 @@ const CpuWidget: FC = ({ load, loading, data, config }) => { const frequency = override?.cpu_frequency ?? data?.frequency; + const averageTemp = + load[load.length - 1]?.reduce((acc, { temp }) => acc + (temp ?? 0), 0) / + load[load.length - 1]?.length; + return ( = ({ load, loading, data, config }) => { } > + {config?.enable_cpu_temps && ( + + Ø: {toFixedCommas(averageTemp, 1) || '?'} °C + + )}