Added healthchecks.io int

This commit is contained in:
Henry Whitaker
2020-08-12 14:07:47 +01:00
parent 33169be746
commit f32fcf8256
11 changed files with 194 additions and 116 deletions

View File

@@ -1,6 +1,6 @@
# Speedtest Tracker # 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.7.19-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.8.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. 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.
@@ -14,6 +14,7 @@ Disclaimer: You will need to accept Ookla's EULA and privacy agreements in order
- Graph of previous speedtests going back x days - Graph of previous speedtests going back x days
- Backup/restore data in JSON/CSV format - Backup/restore data in JSON/CSV format
- Slack/Discord/Telegram notifications - Slack/Discord/Telegram notifications
- [healthchecks.io](https://healthchecks.io) integration
- Organizr integration - Organizr integration
## Installation & Setup ## Installation & Setup

View File

@@ -5,6 +5,7 @@ namespace App\Helpers;
use App\Speedtest; use App\Speedtest;
use Carbon\Carbon; use Carbon\Carbon;
use Exception; use Exception;
use Henrywhitaker3\Healthchecks\Healthchecks;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@@ -51,7 +52,7 @@ class SpeedtestHelper {
$test = false; $test = false;
} }
if(!$test) { if($test == false) {
Speedtest::create([ Speedtest::create([
'ping' => 0, 'ping' => 0,
'upload' => 0, 'upload' => 0,
@@ -59,9 +60,7 @@ class SpeedtestHelper {
'failed' => true, 'failed' => true,
'scheduled' => $scheduled, 'scheduled' => $scheduled,
]); ]);
}
if($test == false) {
return false; return false;
} }

View File

@@ -4,7 +4,10 @@ namespace App\Jobs;
use App\Events\SpeedtestCompleteEvent; use App\Events\SpeedtestCompleteEvent;
use App\Events\SpeedtestFailedEvent; use App\Events\SpeedtestFailedEvent;
use App\Helpers\SettingsHelper;
use App\Helpers\SpeedtestHelper; use App\Helpers\SpeedtestHelper;
use Exception;
use Henrywhitaker3\Healthchecks\Healthchecks;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
@@ -35,11 +38,36 @@ class SpeedtestJob implements ShouldQueue
*/ */
public function handle() public function handle()
{ {
$healthchecksEnabled = (bool)SettingsHelper::get('healthchecks_enabled')->value;
$healthchecksUuid = SettingsHelper::get('healthchecks_uuid')->value;
if($healthchecksEnabled === true) {
try {
$hc = new Healthchecks($healthchecksUuid);
$hc->start();
} catch(Exception $e) {
Log::error($e->getMessage());
}
}
$output = SpeedtestHelper::output(); $output = SpeedtestHelper::output();
$speedtest = SpeedtestHelper::runSpeedtest($output, $this->scheduled); $speedtest = SpeedtestHelper::runSpeedtest($output, $this->scheduled);
if($speedtest == false) { if($speedtest == false) {
if(isset($hc)) {
try {
$hc->fail();
} catch(Exception $e) {
//
}
}
event(new SpeedtestFailedEvent()); event(new SpeedtestFailedEvent());
} else { } else {
if(isset($hc)) {
try {
$hc->success();
} catch(Exception $e) {
//
}
}
event(new SpeedtestCompleteEvent($speedtest)); event(new SpeedtestCompleteEvent($speedtest));
} }
return $speedtest; return $speedtest;

View File

@@ -1,4 +1,10 @@
{ {
"1.8.0": [
{
"description": "Added healthchecks.io integration.",
"link": ""
}
],
"1.7.19": [ "1.7.19": [
{ {
"description": "Updated dependencies.", "description": "Updated dependencies.",

View File

@@ -14,6 +14,7 @@
"fideloper/proxy": "^4.2", "fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^2.0", "fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0", "guzzlehttp/guzzle": "^7.0",
"henrywhitaker3/healthchecks-io": "^1.0",
"laravel-notification-channels/telegram": "^0.4.0", "laravel-notification-channels/telegram": "^0.4.0",
"laravel/framework": "^7.0", "laravel/framework": "^7.0",
"laravel/slack-notification-channel": "^2.0", "laravel/slack-notification-channel": "^2.0",

203
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "eee4cd81905b1464677cd0295e867901", "content-hash": "837c814b9f3c208c35d3e28d611623fa",
"packages": [ "packages": [
{ {
"name": "asm89/stack-cors", "name": "asm89/stack-cors",
@@ -102,12 +102,6 @@
"brick", "brick",
"math" "math"
], ],
"funding": [
{
"url": "https://tidelift.com/funding/github/packagist/brick/math",
"type": "tidelift"
}
],
"time": "2020-04-15T15:59:35+00:00" "time": "2020-04-15T15:59:35+00:00"
}, },
{ {
@@ -498,20 +492,6 @@
"uppercase", "uppercase",
"words" "words"
], ],
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Finflector",
"type": "tidelift"
}
],
"time": "2020-05-29T15:13:26+00:00" "time": "2020-05-29T15:13:26+00:00"
}, },
{ {
@@ -574,20 +554,6 @@
"parser", "parser",
"php" "php"
], ],
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Flexer",
"type": "tidelift"
}
],
"time": "2020-05-25T17:44:05+00:00" "time": "2020-05-25T17:44:05+00:00"
}, },
{ {
@@ -824,12 +790,6 @@
"crossdomain", "crossdomain",
"laravel" "laravel"
], ],
"funding": [
{
"url": "https://github.com/barryvdh",
"type": "github"
}
],
"time": "2020-05-31T07:30:16+00:00" "time": "2020-05-31T07:30:16+00:00"
}, },
{ {
@@ -1035,6 +995,57 @@
], ],
"time": "2019-07-01T23:21:34+00:00" "time": "2019-07-01T23:21:34+00:00"
}, },
{
"name": "henrywhitaker3/healthchecks-io",
"version": "v1.0.1",
"source": {
"type": "git",
"url": "https://github.com/henrywhitaker3/PHP-healthchecks.io.git",
"reference": "c9dc8bed2f537e6043ec84c0e95182c15f5b990b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/henrywhitaker3/PHP-healthchecks.io/zipball/c9dc8bed2f537e6043ec84c0e95182c15f5b990b",
"reference": "c9dc8bed2f537e6043ec84c0e95182c15f5b990b",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"rakit/validation": "^1.3",
"ramsey/uuid": "^4.1"
},
"require-dev": {
"phpstan/phpstan": "^0.12.37",
"phpunit/phpunit": "^8.5",
"vlucas/phpdotenv": "^5.1"
},
"type": "library",
"autoload": {
"psr-4": {
"Henrywhitaker3\\Healthchecks\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Henry Whitaker",
"email": "henrywhitaker3@outlook.com",
"homepage": "https://github.com/henrywhitaker3"
}
],
"description": "A simple PHP healthchecks.io wrapper",
"homepage": "https://github.com/henrywhitaker3/PHP-healthchecks.io",
"keywords": [
"api",
"healthchecks",
"healthchecks.io",
"wrapper"
],
"time": "2020-08-12T11:56:35+00:00"
},
{ {
"name": "laravel-notification-channels/telegram", "name": "laravel-notification-channels/telegram",
"version": "0.4.1", "version": "0.4.1",
@@ -2548,6 +2559,48 @@
], ],
"time": "2020-05-03T19:32:03+00:00" "time": "2020-05-03T19:32:03+00:00"
}, },
{
"name": "rakit/validation",
"version": "v1.3.2",
"source": {
"type": "git",
"url": "https://github.com/rakit/validation.git",
"reference": "126306ccabeadec24b6fa310605c71be67dee188"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/rakit/validation/zipball/126306ccabeadec24b6fa310605c71be67dee188",
"reference": "126306ccabeadec24b6fa310605c71be67dee188",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": ">=7.0"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.2",
"phpunit/phpunit": "^6.5",
"squizlabs/php_codesniffer": "^3"
},
"type": "library",
"autoload": {
"psr-4": {
"Rakit\\Validation\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Muhammad Syifa",
"email": "emsifa@gmail.com"
}
],
"description": "PHP Laravel like standalone validation library",
"time": "2020-08-09T01:18:04+00:00"
},
{ {
"name": "ralouphie/getallheaders", "name": "ralouphie/getallheaders",
"version": "3.0.3", "version": "3.0.3",
@@ -4119,20 +4172,6 @@
"portable", "portable",
"shim" "shim"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-03-09T19:04:49+00:00" "time": "2020-03-09T19:04:49+00:00"
}, },
{ {
@@ -4491,20 +4530,6 @@
"polyfill", "polyfill",
"shim" "shim"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-03-02T11:55:35+00:00" "time": "2020-03-02T11:55:35+00:00"
}, },
{ {
@@ -5202,12 +5227,6 @@
"jwt", "jwt",
"laravel" "laravel"
], ],
"funding": [
{
"url": "https://www.patreon.com/seantymon",
"type": "patreon"
}
],
"time": "2020-03-04T11:21:28+00:00" "time": "2020-03-04T11:21:28+00:00"
}, },
{ {
@@ -5763,20 +5782,6 @@
"constructor", "constructor",
"instantiate" "instantiate"
], ],
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator",
"type": "tidelift"
}
],
"time": "2020-05-29T17:27:14+00:00" "time": "2020-05-29T17:27:14+00:00"
}, },
{ {
@@ -6367,20 +6372,6 @@
"php", "php",
"symfony" "symfony"
], ],
"funding": [
{
"url": "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L",
"type": "custom"
},
{
"url": "https://github.com/nunomaduro",
"type": "github"
},
{
"url": "https://www.patreon.com/nunomaduro",
"type": "patreon"
}
],
"time": "2020-04-04T19:56:08+00:00" "time": "2020-04-04T19:56:08+00:00"
}, },
{ {
@@ -7257,12 +7248,6 @@
"highlight.php", "highlight.php",
"syntax" "syntax"
], ],
"funding": [
{
"url": "https://github.com/allejo",
"type": "github"
}
],
"time": "2020-03-02T05:59:21+00:00" "time": "2020-03-02T05:59:21+00:00"
}, },
{ {

View File

@@ -7,7 +7,7 @@ return [
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
*/ */
'version' => '1.7.19', 'version' => '1.8.0',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@@ -0,0 +1,47 @@
<?php
use App\Helpers\SettingsHelper;
use App\Setting;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddHealthchecksSettings extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!SettingsHelper::get('healthchecks_enabled')) {
Setting::create([
'name' => 'healthchecks_enabled',
'value' => false,
'description' => 'Enable the healthchecks.io integration for speedtests.'
]);
}
if(!SettingsHelper::get('healthchecks_uuid')) {
Setting::create([
'name' => 'healthchecks_uuid',
'value' => '',
'description' => ''
]);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Setting::whereIn('name', [
'healthchecks_enabled',
'healthchecks_uuid',
])->delete();
}
}

2
public/js/app.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -205,7 +205,6 @@ export default class HistoryGraph extends Component {
failData.datasets[1].data.push(fail); failData.datasets[1].data.push(fail);
failData.labels.push(new Date(e.date).toLocaleString([], {year: '2-digit', month:'2-digit', day:'2-digit'})); failData.labels.push(new Date(e.date).toLocaleString([], {year: '2-digit', month:'2-digit', day:'2-digit'}));
}) })
console.log(failData);
this.setState({ this.setState({
failData: failData, failData: failData,

View File

@@ -158,6 +158,18 @@ export default class Settings extends Component {
} }
]} /> ]} />
</Col> </Col>
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
<SettingWithModal title="healthchecks.io settings" description="Control settings for healthchecks.io" autoClose={false} settings={[
{
obj: e.healthchecks_uuid,
type: 'text'
},
{
obj: e.healthchecks_enabled,
type: 'checkbox'
}
]} />
</Col>
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}> <Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
<ResetSettings /> <ResetSettings />
</Col> </Col>