Skip to content

Commit af3abb8

Browse files
committed
fix: improve connection pool and server metrics display
- Fix connection count calculation in MonitorManager to use visible connections from SHOW PROCESSLIST instead of Threads_connected - Fix visibleHeight calculation in ConnectionPoolPane to correctly display all connections - Add support for Oracle connection IDs (sid) and schema names in ConnectionPoolPane - Fix SchemaBrowserPane to handle array table data correctly - Improve ServerMetricsPane metric labels for clarity: - visible_connections -> Connections (matches ConnectionPoolPane) - threads_connected -> Current Connections - threads_running -> Active Queries - questions -> Queries (session) - connections -> Connections (lifetime) - Fix uptime retrieval in MySQL/MariaDB dialects to use rawQuery instead of rawQueryValue
1 parent f9cc8af commit af3abb8

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

src/cli/MonitorManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ protected static function getActiveConnectionsMySQL(PdoDb $db): array
172172
}
173173

174174
// Get connection limits
175-
$status = $db->rawQuery("SHOW STATUS LIKE 'Threads_connected'");
175+
// Use count of visible connections from SHOW PROCESSLIST for current
176+
// (SHOW PROCESSLIST only shows connections user has permission to see)
176177
$maxConn = $db->rawQuery("SHOW VARIABLES LIKE 'max_connections'");
177-
$currentVal = $status[0]['Value'] ?? 0;
178178
$maxVal = $maxConn[0]['Value'] ?? 0;
179-
$current = is_int($currentVal) ? $currentVal : (is_string($currentVal) ? (int)$currentVal : 0);
180179
$max = is_int($maxVal) ? $maxVal : (is_string($maxVal) ? (int)$maxVal : 0);
180+
$current = count($result); // Use actual count of visible connections
181181

