PCP Client¶
pcp_mcp.client
¶
Async client for pmproxy REST API.
PCPClient
¶
PCPClient(
base_url: str,
target_host: str = "localhost",
auth: tuple[str, str] | None = None,
timeout: float = 30.0,
verify: bool | str = True,
)
Async client for pmproxy REST API.
Handles PMAPI context management and metric fetching via the pmproxy REST API endpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Base URL for pmproxy (e.g., http://localhost:44322). |
required |
target_host
|
str
|
Which pmcd host to connect to (passed as hostspec). |
'localhost'
|
auth
|
tuple[str, str] | None
|
Optional HTTP basic auth tuple (username, password). |
None
|
timeout
|
float
|
Request timeout in seconds. |
30.0
|
verify
|
bool | str
|
TLS verification (True, False, or path to CA bundle). |
True
|
Initialize the PCP client.
Source code in src/pcp_mcp/client.py
__aenter__
async
¶
Enter async context and establish pmapi context.
Source code in src/pcp_mcp/client.py
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: object,
) -> None
Exit async context and close httpx client.
Source code in src/pcp_mcp/client.py
describe
async
¶
Get metric metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_name
|
str
|
Full PCP metric name. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Metric metadata dict, or empty dict if not found. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If client is not connected. |
HTTPStatusError
|
If the request fails. |
Source code in src/pcp_mcp/client.py
fetch
async
¶
Fetch current values for metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_names
|
list[str]
|
List of PCP metric names to fetch. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Raw JSON response from pmproxy /pmapi/fetch endpoint. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If client is not connected. |
HTTPStatusError
|
If the request fails. |
Source code in src/pcp_mcp/client.py
fetch_with_rates
async
¶
fetch_with_rates(
metric_names: list[str],
counter_metrics: set[str],
sample_interval: float = 1.0,
progress_callback: ProgressCallback | None = None,
) -> dict[str, dict]
Fetch metrics, calculating rates for counters.
Takes two samples separated by sample_interval seconds. Counter metrics are converted to per-second rates. Gauge metrics return the second sample's value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_names
|
list[str]
|
List of PCP metric names to fetch. |
required |
counter_metrics
|
set[str]
|
Set of metric names that are counters. |
required |
sample_interval
|
float
|
Seconds between samples for rate calculation. |
1.0
|
progress_callback
|
ProgressCallback | None
|
Optional async callback for progress updates. Called with (current, total, message) during long operations. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
Dict mapping metric name to {value, instances} where value/instances |
dict[str, dict]
|
contain the rate (for counters) or instant value (for gauges). |
Source code in src/pcp_mcp/client.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
search
async
¶
Search for metrics matching pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
Metric name prefix to search for (e.g., "kernel.all"). |
required |
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of metric metadata dicts from pmproxy. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If client is not connected. |
HTTPStatusError
|
If the request fails. |