| @@ 10-52 (lines=43) @@ | ||
| 7 | use Illuminate\Database\Capsule\Manager; |
|
| 8 | use JildertMiedema\SystemMonitor\System\MeasurementStore; |
|
| 9 | ||
| 10 | final class MysqlConnectionSpeed implements Measurement |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var Manager |
|
| 14 | */ |
|
| 15 | private $manager; |
|
| 16 | ||
| 17 | public function __construct(Manager $manager) |
|
| 18 | { |
|
| 19 | $this->manager = $manager; |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * The name of the. |
|
| 24 | * |
|
| 25 | * @return string |
|
| 26 | */ |
|
| 27 | public function name(): string |
|
| 28 | { |
|
| 29 | return 'mysql.speed'; |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * Runs the measurement. |
|
| 34 | * |
|
| 35 | * @param MeasurementStore $store |
|
| 36 | * @param array $data |
|
| 37 | */ |
|
| 38 | public function run(MeasurementStore $store, array $data) |
|
| 39 | { |
|
| 40 | $connection = array_get($data, 'connection'); |
|
| 41 | $key = array_get($data, 'key'); |
|
| 42 | ||
| 43 | $database = $this->manager->getConnection($connection); |
|
| 44 | ||
| 45 | $timerStart = microtime(true); |
|
| 46 | $database->select('SELECT 1'); |
|
| 47 | $timerEnd = microtime(true); |
|
| 48 | $time = round(($timerEnd - $timerStart) * 1000, 4); |
|
| 49 | ||
| 50 | $store->storeTimer($key, $time . '|ms'); |
|
| 51 | } |
|
| 52 | } |
|
| 53 | ||
| @@ 10-52 (lines=43) @@ | ||
| 7 | use Illuminate\Redis\RedisManager; |
|
| 8 | use JildertMiedema\SystemMonitor\System\MeasurementStore; |
|
| 9 | ||
| 10 | final class RedisConnectionSpeed implements Measurement |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var RedisManager |
|
| 14 | */ |
|
| 15 | private $redis; |
|
| 16 | ||
| 17 | public function __construct(RedisManager $redis) |
|
| 18 | { |
|
| 19 | $this->redis = $redis; |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * The name of the. |
|
| 24 | * |
|
| 25 | * @return string |
|
| 26 | */ |
|
| 27 | public function name(): string |
|
| 28 | { |
|
| 29 | return 'redis.speed'; |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * Runs the measurement. |
|
| 34 | * |
|
| 35 | * @param MeasurementStore $store |
|
| 36 | * @param array $data |
|
| 37 | */ |
|
| 38 | public function run(MeasurementStore $store, array $data) |
|
| 39 | { |
|
| 40 | $connection = array_get($data, 'connection'); |
|
| 41 | $key = array_get($data, 'key'); |
|
| 42 | ||
| 43 | $database = $this->redis->connection($connection)->client(); |
|
| 44 | ||
| 45 | $timer_start = microtime(true); |
|
| 46 | $database->ping('PING'); |
|
| 47 | $timer_end = microtime(true); |
|
| 48 | $time = round(($timer_end - $timer_start) * 1000, 4); |
|
| 49 | ||
| 50 | $store->storeTimer($key, $time . '|ms'); |
|
| 51 | } |
|
| 52 | } |
|
| 53 | ||