Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
MauriceNino committed May 18, 2022
2 parents 84c2afd + 6324389 commit 207e8b5
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 15 additions & 4 deletions backend/src/dynamic-info.ts
Original file line number Diff line number Diff line change
@@ -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 = <R>(
bufferSize: number,
Expand All @@ -25,10 +26,20 @@ export const cpuObs = createBufferedInterval(
CONFIG.cpu_shown_datapoints,
CONFIG.cpu_poll_interval,
async (): Promise<CpuLoad> => {
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,
}));
}
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 10 additions & 8 deletions frontend/src/utils/calculations.ts
Original file line number Diff line number Diff line change
@@ -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);
};
18 changes: 18 additions & 0 deletions frontend/src/widgets/cpu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -88,6 +97,10 @@ const CpuWidget: FC<CpuWidgetProps> = ({ 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 (
<HardwareInfoContainer
color={theme.colors.cpuPrimary}
Expand Down Expand Up @@ -127,6 +140,11 @@ const CpuWidget: FC<CpuWidgetProps> = ({ load, loading, data, config }) => {
</CpuSwitchContainer>
}
>
{config?.enable_cpu_temps && (
<TempContainer>
Ø: {toFixedCommas(averageTemp, 1) || '?'} °C
</TempContainer>
)}
<ResponsiveLine
isInteractive={true}
enableSlices='x'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dashdot-cli",
"version": "1.5.0",
"version": "1.6.0",
"description": "dash. - a modern server dashboard",
"repository": "https://github.com/MauriceNino/dashdot",
"homepage": "https://github.com/MauriceNino/dashdot#readme",
Expand Down
2 changes: 2 additions & 0 deletions shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type CpuInfo = {
export type CpuLoad = {
core: number;
load: number;
temp: number;
}[];

export type RamInfo = {
Expand Down Expand Up @@ -49,6 +50,7 @@ export type Config = {
port: number;
disable_tilt: boolean;
disable_host: boolean;
enable_cpu_temps: boolean;
os_widget_enable: boolean;
os_widget_grow: number;
cpu_widget_enable: boolean;
Expand Down

0 comments on commit 207e8b5

Please sign in to comment.