Skip to content

Commit

Permalink
feat(api, view): add raid information to storage widget
Browse files Browse the repository at this point in the history
fixes #40
  • Loading branch information
MauriceNino committed Jun 15, 2022
1 parent 7c5803d commit ba84d34
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 113 deletions.
42 changes: 21 additions & 21 deletions .github/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,26 @@ Override specific fields, by providing your desired value with the following opt

<!-- markdownlint-disable -->

| Variable | Description | Type | Default Value |
| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------------- |
| `DASHDOT_OVERRIDE_OS` | | string |
| `DASHDOT_OVERRIDE_ARCH` | | string |
| `DASHDOT_OVERRIDE_CPU_BRAND` | | string |
| `DASHDOT_OVERRIDE_CPU_MODEL` | | string |
| `DASHDOT_OVERRIDE_CPU_CORES` | | number |
| `DASHDOT_OVERRIDE_CPU_THREADS` | | number |
| `DASHDOT_OVERRIDE_CPU_FREQUENCY` | Number needs to be passed in GHz (e.g. `2.8`) | number |
| `DASHDOT_OVERRIDE_RAM_BRAND` | | string |
| `DASHDOT_OVERRIDE_RAM_SIZE` | Number needs to be passed in bytes (e.g. `34359738368` for 32 GB, because it is `32 * 1024 * 1024 * 1024`) | number |
| `DASHDOT_OVERRIDE_RAM_TYPE` | | string |
| `DASHDOT_OVERRIDE_RAM_FREQUENCY` | | number |
| `DASHDOT_OVERRIDE_NETWORK_TYPE` | | string |
| `DASHDOT_OVERRIDE_NETWORK_SPEED_UP` | Number needs to be passed in bit (e.g. `100000000` for 100 Mb/s, because it is `100 * 1000 * 1000`) | number |
| `DASHDOT_OVERRIDE_NETWORK_SPEED_DOWN` | Number needs to be passed in bit (e.g. `100000000` for 100 Mb/s, because it is `100 * 1000 * 1000`) | number |
| `DASHDOT_OVERRIDE_NETWORK_INTERFACE_SPEED` | Number needs to be passed in Megabit (e.g. `10000` for 10 GB/s, because it is `10 * 1000`) | number |
| `DASHDOT_OVERRIDE_NETWORK_PUBLIC_IP` | | string |
| `DASHDOT_OVERRIDE_STORAGE_BRAND_[1-5]` | Use a suffix of 1, 2, 3, 4 or 5 for the respective drives | string |
| `DASHDOT_OVERRIDE_STORAGE_SIZE_[1-5]` | Use a suffix of 1, 2, 3, 4 or 5 for the respective drives. Number needs to be passed in bytes (e.g. `34359738368` for 32 GB, because it is `32 * 1024 * 1024 * 1024`) | number |
| `DASHDOT_OVERRIDE_STORAGE_TYPE_[1-5]` | Use a suffix of 1, 2, 3, 4 or 5 for the respective drives | string |
| Variable | Description | Type | Default Value |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------ | ------------- |
| `DASHDOT_OVERRIDE_OS` | | string |
| `DASHDOT_OVERRIDE_ARCH` | | string |
| `DASHDOT_OVERRIDE_CPU_BRAND` | | string |
| `DASHDOT_OVERRIDE_CPU_MODEL` | | string |
| `DASHDOT_OVERRIDE_CPU_CORES` | | number |
| `DASHDOT_OVERRIDE_CPU_THREADS` | | number |
| `DASHDOT_OVERRIDE_CPU_FREQUENCY` | Number needs to be passed in GHz (e.g. `2.8`) | number |
| `DASHDOT_OVERRIDE_RAM_BRAND` | | string |
| `DASHDOT_OVERRIDE_RAM_SIZE` | Number needs to be passed in bytes (e.g. `34359738368` for 32 GB, because it is `32 * 1024 * 1024 * 1024`) | number |
| `DASHDOT_OVERRIDE_RAM_TYPE` | | string |
| `DASHDOT_OVERRIDE_RAM_FREQUENCY` | | number |
| `DASHDOT_OVERRIDE_NETWORK_TYPE` | | string |
| `DASHDOT_OVERRIDE_NETWORK_SPEED_UP` | Number needs to be passed in bit (e.g. `100000000` for 100 Mb/s, because it is `100 * 1000 * 1000`) | number |
| `DASHDOT_OVERRIDE_NETWORK_SPEED_DOWN` | Number needs to be passed in bit (e.g. `100000000` for 100 Mb/s, because it is `100 * 1000 * 1000`) | number |
| `DASHDOT_OVERRIDE_NETWORK_INTERFACE_SPEED` | Number needs to be passed in Megabit (e.g. `10000` for 10 GB/s, because it is `10 * 1000`) | number |
| `DASHDOT_OVERRIDE_NETWORK_PUBLIC_IP` | | string |
| `DASHDOT_OVERRIDE_STORAGE_BRANDS` | Pass a comma-separated list of brands of your drives. You can skip correct drives, by passing empty values for it (e.g. `Samsung,,WD` would result in `Samsung` for Drive 1 and `WD` for Drive 3) | string |
| `DASHDOT_OVERRIDE_STORAGE_SIZES` | Pass a comma-separated list of sizes of your drives. You can skip correct drives, by passing empty values for it (e.g. `123,,321` would result in `123` for Drive 1 and `321` for Drive 3). Number needs to be passed in bytes (e.g. `34359738368` for 32 GB, because it is `32 * 1024 * 1024 * 1024`) | string |
| `DASHDOT_OVERRIDE_STORAGE_TYPES` | Pass a comma-separated list of types of your drives. You can skip correct drives, by passing empty values for it (e.g. `SSD,,HDD` would result in `SSD` for Drive 1 and `HDD` for Drive 3) | string |

