Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master -> Dev #671

Merged
merged 48 commits into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
a170a96
Upgrade to laravel 8
henrywhitaker3 Mar 7, 2021
1fd033b
Grab all settings instead of new query for each one
henrywhitaker3 Mar 7, 2021
ba8f82a
Ignore file from clockwork
henrywhitaker3 Mar 7, 2021
a2d8886
Moved speedtest logic into interface
henrywhitaker3 Mar 7, 2021
75c5a49
Moved more stuff into actions, and made one endpoint for homepage data
henrywhitaker3 Mar 7, 2021
ce4913a
Grab all stats data in one go
henrywhitaker3 Mar 7, 2021
2d60f1c
Update the text for server selection
henrywhitaker3 Mar 7, 2021
a45f52f
Formatting
henrywhitaker3 Mar 7, 2021
85d2d87
Changelog etc
henrywhitaker3 Mar 7, 2021
2861196
Commands now use provider DI
henrywhitaker3 Mar 7, 2021
ac4fd6c
Use them
henrywhitaker3 Mar 7, 2021
a71356f
Fix some tests
henrywhitaker3 Mar 7, 2021
d91a5ef
Update workflow
henrywhitaker3 Mar 7, 2021
0b593e6
Added delete button for failed tests
henrywhitaker3 Apr 10, 2021
305e4bb
Order/location of columns is now variable
henrywhitaker3 Apr 10, 2021
b232c21
Add hidden columns setting
henrywhitaker3 Apr 10, 2021
c9e86ac
Added sortable list for visible columns
henrywhitaker3 Apr 10, 2021
fe871a7
Added multi droppable handling
henrywhitaker3 Apr 10, 2021
9870aeb
Styled columns and refresh config on save
henrywhitaker3 Apr 10, 2021
39b3637
Merge branch 'add-column-options' into alpha
henrywhitaker3 Apr 10, 2021
5e2cc96
Make General the default tab again
henrywhitaker3 Apr 10, 2021
b0659fd
Fix schedule for timezones
henrywhitaker3 Apr 10, 2021
78fcf49
Fix migrations for new cast
henrywhitaker3 Apr 10, 2021
1d9fba6
Fix tests and update version number
henrywhitaker3 Apr 10, 2021
bed7e84
Move back to memory db
henrywhitaker3 Apr 10, 2021
20b3cb9
Don't store settings in static array
henrywhitaker3 Apr 10, 2021
b82b7c6
Timeout accept eula
henrywhitaker3 Apr 10, 2021
f92c040
Fix itny bugs
henrywhitaker3 Apr 10, 2021
492b5df
Auth on delete
henrywhitaker3 Apr 10, 2021
dd87160
Merge pull request #521 from henrywhitaker3/alpha
henrywhitaker3 Apr 10, 2021
76e21bf
Remove clockwork
henrywhitaker3 Apr 10, 2021
cb5abcf
Merge branch 'alpha' into dev
henrywhitaker3 Apr 10, 2021
5db1106
Adds support for influxdb version 1
henrywhitaker3 Apr 10, 2021
4e6049b
Remove logging
henrywhitaker3 Apr 10, 2021
8453597
Formatting
henrywhitaker3 Apr 10, 2021
7b16f1a
Remove influx console command
henrywhitaker3 Apr 10, 2021
0b8ccfd
Added speedtest seeder
henrywhitaker3 Apr 10, 2021
99c64af
Move models into Models dir
henrywhitaker3 Apr 10, 2021
7cf8dfc
Moved auth models into right folder
henrywhitaker3 Apr 10, 2021
4dc3e5b
Move influx interface into interfaces folder
henrywhitaker3 Apr 10, 2021
5dbc6b9
Added username/password fields
henrywhitaker3 Apr 10, 2021
91b7ec7
Added helm chart to readme
henrywhitaker3 Apr 10, 2021
f809f81
Used a mock ooklatester in tests
henrywhitaker3 Apr 11, 2021
48fbbc3
Added version 1 fields to settings page
henrywhitaker3 Apr 11, 2021
a962865
Add db field to settings page
henrywhitaker3 Apr 11, 2021
ce549b5
Try to stop chrome form autofilling
henrywhitaker3 Apr 11, 2021
219c5d6
Merge pull request #563 from henrywhitaker3/alpha
henrywhitaker3 Apr 11, 2021
9fb573e
Fix workflows
henrywhitaker3 Aug 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/laravel-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Download Speedtest binary
run: wget https://bintray.com/ookla/download/download_file?file_path=ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz && tar zxvf speedtest.tgz && mv speedtest app/Bin/
run: wget https://install.speedtest.net/app/cli/ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz && tar zxvf speedtest.tgz && mv speedtest app/Bin/
- name: Accept EULA
env:
DB_CONNECTION: sqlite
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/laravel-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Download Speedtest binary
run: wget https://bintray.com/ookla/download/download_file?file_path=ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz && tar zxvf speedtest.tgz && mv speedtest app/Bin/
run: wget https://install.speedtest.net/app/cli/ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz && tar zxvf speedtest.tgz && mv speedtest app/Bin/
- name: Accept EULA
env:
DB_CONNECTION: sqlite
Expand All @@ -56,4 +56,4 @@ jobs:
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
run: vendor/bin/phpunit
run: php artisan test --parallel
2 changes: 1 addition & 1 deletion .github/workflows/laravel-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Download Speedtest binary
run: wget https://bintray.com/ookla/download/download_file?file_path=ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz && tar zxvf speedtest.tgz && mv speedtest app/Bin/
run: wget https://install.speedtest.net/app/cli/ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz && tar zxvf speedtest.tgz && mv speedtest app/Bin/
- name: Accept EULA
env:
DB_CONNECTION: sqlite
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Speedtest Tracker

