get_mysql_status
Retrieve MySQL server status including version, uptime, current connections, and query statistics to monitor database health and performance.
Instructions
Get MySQL server status including version, uptime, connections, and query statistics.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| server | No | Server alias (e.g., 'pi1', 'web-server'). Uses default server if not specified. |
Implementation Reference
- src/tools/database.py:135-197 (handler)The async function `get_mysql_status(client: WebminClient) -> ToolResult` that implements the tool logic. It checks if MySQL is running via XML-RPC, returns version/config if running, or graceful error messages if not.
async def get_mysql_status(client: WebminClient) -> ToolResult: """Get MySQL server status. Returns MySQL server status variables and connection info. Args: client: Authenticated WebminClient instance. Returns: ToolResult with MySQL status. """ try: # Check if MySQL is running first running_check = await client.call("mysql", "is_mysql_running") is_running = False error_message = None if isinstance(running_check, list) and len(running_check) > 0: status_code = running_check[0] is_running = status_code == 1 if not is_running and len(running_check) > 1: error_message = str(running_check[1])[:200] elif isinstance(running_check, (int, bool)): is_running = bool(running_check) if not is_running: # Get version info even if not running version = await client.call("mysql", "get_mysql_version") return ToolResult.ok({ "running": False, "installed": bool(version), "version": version if version else None, "error": error_message, }) # Try to get detailed status try: version = await client.call("mysql", "get_mysql_version") config = await client.call("mysql", "get_mysql_config") return ToolResult.ok({ "running": True, "version": version if version else None, "config_files": len(config) if isinstance(config, list) else 0, }) except Exception: return ToolResult.ok({ "running": True, "message": "MySQL is running but detailed status not available via XML-RPC", }) except Exception as e: error_str = str(e).lower() if "connect" in error_str or "running" in error_str or "socket" in error_str: return ToolResult.ok({ "running": False, "error": str(e)[:200], }) return ToolResult.fail( code="MYSQL_STATUS_ERROR", message=f"Failed to get MySQL status: {e}", ) - src/server.py:983-994 (schema)Tool definition registration with name 'get_mysql_status', description, and inputSchema (only optional 'server' param).
Tool( name="get_mysql_status", description=( "Get MySQL server status including version, uptime, " "connections, and query statistics." ), inputSchema={ "type": "object", "properties": {**SERVER_PARAM}, "required": [], }, ), - src/server.py:1759-1760 (registration)Dispatch routing that maps the tool name 'get_mysql_status' to `database.get_mysql_status(client)`.
if name == "get_mysql_status": return await database.get_mysql_status(client) - tests/test_tools_database.py:137-196 (helper)Test class `TestGetMysqlStatus` with 5 test cases covering running, not running, not installed, connection error, and other error scenarios.
class TestGetMysqlStatus: """Tests for get_mysql_status tool.""" async def test_get_status_running(self, mock_client: AsyncMock) -> None: """Test when MySQL is running.""" mock_client.call.side_effect = [ [1, ""], # is_mysql_running "8.0.35", # get_mysql_version [{"name": "mysql", "file": "/etc/mysql/my.cnf"}], # get_mysql_config ] result = await database.get_mysql_status(mock_client) assert result.success assert result.data["running"] is True assert result.data["version"] == "8.0.35" async def test_get_status_not_running(self, mock_client: AsyncMock) -> None: """Test when MySQL is not running.""" mock_client.call.side_effect = [ [0, "Can't connect to MySQL server through socket"], # is_mysql_running "8.0.35", # get_mysql_version still works ] result = await database.get_mysql_status(mock_client) assert result.success assert result.data["running"] is False assert result.data["version"] == "8.0.35" async def test_get_status_not_installed(self, mock_client: AsyncMock) -> None: """Test when MySQL is not installed.""" mock_client.call.side_effect = [ [0, "MySQL not installed"], # is_mysql_running "", # get_mysql_version - empty ] result = await database.get_mysql_status(mock_client) assert result.success assert result.data["running"] is False assert result.data["installed"] is False async def test_get_status_connection_error(self, mock_client: AsyncMock) -> None: """Test connection error is handled gracefully.""" mock_client.call.side_effect = Exception("Can't connect to socket") result = await database.get_mysql_status(mock_client) assert result.success assert result.data["running"] is False async def test_get_status_other_error(self, mock_client: AsyncMock) -> None: """Test other errors are reported.""" mock_client.call.side_effect = Exception("Permission denied") result = await database.get_mysql_status(mock_client) assert not result.success assert result.error.code == "MYSQL_STATUS_ERROR"