Skip to content

Commit

Permalink
feat: add option to read speed-test result from file
Browse files Browse the repository at this point in the history
fixes #558
  • Loading branch information
MauriceNino committed Jan 29, 2023
1 parent 55e7c32 commit 006dd6f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 2 deletions.
15 changes: 14 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ When you are done with all that, you can start a dev server using `docker-compos
with:

```bash
yarn run dev
yarn dev
```

### Network

If you want to have a speedtest result in your network graph, create a file at the root
of the project named `speedtest_result`, with the following content and then restart your backend.

```json
{
"unit": "byte",
"speedDown": 150000000,
"speedUp": 50000000
}
```

## Git
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ npm-debug.log
yarn-error.log
testem.log
/typings
/speedtest_result

# System Files
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const CONFIG: Config = {
running_in_docker: penv('RUNNING_IN_DOCKER') === 'true',
accept_ookla_eula: penv('ACCEPT_OOKLA_EULA') === 'true',
use_network_interface: penv('USE_NETWORK_INTERFACE') ?? '',
speed_test_from_path: penv('SPEED_TEST_FROM_PATH'),
fs_device_filter: lst(penv('FS_DEVICE_FILTER') ?? ''),
fs_type_filter: lst(
penv('FS_TYPE_FILTER') ?? 'cifs,9p,fuse.rclone,fuse.mergerfs,nfs4,iso9660'
Expand Down
24 changes: 23 additions & 1 deletion apps/api/src/data/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,26 @@ export default {
speedTest: async (printResult = false): Promise<Partial<NetworkInfo>> => {
let usedRunner: string;
let result: Partial<NetworkInfo>;
if (CONFIG.accept_ookla_eula && (await commandExists('speedtest'))) {

if (CONFIG.speed_test_from_path) {
usedRunner = 'file';
const json = JSON.parse(
fs.readFileSync(CONFIG.speed_test_from_path, 'utf-8')
);

const unit = json.unit ?? 'bit';

if (unit !== 'bit' && unit !== 'byte')
throw new Error(
"You can only use 'bit' or 'byte' as a unit for your speed-test results"
);

result = {
speedDown: json.speedDown * (unit === 'bit' ? 8 : 1),
speedUp: json.speedUp * (unit === 'bit' ? 8 : 1),
publicIp: json.publicIp,
};
} else if (CONFIG.accept_ookla_eula && (await commandExists('speedtest'))) {
usedRunner = 'ookla';
const { stdout } = await exec('speedtest -f json');
const json = JSON.parse(stdout);
Expand All @@ -122,6 +141,9 @@ export default {
There is no speedtest module installed - please use one of the following:
- speedtest: https://www.speedtest.net/apps/cli
- speedtest-cli: https://github.com/sivel/speedtest-cli
Or alternatively, provide a local file with speedtest results,
using DASHDOT_SPEEDTEST_FROM_PATH.
For more help on how to setup dashdot, look here:
https://getdashdot.com/docs/install/from-source
Expand Down
20 changes: 20 additions & 0 deletions apps/docs/docs/config/features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ If dash. detects the wrong gateway as your default interface, you can provide a
- type: `string`
- default: `unset`

## `DASHDOT_SPEED_TEST_FROM_PATH`

You can provide a local file-path from where dash. should read its speed-test results.
This is also useful, if you want to disable speed-tests, as you can just pass a maximum value for your network graphs
and then disable the `Speed (Up)` and `Speed (Down)` labels in your network widget.

The file that is being read, should have the following format (you will need to remove the comments):

```json
{
"unit": "byte", // can either be "bit" or "byte"
"speedDown": 150000000, // values need to be in the unit provided above
"speedUp": 50000000,
"publicIp": "123.123.123.123" // optional
}
```

- type: `string`
- default: `unset`

## `DASHDOT_FS_DEVICE_FILTER`

To hide specific drives, you can pass the device names as a string list using this parameter.
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
environment:
- DASHDOT_ENABLE_CPU_TEMPS=true
- DASHDOT_ENABLE_STORAGE_SPLIT_VIEW=true
- DASHDOT_SPEED_TEST_FROM_PATH=/app/speedtest_result
ports:
- 3000:3000 # view
- 3001:3001 # api
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 @@ -86,6 +86,7 @@ export type Config = {
port: number;
running_in_docker: boolean;
use_network_interface: string;
speed_test_from_path?: string;
accept_ookla_eula: boolean;
fs_device_filter: string[];
fs_type_filter: string[];
Expand Down

0 comments on commit 006dd6f

Please sign in to comment.