Skip to content

Commit 3b8da2f

Browse files
committed
feat(metrics): implement metrics retrieval class
- Add `Metrics` class with API integration - Create method to retrieve system and Typesense metrics - Define endpoint path for metrics retrieval - Connect with existing `MetricsResponse` type
1 parent 348fb52 commit 3b8da2f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/typesense/metrics.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,39 @@ class MetricsResponse(MetricsResponseBase):
9595
system_cpu24_active_percentage: typing.Optional[str]
9696

9797

98+
class Metrics:
99+
"""
100+
Manages metrics retrieval from the Typesense API.
101+
102+
This class provides methods to retrieve system and Typesense metrics
103+
such as CPU, memory, disk, and network usage.
104+
105+
Attributes:
106+
resource_path (str): The base path for metrics endpoint.
107+
api_call (ApiCall): The ApiCall instance for making API requests.
108+
"""
109+
110+
resource_path: typing.Final[str] = "/metrics.json"
111+
112+
def __init__(self, api_call: ApiCall):
113+
"""
114+
Initialize the Metrics instance.
115+
116+
Args:
117+
api_call (ApiCall): The ApiCall instance for making API requests.
118+
"""
119+
self.api_call = api_call
120+
121+
def retrieve(self) -> MetricsResponse:
122+
"""
123+
Retrieve metrics from the Typesense API.
124+
125+
Returns:
126+
MetricsResponse: A dictionary containing system and Typesense metrics.
127+
"""
128+
response: MetricsResponse = self.api_call.get(
129+
Metrics.resource_path,
130+
as_json=True,
131+
entity_type=MetricsResponse,
132+
)
133+
return response

0 commit comments

Comments
 (0)