ÿØÿàJFIFHHÿá .
BSA HACKER
Logo of a company Server : Apache
System : Linux nusantara.hosteko.com 4.18.0-553.16.1.lve.el8.x86_64 #1 SMP Tue Aug 13 17:45:03 UTC 2024 x86_64
User : koperas1 ( 1254)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /opt/cloudlinux/venv/lib64/python3.11/site-packages/prometheus_client/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/prometheus_client/asgi.py
from urllib.parse import parse_qs

from .exposition import _bake_output
from .registry import REGISTRY


def make_asgi_app(registry=REGISTRY):
    """Create a ASGI app which serves the metrics from a registry."""

    async def prometheus_app(scope, receive, send):
        assert scope.get("type") == "http"
        # Prepare parameters
        params = parse_qs(scope.get('query_string', b''))
        accept_header = "Accept: " + ",".join([
            value.decode("utf8") for (name, value) in scope.get('headers')
            if name.decode("utf8") == 'accept'
        ])
        # Bake output
        status, header, output = _bake_output(registry, accept_header, params)
        # Return output
        payload = await receive()
        if payload.get("type") == "http.request":
            await send(
                {
                    "type": "http.response.start",
                    "status": int(status.split(' ')[0]),
                    "headers": [
                        tuple(x.encode('utf8') for x in header)
                    ]
                }
            )
            await send({"type": "http.response.body", "body": output})

    return prometheus_app