Skip to content

Commit 78aafd8

Browse files
authored
Merge pull request #374 from rahuld109/feature/show-info-queries
Add SHOW STORAGE INFO and SHOW BUILD INFO query methods
2 parents f212d3a + fd00a4e commit 78aafd8

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

docs/reference/gqlalchemy/vendors/memgraph.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,31 @@ Terminate transactions in the database.
340340

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

343+
344+
#### get\_storage\_info
345+
346+
```python
347+
def get_storage_info() -> List[dict]
348+
```
349+
350+
Get detailed storage information about the database instance.
351+
352+
**Returns**:
353+
354+
- `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.
355+
356+
#### get\_build\_info
357+
358+
```python
359+
def get_build_info() -> List[dict]
360+
```
361+
362+
Get build information about the Memgraph instance.
363+
364+
**Returns**:
365+
366+
- `List[dict]` - A list of dictionaries with 'build info' and 'value' keys containing build_type (the optimization level).
367+
343368
#### analyze\_graph
344369

345370
```python
@@ -375,3 +400,4 @@ Delete graph statistics previously calculated by analyze_graph.
375400

376401
- `List[dict]` - A list of dictionaries containing deleted index info with keys: label, property.
377402

403+

gqlalchemy/vendors/memgraph.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,31 @@ def terminate_transactions(self, transaction_ids: List[str]) -> List[MemgraphTer
570570

571571
return terminated_transactions
572572

573+
def get_storage_info(self) -> List[dict]:
574+
"""Get detailed storage information about the database instance.
575+
576+
Returns:
577+
List[dict]: A list of dictionaries with 'storage info' and 'value' keys containing:
578+
- name: Current database name
579+
- vertex_count: Total number of stored nodes
580+
- edge_count: Total number of stored relationships
581+
- average_degree: Average number of relationships per node
582+
- memory_res: Non-swapped physical RAM memory used
583+
- disk_usage: Data directory disk space consumption
584+
- memory_tracked: RAM allocated and tracked by Memgraph
585+
- and other storage-related metrics
586+
"""
587+
return list(self.execute_and_fetch("SHOW STORAGE INFO;"))
588+
589+
def get_build_info(self) -> List[dict]:
590+
"""Get build information about the Memgraph instance.
591+
592+
Returns:
593+
List[dict]: A list of dictionaries with 'build info' and 'value' keys containing:
594+
- build_type: The optimization level the instance was built with
595+
"""
596+
return list(self.execute_and_fetch("SHOW BUILD INFO;"))
597+
573598
def analyze_graph(self, labels: Optional[List[str]] = None) -> List[dict]:
574599
"""Analyze graph to calculate statistics for better index selection.
575600

tests/memgraph/test_show_info.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright (c) 2016-2022 Memgraph Ltd. [https://memgraph.com]
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from unittest.mock import patch
16+
17+
from gqlalchemy.vendors.memgraph import Memgraph
18+
19+
20+
def test_get_storage_info():
21+
"""Test get_storage_info returns storage information."""
22+
memgraph = Memgraph()
23+
mock_result = [
24+
{"storage info": "name", "value": "memgraph"},
25+
{"storage info": "vertex_count", "value": 100},
26+
{"storage info": "edge_count", "value": 200},
27+
]
28+
29+
with patch.object(Memgraph, "execute_and_fetch", return_value=iter(mock_result)) as mock:
30+
result = memgraph.get_storage_info()
31+
32+
mock.assert_called_with("SHOW STORAGE INFO;")
33+
assert result == mock_result
34+
35+
36+
def test_get_build_info():
37+
"""Test get_build_info returns build information."""
38+
memgraph = Memgraph()
39+
mock_result = [
40+
{"build info": "build_type", "value": "Release"},
41+
]
42+
43+
with patch.object(Memgraph, "execute_and_fetch", return_value=iter(mock_result)) as mock:
44+
result = memgraph.get_build_info()
45+
46+
mock.assert_called_with("SHOW BUILD INFO;")
47+
assert result == mock_result

0 commit comments

Comments
 (0)