Skip to content

Commit

Permalink
Merge pull request #9 from arueckauer/docs/various-fixes-and-improvem…
Browse files Browse the repository at this point in the history
…ents

Docs/various fixes and improvements
  • Loading branch information
weierophinney committed Aug 11, 2020
2 parents ed2e639 + a4f55a3 commit 82e48b0
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 30 deletions.
14 changes: 7 additions & 7 deletions docs/book/architecture.md
@@ -1,22 +1,22 @@
# Architecture

A single diagnostic [Check](https://github.com/laminas/tree/master/src/Check/CheckInterface.php)
A single diagnostic [Check](https://github.com/laminas/laminas-diagnostics/blob/master/src/Check/CheckInterface.php)
performs one particular test on the application or environment.

It MUST return a [Result](src/laminas-diagnostics/Result/ResultInterface.php)
It MUST return a [Result](https://github.com/laminas/laminas-diagnostics/blob/master/src/Result/ResultInterface.php)
which implements one of the following result interfaces:

- [Success](https://github.com/laminas/tree/master/src/Result/SuccessInterface.php) - in case the check ran through without any issue.
- [Warning](https://github.com/laminas/tree/master/src/Result/WarningInterface.php) - in case there might be something wrong.
- [Failure](https://github.com/laminas/tree/master/src/Result/FailureInterface.php) - when the test failed and an intervention is required.
- [Success](https://github.com/laminas/laminas-diagnostics/blob/master/src/Result/SuccessInterface.php) - in case the check ran through without any issue.
- [Warning](https://github.com/laminas/laminas-diagnostics/blob/master/src/Result/WarningInterface.php) - in case there might be something wrong.
- [Failure](https://github.com/laminas/laminas-diagnostics/blob/master/src/Result/FailureInterface.php) - when the test failed and an intervention is required.

Each test [Result](https://github.com/laminas/tree/master/src/Result/ResultInterface.php) can additionally return:
Each test [Result](https://github.com/laminas/laminas-diagnostics/blob/master/src/Result/ResultInterface.php) can additionally return:

- **result message** via `getMessage()`. It can be used to describe the context of the result.
- **result data** via `getData()`. This can be used for providing detailed information on the cause of particular
result, which might be useful for debugging problems.

One can define additional [result interfaces](https://github.com/laminas/tree/master/src/Result/ResultInterface.php),
One can define additional [result interfaces](https://github.com/laminas/laminas-diagnostics/blob/master/src/Result/ResultInterface.php),
to denote additional severity levels (e.g. critical, alert, notice) or
appropriate actions (i.e. missing, incomplete). However, it is recommended to
extend the primary set of success, warning, and failure interfaces for
Expand Down
8 changes: 4 additions & 4 deletions docs/book/custom-checks.md
@@ -1,6 +1,6 @@
# Writing Custom Checks

A Check class MUST implement [Check](https://github.com/laminas/laminas-diagnostics/tree/master/src/Check/CheckInterface.php)
A Check class MUST implement [CheckInterface](https://github.com/laminas/laminas-diagnostics/tree/master/src/Check/CheckInterface.php)
and provide the following methods:

```php
Expand All @@ -26,9 +26,9 @@ interface CheckInterface
```

The main `check()` method is responsible for performing the actual check, and is
expected to return a [Result](https://github.com/laminas/laminas-diagnostics/tree/master/src/Result/ResultInterface.php).
It is recommended to use the built-in result classes for compatibility with the
diagnostics Runner and other checks.
expected to return a [ResultInterface](https://github.com/laminas/laminas-diagnostics/tree/master/src/Result/ResultInterface.php)
instance. It is recommended to use the built-in result classes for
compatibility with the diagnostics Runner and other checks.

Below is an example class that checks if the PHP default timezone is set to UTC.

Expand Down
88 changes: 70 additions & 18 deletions docs/book/diagnostics.md
Expand Up @@ -7,7 +7,7 @@ The following built-in tests are currently available:

## ApcFragmentation

Make sure that [APC memory fragmentation level](www.php.net/apc/) is below a
Make sure that [APC memory fragmentation level](https://www.php.net/apc/) is below a
given threshold:

```php
Expand All @@ -20,7 +20,7 @@ $fragmentation = new ApcFragmentation(50, 90);

## ApcMemory

Check [APC memory usage percent](www.php.net/apc/) and make sure it's below a
Check [APC memory usage percent](https://www.php.net/apc/) and make sure it's below a
given threshold.

```php
Expand Down Expand Up @@ -74,6 +74,29 @@ $checkRbacClasses = new ClassExists([
]);
```

## CouchDBCheck

Check if a connection to a given CouchDB server is possible.

```php
<?php
use Laminas\Diagnostics\Check\CouchDBCheck;

// Simple check without credentials
$couchDbNoCredentials = new CouchDBCheck(['url' => 'http://127.0.0.1:5984']);

// Check with user and password
$couchDbSettings = [
'protocol' => 'http',
'host' => '127.0.0.1',
'port' => '5984',
'username' => 'my_username',
'password' => 'I0z&+oFP^FHdd9%i',
'dbname' => 'my_database',
];
$couchDbWithCredentials = new CouchDBCheck($couchDbSettings);
```

## CpuPerformance

Benchmark CPU performance and return failure if it is below the given ratio. The
Expand Down Expand Up @@ -145,7 +168,25 @@ $homeHasAtLeast1TB = new DiskFree('1TiB', '/home');
$dataHasAtLeast900Bytes = new DiskFree(900, __DIR__ . '/data/');
```

### ExtensionLoaded
## DiskUsage

Check if the disk usage is below warning/critical percent thresholds.

The first parameter is the warning threshold, which can be supplied as an
integer (in percent, e.g. `80`). The second parameter is the critical
threshold, which is also supplied as an integer (in percent, e.g. `90`). The
third parameter is the disk path to check; on \*NIX systems it is an ordinary
path (e.g. `/tmp`), while on Windows systems it is a drive letter (e.g. `C:`).

```php
<?php
use Laminas\Diagnostics\Check\DiskUsage;

$diskUsageNix = new DiskUsage(80, 90, '/tmp');
$diskUsageWin = new DiskUsage(80, 90, 'C:');
```

## ExtensionLoaded

Check if a PHP extension (or an array of extensions) is currently loaded.

Expand Down Expand Up @@ -192,8 +233,8 @@ $checkPageContent = new HttpService(
## GuzzleHttpService

Attempt connection to a given HTTP host or IP address and try to load a web page
using [Guzzle](http://docs.guzzlephp.org). The check also supports checking
response codes and page contents.
using [Guzzle](https://docs.guzzlephp.org/en/stable/). The check also supports
checking response codes and page contents.

The constructor signature of the `GuzzleHttpService` is as follows:

Expand Down Expand Up @@ -309,38 +350,49 @@ $checkLocal = new Memcached('127.0.0.1'); // default port
$checkBackup = new Memcached('10.0.30.40', 11212);
```

### MongoDb
Check if connection to MongoDb is possible
## MongoDb

Check if a connection to a given MongoDb server is possible.

````php
```php
<?php
use Laminas\Diagnostics\Check\Mongo;

$mongoCheck = new Mongo('mongodb://127.0.0.1:27017');
// and with user/password
$mongoCheck = new Mongo('mongodb://user:password@127.0.0.1:27017');
````
```

## OpCacheMemory

Check [OPcache memory usage percent](https://www.php.net/opcache) and make sure it's below a
given threshold.

## MongoDb
```php
<?php
use Laminas\Diagnostics\Check\OpCacheMemory;

Check if a connection to a given MongoDb server is possible.
// Display a warning with memory usage is above 70% and a failure above 90%
$opCacheMemory = new OpCacheMemory(70, 90);
```

## PDOCheck

Check if a connection to a given database server is possible.

```php
<?php
use Laminas\Diagnostics\Check\Mongo;
use Laminas\Diagnostics\Check\PDOCheck;

$mongoCheck = new Mongo('mongodb://127.0.0.1:27017');
// and with user/password
$mongoCheck = new Mongo('mongodb://user:password@127.0.0.1:27017');
$pdoMySql = new PDOCheck('mysql://localhost/my_database', 'my_username', 'oFPZc!W&zV>,YCrz');
$pdoSqlite = new PDOCheck('sqlite:example.db', '', '');
```

## PhpVersion

Check if the current PHP version matches the given requirement. The test accepts
2 parameters: baseline version and optional
[comparison operator](http://www.php.net/manual/en/function.version-compare.php).
[comparison operator](https://www.php.net/version_compare).

```php
<?php
Expand Down Expand Up @@ -412,8 +464,8 @@ $redisCheck = new Redis('localhost', 6379, 'secret');
## SecurityAdvisory

Run a security check of libraries locally installed by
[Composer](http://getcomposer.org) against [SensioLabs Security Advisory
database](https://security.sensiolabs.org/database), and warn about potential
[Composer](https://getcomposer.org/) against [SensioLabs Security Advisory
database](https://security.symfony.com/), and warn about potential
security vulnerabilities.

```php
Expand Down
2 changes: 1 addition & 1 deletion docs/book/usage.md
Expand Up @@ -71,7 +71,7 @@ OK (2 diagnostic tests)
## Using a result collection

The diagnostics runner will always return a
[Laminas\Diagnostics\Result\Collection](https://github.com/laminas/laminas-diagnostics/src/Result/Collection.php),
[Laminas\Diagnostics\Result\Collection](https://github.com/laminas/laminas-diagnostics/blob/master/src/Result/Collection.php),
even when no reporter is attached. This collection contains results for all
tests and failure counters.

Expand Down

0 comments on commit 82e48b0

Please sign in to comment.