PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.2
Independent Analytics – WordPress Analytics Plugin v2.15.2
2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / illuminate / database / Console / MonitorCommand.php
independent-analytics / vendor / illuminate / database / Console Last commit date
Factories 2 weeks ago Migrations 2 weeks ago Seeds 2 weeks ago DatabaseInspectionCommand.php 2 weeks ago DbCommand.php 2 weeks ago DumpCommand.php 2 weeks ago MonitorCommand.php 2 weeks ago PruneCommand.php 2 weeks ago ShowCommand.php 2 weeks ago TableCommand.php 2 weeks ago WipeCommand.php 2 weeks ago
MonitorCommand.php
124 lines
1 <?php
2
3 namespace IAWPSCOPED\Illuminate\Database\Console;
4
5 use IAWPSCOPED\Illuminate\Contracts\Events\Dispatcher;
6 use IAWPSCOPED\Illuminate\Database\ConnectionResolverInterface;
7 use IAWPSCOPED\Illuminate\Database\Events\DatabaseBusy;
8 use IAWPSCOPED\Illuminate\Support\Composer;
9 use IAWPSCOPED\Symfony\Component\Console\Attribute\AsCommand;
10 /** @internal */
11 #[AsCommand(name: 'db:monitor')]
12 class MonitorCommand extends DatabaseInspectionCommand
13 {
14 /**
15 * The name and signature of the console command.
16 *
17 * @var string
18 */
19 protected $signature = 'db:monitor
20 {--databases= : The database connections to monitor}
21 {--max= : The maximum number of connections that can be open before an event is dispatched}';
22 /**
23 * The name of the console command.
24 *
25 * This name is used to identify the command during lazy loading.
26 *
27 * @var string|null
28 *
29 * @deprecated
30 */
31 protected static $defaultName = 'db:monitor';
32 /**
33 * The console command description.
34 *
35 * @var string
36 */
37 protected $description = 'Monitor the number of connections on the specified database';
38 /**
39 * The connection resolver instance.
40 *
41 * @var \Illuminate\Database\ConnectionResolverInterface
42 */
43 protected $connection;
44 /**
45 * The events dispatcher instance.
46 *
47 * @var \Illuminate\Contracts\Events\Dispatcher
48 */
49 protected $events;
50 /**
51 * Create a new command instance.
52 *
53 * @param \Illuminate\Database\ConnectionResolverInterface $connection
54 * @param \Illuminate\Contracts\Events\Dispatcher $events
55 * @param \Illuminate\Support\Composer $composer
56 */
57 public function __construct(ConnectionResolverInterface $connection, Dispatcher $events, Composer $composer)
58 {
59 parent::__construct($composer);
60 $this->connection = $connection;
61 $this->events = $events;
62 }
63 /**
64 * Execute the console command.
65 *
66 * @return void
67 */
68 public function handle()
69 {
70 $databases = $this->parseDatabases($this->option('databases'));
71 $this->displayConnections($databases);
72 if ($this->option('max')) {
73 $this->dispatchEvents($databases);
74 }
75 }
76 /**
77 * Parse the database into an array of the connections.
78 *
79 * @param string $databases
80 * @return \Illuminate\Support\Collection
81 */
82 protected function parseDatabases($databases)
83 {
84 return \IAWPSCOPED\collect(\explode(',', $databases))->map(function ($database) {
85 if (!$database) {
86 $database = $this->laravel['config']['database.default'];
87 }
88 $maxConnections = $this->option('max');
89 return ['database' => $database, 'connections' => $connections = $this->getConnectionCount($this->connection->connection($database)), 'status' => $maxConnections && $connections >= $maxConnections ? '<fg=yellow;options=bold>ALERT</>' : '<fg=green;options=bold>OK</>'];
90 });
91 }
92 /**
93 * Display the databases and their connection counts in the console.
94 *
95 * @param \Illuminate\Support\Collection $databases
96 * @return void
97 */
98 protected function displayConnections($databases)
99 {
100 $this->newLine();
101 $this->components->twoColumnDetail('<fg=gray>Database name</>', '<fg=gray>Connections</>');
102 $databases->each(function ($database) {
103 $status = '[' . $database['connections'] . '] ' . $database['status'];
104 $this->components->twoColumnDetail($database['database'], $status);
105 });
106 $this->newLine();
107 }
108 /**
109 * Dispatch the database monitoring events.
110 *
111 * @param \Illuminate\Support\Collection $databases
112 * @return void
113 */
114 protected function dispatchEvents($databases)
115 {
116 $databases->each(function ($database) {
117 if ($database['status'] === '<fg=green;options=bold>OK</>') {
118 return;
119 }
120 $this->events->dispatch(new DatabaseBusy($database['database'], $database['connections']));
121 });
122 }
123 }
124