<!-- markdownlint-enable -->
41 changes: 18 additions & 23 deletions apps/api/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
import { Config } from '@dash/common';

const numNull = (val: string | undefined): number | undefined => {
if (val === undefined) {
if (val === undefined || val === '') {
return undefined;
}
return +val;
};

const penv = (key: string): string | undefined => process.env[`DASHDOT_${key}`];
const lst = (item: string): any[] => item.split(',');
const lst = (item: string): string[] => (item === '' ? [] : item.split(','));
const numlst = (item: string): number[] => lst(item).map(numNull);

export const CONFIG: Config = {
port: numNull(penv('PORT')) ?? 3001,
widget_list: lst(penv('WIDGET_LIST') ?? 'os,cpu,storage,ram,network'),
widget_list: lst(
penv('WIDGET_LIST') ?? 'os,cpu,storage,ram,network'
) as any[],
accept_ookla_eula: penv('ACCEPT_OOKLA_EULA') === 'true',

disable_host: penv('DISABLE_HOST') === 'true',
os_label_list: lst(penv('OS_LABEL_LIST') ?? 'os,arch,up_since'),
os_label_list: lst(penv('OS_LABEL_LIST') ?? 'os,arch,up_since') as any[],
os_widget_grow: numNull(penv('OS_WIDGET_GROW')) ?? 1.5,
os_widget_min_width: numNull(penv('OS_WIDGET_MIN_WIDTH')) ?? 300,

enable_cpu_temps: penv('ENABLE_CPU_TEMPS') === 'true',
cpu_label_list: lst(
penv('CPU_LABEL_LIST') ?? 'brand,model,cores,threads,frequency'
),
) as any[],
cpu_widget_grow: numNull(penv('CPU_WIDGET_GROW')) ?? 4,
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,

storage_label_list: lst(penv('STORAGE_LABEL_LIST') ?? 'brand,size,type'),
storage_label_list: lst(
penv('STORAGE_LABEL_LIST') ?? 'brand,size,type,raid'
) as any[],
storage_widget_grow: numNull(penv('STORAGE_WIDGET_GROW')) ?? 3.5,
storage_widget_min_width: numNull(penv('STORAGE_WIDGET_MIN_WIDTH')) ?? 500,
storage_poll_interval: numNull(penv('STORAGE_POLL_INTERVAL')) ?? 60000,

ram_label_list: lst(penv('RAM_LABEL_LIST') ?? 'brand,size,type,frequency'),
ram_label_list: lst(
penv('RAM_LABEL_LIST') ?? 'brand,size,type,frequency'
) as any[],
ram_widget_grow: numNull(penv('RAM_WIDGET_GROW')) ?? 4,
ram_widget_min_width: numNull(penv('RAM_WIDGET_MIN_WIDTH')) ?? 500,
ram_shown_datapoints: numNull(penv('RAM_SHOWN_DATAPOINTS')) ?? 20,
Expand All @@ -43,7 +50,7 @@ export const CONFIG: Config = {
speed_test_interval: numNull(penv('SPEED_TEST_INTERVAL')) ?? 60,
network_label_list: lst(
penv('NETWORK_LABEL_LIST') ?? 'type,speed_up,speed_down,interface_speed'
),
) as any[],
network_widget_grow: numNull(penv('NETWORK_WIDGET_GROW')) ?? 6,
network_widget_min_width: numNull(penv('NETWORK_WIDGET_MIN_WIDTH')) ?? 500,
network_shown_datapoints: numNull(penv('NETWORK_SHOWN_DATAPOINTS')) ?? 20,
Expand All @@ -66,20 +73,8 @@ export const CONFIG: Config = {
network_speed_down: numNull(penv('OVERRIDE_NETWORK_SPEED_DOWN')),
network_interface_speed: numNull(penv('OVERRIDE_NETWORK_INTERFACE_SPEED')),
network_public_ip: penv('OVERRIDE_NETWORK_PUBLIC_IP'),
storage_brand_1: penv('OVERRIDE_STORAGE_BRAND_1'),
storage_size_1: numNull(penv('OVERRIDE_STORAGE_SIZE_1')),
storage_type_1: penv('OVERRIDE_STORAGE_TYPE_1'),
storage_brand_2: penv('OVERRIDE_STORAGE_BRAND_2'),
storage_size_2: numNull(penv('OVERRIDE_STORAGE_SIZE_2')),
storage_type_2: penv('OVERRIDE_STORAGE_TYPE_2'),
storage_brand_3: penv('OVERRIDE_STORAGE_BRAND_3'),
storage_size_3: numNull(penv('OVERRIDE_STORAGE_SIZE_3')),
storage_type_3: penv('OVERRIDE_STORAGE_TYPE_3'),
storage_brand_4: penv('OVERRIDE_STORAGE_BRAND_4'),
storage_size_4: numNull(penv('OVERRIDE_STORAGE_SIZE_4')),
storage_type_4: penv('OVERRIDE_STORAGE_TYPE_4'),
storage_brand_5: penv('OVERRIDE_STORAGE_BRAND_5'),
storage_size_5: numNull(penv('OVERRIDE_STORAGE_SIZE_5')),
storage_type_5: penv('OVERRIDE_STORAGE_TYPE_5'),
storage_brands: lst(penv('OVERRIDE_STORAGE_BRANDS') ?? ''),
storage_sizes: numlst(penv('OVERRIDE_STORAGE_SIZES') ?? ''),
storage_types: lst(penv('OVERRIDE_STORAGE_TYPES') ?? ''),
},
};
2 changes: 1 addition & 1 deletion apps/api/src/dynamic-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const getDynamicServerInfo = () => {
const sizes = await si.fsSize();

const filtered = sizes.filter(
({ fs, mount }) => mount.startsWith('/mnt/host_') || fs === 'overlay'
({ mount }) => mount.startsWith('/mnt/host_') || mount === '/'
);

return filtered.reduce((acc, { used }) => acc + used, 0);
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loadCommons } from '@dash/common';
import * as cors from 'cors';
import * as express from 'express';
import * as http from 'http';
Expand Down Expand Up @@ -87,3 +88,4 @@ server.listen(CONFIG.port, async () => {
});