182182
return [
183183
'connections' => $result,

src/cli/ui/panes/ConnectionPoolPane.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,23 @@ public static function render(PdoDb $db, Layout $layout, int $paneIndex, bool $a
137137
}
138138

139139
// Calculate visible height for connections list
140-
// Content area includes: summary (3 rows) + label (1 row) + table header (1 row) + connections list
140+
// Content area includes: summary (3 rows) + spacing (2 rows) + label (1 row) + table header (1 row) + connections list
141141
// In fullscreen: content['height'] = $rows - 2 (header + footer)
142142
// Connections list starts at row 8 (after summary 3 rows + spacing 2 rows + label 1 row + table header 1 row)
143143
// Footer is at row $rows, so last connection row = $rows - 1
144144
// Visible height = ($rows - 1) - 8 + 1 = $rows - 8
145145
$summaryHeight = 3;
146+
$spacingHeight = 2; // Spacing after summary (row += 2)
146147
$labelHeight = 1;
147148
$tableHeaderHeight = 1;
148149
if ($fullscreen) {
149150
// In fullscreen: header (row 1) + summary (rows 2-4) + spacing (row 5) + label (row 6) + table header (row 7) + list (starts row 8) + footer (row $rows)
150151
// Visible height = $rows - 1 (footer) - 7 (header + summary + spacing + label + table header) = $rows - 8
151-
$visibleHeight = $rows - 1 - ($summaryHeight + 2 + $labelHeight + $tableHeaderHeight); // +2 for spacing before label
152+
$visibleHeight = $rows - 1 - ($summaryHeight + $spacingHeight + $labelHeight + $tableHeaderHeight);
152153
} else {
153-
$visibleHeight = $content['height'] - $summaryHeight - 2; // -2 for header and spacing
154+
// In normal mode: summary (3 rows) + spacing (2 rows) + label (1 row) + table header (1 row) = 7 rows used
155+
// Available for connections = content['height'] - 7
156+
$visibleHeight = $content['height'] - $summaryHeight - $spacingHeight - $labelHeight - $tableHeaderHeight;
154157
}
155158

156159
$colWidth = (int)floor($content['width'] / 3);
@@ -199,9 +202,9 @@ public static function render(PdoDb $db, Layout $layout, int $paneIndex, bool $a
199202
Terminal::color(Terminal::COLOR_BLACK);
200203
}
201204

202-
$id = self::truncate((string)($conn['id'] ?? $conn['pid'] ?? $conn['session_id'] ?? ''), $colWidth);
205+
$id = self::truncate((string)($conn['id'] ?? $conn['pid'] ?? $conn['session_id'] ?? $conn['sid'] ?? ''), $colWidth);
203206
$user = self::truncate((string)($conn['user'] ?? $conn['usename'] ?? $conn['login'] ?? ''), $colWidth);
204-
$dbName = self::truncate((string)($conn['db'] ?? $conn['database'] ?? $conn['datname'] ?? ''), $content['width'] - ($colWidth * 2));
207+
$dbName = self::truncate((string)($conn['db'] ?? $conn['database'] ?? $conn['datname'] ?? $conn['schema'] ?? ''), $content['width'] - ($colWidth * 2));
205208

206209
$marker = $isSelected ? '> ' : ' ';
207210
$rowText = $marker . str_pad($id, $colWidth - 2) . str_pad($user, $colWidth) . $dbName;

src/cli/ui/panes/SchemaBrowserPane.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,11 @@ protected static function renderFullscreen(PdoDb $db, array $content, array $tab
152152
Terminal::color(Terminal::COLOR_BLACK);
153153
}
154154

155+
// Extract table name if $table is an array, otherwise use string directly
156+
$tableName = is_array($table) ? ($table['name'] ?? (string)($table[0] ?? '')) : (string)$table;
157+
155158
$marker = $isSelected ? '> ' : ' ';
156-
$tableText = $marker . $table;
159+
$tableText = $marker . $tableName;
157160
if (mb_strlen($tableText, 'UTF-8') > $content['width']) {
158161
$tableText = mb_substr($tableText, 0, $content['width'] - 3, 'UTF-8') . '...';
159162
}

src/cli/ui/panes/ServerMetricsPane.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@ public static function render(PdoDb $db, Layout $layout, int $paneIndex, bool $a
7777

7878
// Display key metrics (dialect-specific)
7979
// Note: Questions and Queries are cumulative counters since server start
80+
// Use visible_connections if available (matches ConnectionPoolPane), otherwise fall back to threads_connected
8081
$keyMetrics = [
81-
'threads_connected' => 'Connections',
82-
'threads_running' => 'Running',
83-
'questions' => 'Questions (total)',
82+
'visible_connections' => 'Connections',
83+
'threads_connected' => 'Current Connections',
84+
'threads_running' => 'Active Queries',
85+
'questions' => 'Queries (session)',
8486
'queries' => 'Queries (total)',
8587
'slow_queries' => 'Slow Queries',
86-
'connections' => 'Connections',
88+
'connections' => 'Connections (lifetime)',
8789
'commits' => 'Commits',
8890
'rollbacks' => 'Rollbacks',
8991
'sessions' => 'Sessions',

src/dialects/mariadb/MariaDBDialect.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,8 +1582,9 @@ public function getServerMetrics(PdoDb $db): array
15821582
$metrics['version'] = is_string($version) ? $version : 'unknown';
15831583

15841584
// Get uptime
1585-
$uptime = $db->rawQueryValue("SHOW STATUS WHERE Variable_name = 'Uptime'");
1586-
$uptimeValue = is_int($uptime) ? $uptime : (is_string($uptime) ? (int)$uptime : 0);
1585+
$uptimeResult = $db->rawQuery("SHOW STATUS WHERE Variable_name = 'Uptime'");
1586+
$uptimeValue = $uptimeResult[0]['Value'] ?? 0;
1587+
$uptimeValue = is_int($uptimeValue) ? $uptimeValue : (is_string($uptimeValue) ? (int)$uptimeValue : 0);
15871588
$metrics['uptime_seconds'] = $uptimeValue;
15881589

15891590
// Get key status variables

src/dialects/mysql/MySQLDialect.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,8 +1625,9 @@ public function getServerMetrics(PdoDb $db): array
16251625
$metrics['version'] = is_string($version) ? $version : 'unknown';
16261626

16271627
// Get uptime
1628-
$uptime = $db->rawQueryValue("SHOW STATUS WHERE Variable_name = 'Uptime'");
1629-
$uptimeValue = is_int($uptime) ? $uptime : (is_string($uptime) ? (int)$uptime : 0);
1628+
$uptimeResult = $db->rawQuery("SHOW STATUS WHERE Variable_name = 'Uptime'");
1629+
$uptimeValue = $uptimeResult[0]['Value'] ?? 0;
1630+
$uptimeValue = is_int($uptimeValue) ? $uptimeValue : (is_string($uptimeValue) ? (int)$uptimeValue : 0);
16301631
$metrics['uptime_seconds'] = $uptimeValue;
16311632

16321633
// Get key status variables

0 commit comments

Comments
 (0)