Skip to main content

A Prometheus Python client library for asyncio-based applications

Project description

https://travis-ci.org/claws/aioprometheus.svg?branch=master https://img.shields.io/pypi/v/aioprometheus.svg

aioprometheus

aioprometheus is a Prometheus Python client library for asyncio-based applications. It provides metrics collection and serving capabilities, supports multiple data formats and pushing metrics to a gateway.

The project documentation can be found on ReadTheDocs.

Install

$ pip install aioprometheus

Example

The following example shows the @timer decorator being used to expose a metric to Prometheus that measures how long a particular function takes to execute.

import asyncio
import random

from aioprometheus import Service, Summary, timer


# Create a metric to track time spent and requests made.
REQUEST_TIME = Summary(
    'request_processing_seconds', 'Time spent processing request')


# Decorate function with metric.
@timer(REQUEST_TIME)
async def handle_request(duration):
    ''' A dummy function that takes some time '''
    await asyncio.sleep(duration)


async def handle_requests():
    # Start up the server to expose the metrics.
    await svr.start(port=8000)
    # Generate some requests.
    while True:
        await handle_request(random.random())


if __name__ == '__main__':

    loop = asyncio.get_event_loop()

    svr = Service(loop=loop)
    svr.registry.register(REQUEST_TIME)

    try:
        loop.run_until_complete(handle_requests())
    except KeyboardInterrupt:
        pass
    finally:
        loop.run_until_complete(svr.stop())
    loop.stop()
    loop.close()

License

aioprometheus is released under the MIT license.

aioprometheus originates from the (now deprecated) prometheus python package which was released under the MIT license. aioprometheus continues to use the MIT license and contains a copy of the orignal MIT license from the prometheus-python project as instructed by the original license.

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

aioprometheus-16.8.7.tar.gz (34.5 kB view details)

Uploaded Source

File details

Details for the file aioprometheus-16.8.7.tar.gz.

File metadata

File hashes

Hashes for aioprometheus-16.8.7.tar.gz
Algorithm Hash digest
SHA256 76d7f7de29a5fccccf034a02a11a858f9355605f2557c85cc48e9af453f7f05c
MD5 762524156a8eea321fb5ad97176b323d
BLAKE2b-256 a90bff0ec3a9474aabfee368865223e303a19a784deb64abc18a8dfb9537f610

See more details on using hashes here.

Supported by

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