Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/reference/gqlalchemy/vendors/memgraph.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,27 @@ Terminate transactions in the database.

- `List[MemgraphTerminatedTransaction]` - A list of MemgraphTerminatedTransaction objects with info on their status.

#### get\_storage\_info

```python
def get_storage_info() -> List[dict]
```

Get detailed storage information about the database instance.

**Returns**:

- `List[dict]` - A list of dictionaries with 'storage info' and 'value' keys containing storage metrics like name, vertex_count, edge_count, memory_res, disk_usage, etc.

#### get\_build\_info

```python
def get_build_info() -> List[dict]
```

Get build information about the Memgraph instance.

**Returns**:

- `List[dict]` - A list of dictionaries with 'build info' and 'value' keys containing build_type (the optimization level).

25 changes: 25 additions & 0 deletions gqlalchemy/vendors/memgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,28 @@ def terminate_transactions(self, transaction_ids: List[str]) -> List[MemgraphTer
terminated_transactions = list(map(create_terminated_transaction, transactions_data))

return terminated_transactions

def get_storage_info(self) -> List[dict]:
"""Get detailed storage information about the database instance.

Returns:
List[dict]: A list of dictionaries with 'storage info' and 'value' keys containing:
- name: Current database name
- vertex_count: Total number of stored nodes
- edge_count: Total number of stored relationships
- average_degree: Average number of relationships per node
- memory_res: Non-swapped physical RAM memory used
- disk_usage: Data directory disk space consumption
- memory_tracked: RAM allocated and tracked by Memgraph
- and other storage-related metrics
"""
return list(self.execute_and_fetch("SHOW STORAGE INFO;"))

def get_build_info(self) -> List[dict]:
"""Get build information about the Memgraph instance.

Returns:
List[dict]: A list of dictionaries with 'build info' and 'value' keys containing:
- build_type: The optimization level the instance was built with
"""
return list(self.execute_and_fetch("SHOW BUILD INFO;"))
47 changes: 47 additions & 0 deletions tests/memgraph/test_show_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright (c) 2016-2022 Memgraph Ltd. [https://memgraph.com]
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest.mock import patch

from gqlalchemy.vendors.memgraph import Memgraph


def test_get_storage_info():
"""Test get_storage_info returns storage information."""
memgraph = Memgraph()
mock_result = [
{"storage info": "name", "value": "memgraph"},
{"storage info": "vertex_count", "value": 100},
{"storage info": "edge_count", "value": 200},
]

with patch.object(Memgraph, "execute_and_fetch", return_value=iter(mock_result)) as mock:
result = memgraph.get_storage_info()

mock.assert_called_with("SHOW STORAGE INFO;")
assert result == mock_result


def test_get_build_info():
"""Test get_build_info returns build information."""
memgraph = Memgraph()
mock_result = [
{"build info": "build_type", "value": "Release"},
]

with patch.object(Memgraph, "execute_and_fetch", return_value=iter(mock_result)) as mock:
result = memgraph.get_build_info()

mock.assert_called_with("SHOW BUILD INFO;")
assert result == mock_result