[![Docker pulls](https://img.shields.io/docker/pulls/henrywhitaker3/speedtest-tracker?style=flat-square)](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/henrywhitaker3/Speedtest-Tracker/Stable?label=master&logo=github&style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/henrywhitaker3/Speedtest-Tracker/Dev?label=dev&logo=github&style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [![last_commit](https://img.shields.io/github/last-commit/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [![issues](https://img.shields.io/github/issues/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [![commit_freq](https://img.shields.io/github/commit-activity/m/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) ![version](https://img.shields.io/badge/version-v1.10.4-success?style=flat-square) [![license](https://img.shields.io/github/license/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
[![Docker pulls](https://img.shields.io/docker/pulls/henrywhitaker3/speedtest-tracker?style=flat-square)](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/henrywhitaker3/Speedtest-Tracker/Stable?label=master&logo=github&style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/henrywhitaker3/Speedtest-Tracker/Dev?label=dev&logo=github&style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [![last_commit](https://img.shields.io/github/last-commit/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [![issues](https://img.shields.io/github/issues/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [![commit_freq](https://img.shields.io/github/commit-activity/m/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) ![version](https://img.shields.io/badge/version-v1.12.0-success?style=flat-square) [![license](https://img.shields.io/github/license/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)

This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses the [Ookla's speedtest cli](https://www.speedtest.net/apps/cli) package to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results.

Expand All @@ -18,6 +18,7 @@ Disclaimer: You will need to accept Ookla's EULA and privacy agreements in order
- Slack/Discord/Telegram notifications
- [healthchecks.io](https://healthchecks.io) integration
- Organizr integration
- InfluxDB integration (currently v1 only, v2 is a WIP)

## Installation & Setup

Expand Down Expand Up @@ -84,6 +85,8 @@ Container images are configured using parameters passed at runtime (such as thos
| `-e PUID` | Optional. Supply a local user ID for volume permissions |
| `-e PGID` | Optional. Supply a local group ID for volume permissions |
| `-e AUTH` | Optional. Set to 'true' to enable authentication for the app |
| `-e INFLUXDB_RETENTION`| Optional. Sets the InfluxDB retention period, defaults to `30d` |
| `-e INFLUXDB_HOST_TAG | Optional. Sets the InfluxDB host tag value, defaults to `speedtest` |

### Authentication

Expand All @@ -101,3 +104,7 @@ After enabling, you should change the password through the web UI.
### Manual Install

For manual installations, please follow the instructions [here](https://github.com/henrywhitaker3/Speedtest-Tracker/wiki/Manual-Installation).

### Kubernetes

There is a 3rd party helm chart available [here](https://github.com/sOblivionsCall/charts).
48 changes: 48 additions & 0 deletions app/Actions/GetFailedSpeedtestData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Actions;

use App\Models\Speedtest;
use Cache;
use Carbon\Carbon;
use DB;
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;

class GetFailedSpeedtestData implements ActionInterface
{
/**
* Run the action.
*
* @return mixed
*/
public function run($days = 7)
{
$ttl = Carbon::now()->addDays(1);

return Cache::remember('failure-rate-' . $days, $ttl, function () use ($days) {
$range = [
Carbon::today()
];
for ($i = 0; $i < ($days - 1); $i++) {
$prev = end($range);
$new = $prev->copy()->subDays(1);
array_push($range, $new);
}

$rate = [];

foreach ($range as $day) {
$success = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', false)->get()[0]['rate'];
$fail = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', true)->get()[0]['rate'];

array_push($rate, [
'date' => $day->toDateString(),
'success' => $success,
'failure' => $fail,
]);
}

return array_reverse($rate);
});
}
}
52 changes: 52 additions & 0 deletions app/Actions/GetLatestSpeedtestData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Actions;

use App\Helpers\SettingsHelper;
use App\Helpers\SpeedtestHelper;
use App\Models\Speedtest;
use DB;
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;

class GetLatestSpeedtestData implements ActionInterface
{
/**
* Run the action.
*
* @return mixed
*/
public function run()
{
$data = SpeedtestHelper::latest();

$response = [
'data' => $data,
];

if (SettingsHelper::get('show_average')) {
$avg = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
->where('failed', false)
->first()
->toArray();
$response['average'] = $avg;
}

if (SettingsHelper::get('show_max')) {
$max = Speedtest::select(DB::raw('MAX(ping) as ping, MAX(download) as download, MAX(upload) as upload'))
->where('failed', false)
->first()
->toArray();
$response['maximum'] = $max;
}

if (SettingsHelper::get('show_min')) {
$min = Speedtest::select(DB::raw('MIN(ping) as ping, MIN(download) as download, MIN(upload) as upload'))
->where('failed', false)
->first()
->toArray();
$response['minimum'] = $min;
}

return $response;
}
}
37 changes: 37 additions & 0 deletions app/Actions/GetSpeedtestTimeData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Actions;

use App\Helpers\SettingsHelper;
use App\Models\Speedtest;
use Cache;
use Carbon\Carbon;
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;

class GetSpeedtestTimeData implements ActionInterface
{
/**
* Run the action.
*
* @return mixed
*/
public function run($days = 7)
{
$ttl = Carbon::now()->addDays(1);

return Cache::remember('speedtest-days-' . $days, $ttl, function () use ($days) {
$showFailed = (bool)SettingsHelper::get('show_failed_tests_on_graph')->value;

if ($showFailed === true) {
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
->orderBy('created_at', 'asc')
->get();
}

return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
->where('failed', false)
->orderBy('created_at', 'asc')
->get();
});
}
}
35 changes: 35 additions & 0 deletions app/Actions/QueueSpeedtest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Actions;

use App\Helpers\SettingsHelper;
use App\Interfaces\SpeedtestProvider;
use App\Jobs\SpeedtestJob;
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;

class QueueSpeedtest implements ActionInterface
{
private SpeedtestProvider $speedtestProvider;

/**
* Create a new action instance.
*
* @return void
*/
public function __construct(SpeedtestProvider $speedtestProvider)
{
$this->speedtestProvider = $speedtestProvider;
}

/**
* Run the action.
*
* @return mixed
*/
public function run()
{
SettingsHelper::loadIntegrationConfig();

SpeedtestJob::dispatch(false, config('integrations'), $this->speedtestProvider);
}
}
52 changes: 52 additions & 0 deletions app/Casts/CommaSeparatedArrayCast.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Casts;

use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

class CommaSeparatedArrayCast implements CastsAttributes
{
/**
* Array of settings that should be cast
*/
private array $shouldCast = [
'visible_columns',
'hidden_columns',
];

/**
* Cast the given value.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @return mixed
*/
public function get($model, $key, $value, $attributes)
{
if (!in_array($model->name, $this->shouldCast)) {
return $value;
}

return explode(',', $value);
}

/**
* Prepare the given value for storage.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @return mixed
*/
public function set($model, $key, $value, $attributes)
{
if (!in_array($model->name, $this->shouldCast)) {
return $value;
}

return implode(',', $value);
}
}
3 changes: 2 additions & 1 deletion app/Console/Commands/AcceptEULACommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __construct()
*/
public function handle()
{
shell_exec(config('speedtest.home') . ' && ' . app_path() . '/Bin/speedtest --accept-license --accept-gdpr');
$this->info('Acceping EULA');
shell_exec(config('speedtest.home') . ' && timeout 3s ' . app_path() . '/Bin/speedtest --accept-license --accept-gdpr');
}
}
2 changes: 1 addition & 1 deletion app/Console/Commands/ClearOldSessionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Auth\LoginSession;
use App\Models\Auth\LoginSession;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Log;
Expand Down
16 changes: 11 additions & 5 deletions app/Console/Commands/SpeedtestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Console\Commands;

use App\Exceptions\SpeedtestFailureException;
use App\Helpers\SpeedtestHelper;
use App\Interfaces\SpeedtestProvider;
use Illuminate\Console\Command;

class SpeedtestCommand extends Command
Expand All @@ -21,13 +23,17 @@ class SpeedtestCommand extends Command
*/
protected $description = 'Performs a new speedtest';

private SpeedtestProvider $speedtestProvider;

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
public function __construct(SpeedtestProvider $speedtestProvider)
{
$this->speedtestProvider = $speedtestProvider;

parent::__construct();
}

Expand All @@ -40,14 +46,14 @@ public function handle()
{
$this->info('Running speedtest, this might take a while...');

$results = SpeedtestHelper::runSpeedtest(false, false);

if(!is_object($results)) {
try {
$results = $this->speedtestProvider->run(false, false);
} catch (SpeedtestFailureException $e) {
$this->error('Something went wrong running the speedtest.');
exit();
}

if(property_exists($results, 'ping') && property_exists($results, 'download') && property_exists($results, 'upload')) {
if (property_exists($results, 'ping') && property_exists($results, 'download') && property_exists($results, 'upload')) {
$this->error('Something went wrong running the speedtest.');
exit();
}
Expand Down
Loading