server.on('error', console.error);
loadCommons();
67 changes: 57 additions & 10 deletions apps/api/src/static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,62 @@ const loadRamInfo = async (): Promise<void> => {
};

const loadStorageInfo = async (): Promise<void> => {
const info = await si.diskLayout();
const [disks, blocks] = await Promise.all([
si.diskLayout(),
si.blockDevices(),
]);

STATIC_INFO.storage = {
layout: info.map(({ size, type, vendor }) => ({
brand: vendor,
size,
type,
})),
};
const raidMembers = blocks.filter(block => block.fsType.endsWith('_member'));
const blockDisks = blocks.filter(block => block.type === 'disk');
const blockParts = blocks.filter(block => block.type === 'part');

if (raidMembers.length > 0) {
const blockLayout = blockDisks
.map(disk => {
const diskRaidMem = raidMembers.filter(member =>
member.name.startsWith(disk.name)
);
const diskParts = blockParts.filter(part =>
part.name.startsWith(disk.name)
);
const nativeDisk = disks.find(d => d.name === disk.model);

if (nativeDisk != null) {
if (diskParts.some(part => part.mount != null && part.mount !== '')) {
return {
brand: nativeDisk.vendor,
size: nativeDisk.size,
type: nativeDisk.type,
};
} else if (diskRaidMem.length > 0) {
const label = diskRaidMem[0].label.includes(':')
? diskRaidMem[0].label.split(':')[0]
: diskRaidMem[0].label;
return {
brand: nativeDisk.vendor,
size: nativeDisk.size,
type: nativeDisk.type,
raidGroup: label,
};
}
}

return undefined;
})
.filter(d => d != null);

STATIC_INFO.storage = {
layout: blockLayout,
};
} else {
STATIC_INFO.storage = {
layout: disks.map(({ size, type, vendor }) => ({
brand: vendor,
size,
type,
})),
};
}
};

const loadNetworkInfo = async (): Promise<void> => {
Expand Down Expand Up @@ -144,8 +191,8 @@ const commandExists = async (command: string): Promise<boolean> => {
}
};

export const runSpeedTest = async (): Promise<void> => {
let usedRunner;
export const runSpeedTest = async (): Promise<string> => {
let usedRunner: string;
if (CONFIG.accept_ookla_eula && (await commandExists('speedtest'))) {
usedRunner = 'ookla';
const { stdout } = await exec('speedtest -f json');
Expand Down
3 changes: 2 additions & 1 deletion apps/view/src/components/info-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const InfoTextLabel = styled(ThemedText)`
font-size: 0.8rem;
padding-bottom: 3px;
padding-right: 15px;
white-space: nowrap;
line-height: 1.5;
white-space: pre;
`;

const InfoTextValue = styled(ThemedText)`
Expand Down
2 changes: 2 additions & 0 deletions apps/view/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loadCommons } from '@dash/common';
import 'antd/dist/antd.variable.min.css';
import React from 'react';
import { createRoot } from 'react-dom/client';
Expand All @@ -13,3 +14,4 @@ root.render(
);

reportWebVitals();
loadCommons();
Loading

0 comments on commit ba84d34

Please sign in to comment.