Skip to main content

No project description provided

Project description

httpx-metrics

httpx-metrics is a utility library that offers classes for integrating metrics into your httpx client (currently, it supports only Prometheus metrics).

PyPI - Version PyPI - Python Version


Table of Contents

Installation

pip install httpx-metrics

Usage

import httpx
import anyio
from httpx_metrics.async_metrics import (
    AsyncDownloadDurationMetric,
    AsyncProcessingRequestsMetric,
    AsyncRequestsDurationMetric,
    AsyncTotalRequestsMetric,
)
from httpx_metrics import AsyncPrometheusTransport

metrics_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 transports

    Type: Counter

    Description: Total number of cached requests

    Labels

    • method
    • status_code
    • path
    • version
    • revalidated

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

httpx_metrics-0.0.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

httpx_metrics-0.0.1-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file httpx_metrics-0.0.1.tar.gz.

File metadata

  • Download URL: httpx_metrics-0.0.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for httpx_metrics-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c933e4b13a2dfbc0aafb502d5edaa0a224376761532e29a2cef1d7b6833b57e7
MD5 c73279d7d7a446c39513dce1545349be
BLAKE2b-256 9eeba646a6fb3b0f059568f56d130de817346e892552e0a913e78240ab340749

See more details on using hashes here.

File details

Details for the file httpx_metrics-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for httpx_metrics-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 972899238a190688a4e9f0b7292eaaa42e94350f0fed1e3788794917e81fc7a4
MD5 c74a1608a013b0c4f672b9bf5dd4fa23
BLAKE2b-256 7f835704d4ede28bb4f391b07f6a51a713c863be7d52d9369b2a231fb58e6b26

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page