https://github.com/karpetrosyan/httpx-metrics
https://github.com/karpetrosyan/httpx-metrics
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/karpetrosyan/httpx-metrics
- Owner: karpetrosyan
- License: mit
- Created: 2024-06-20T17:41:44.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2024-06-23T15:44:24.000Z (12 months ago)
- Last Synced: 2025-04-06T06:48:52.403Z (2 months ago)
- Language: Python
- Size: 17.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# httpx-metrics
httpx-metrics is a utility library that offers classes for integrating metrics into your httpx client (currently, it supports only Prometheus metrics).
[](https://pypi.org/project/httpx-metrics)
[](https://pypi.org/project/httpx-metrics)-----
## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [Supported metrics](#supported-metrics)## Installation
```console
pip install httpx-metrics
```## Usage
```python
import httpx
import anyio
from httpx_metrics.async_metrics import (
AsyncDownloadDurationMetric,
AsyncProcessingRequestsMetric,
AsyncRequestsDurationMetric,
AsyncTotalRequestsMetric,
)
from httpx_metrics import AsyncPrometheusTransportmetrics_transport = AsyncPrometheusTransport(
next_transport=httpx.AsyncHTTPTransport(),
metrics=[
AsyncRequestsDurationMetric(),
AsyncTotalRequestsMetric(),
AsyncProcessingRequestsMetric(),
AsyncDownloadDurationMetric(),
],
exporter_port=8000,
)async def main():
async with httpx.AsyncClient(transport=metrics_transport) as client:
while True:
response = await client.get("https://www.encode.io")
await anyio.sleep(5)anyio.run(main)
```## Supported metrics
- **AsyncTotalRequestsMetric** / **TotalRequestsMetric**
**Type**: Counter**Description**: Total number of requests
**Labels**
- method
- status_code
- path
- version- **AsyncRequestsDurationMetric** / **RequestsDurationMetric**
**Type**: Histogram
**Description**: Request duration in seconds
**Labels**
- method
- status_code
- path
- version- **AsyncProcessingRequestsMetric** / **ProcessingRequestsMetric**
**Type**: Gauge
**Description**: Number of requests in fly
**Labels**
- method
- path- **AsyncDownloadDurationMetric** / **DownloadDurationMetric**
**Type**: Histogram
**Description**: Response body downloading duration in seconds
**Labels**
- method
- status_code
- path
- version- **AsyncCachedRequestsMetric** / **CachedRequestsMetric**
**Note**: This metric should be used on top of [hishel](hishel.com) transports
**Type**: Counter
**Description**: Total number of cached requests
**Labels**
- method
- status_code
- path
- version
- revalidated