Voice et bot modif
This commit is contained in:
parent
189d56026b
commit
7333a22bcd
10774 changed files with 634644 additions and 933308 deletions
|
|
@ -0,0 +1,5 @@
|
|||
from .exposition import PrometheusDjangoView
|
||||
|
||||
__all__ = [
|
||||
"PrometheusDjangoView",
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,43 @@
|
|||
import os
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.views import View
|
||||
|
||||
import prometheus_client
|
||||
from prometheus_client import multiprocess
|
||||
from prometheus_client.exposition import _bake_output
|
||||
|
||||
|
||||
class PrometheusDjangoView(View):
|
||||
multiprocess_mode: bool = "PROMETHEUS_MULTIPROC_DIR" in os.environ or "prometheus_multiproc_dir" in os.environ
|
||||
registry: prometheus_client.CollectorRegistry = None
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
if self.registry is None:
|
||||
if self.multiprocess_mode:
|
||||
self.registry = prometheus_client.CollectorRegistry()
|
||||
multiprocess.MultiProcessCollector(self.registry)
|
||||
else:
|
||||
self.registry = prometheus_client.REGISTRY
|
||||
accept_header = request.headers.get("Accept")
|
||||
accept_encoding_header = request.headers.get("Accept-Encoding")
|
||||
# Bake output
|
||||
status, headers, output = _bake_output(
|
||||
registry=self.registry,
|
||||
accept_header=accept_header,
|
||||
accept_encoding_header=accept_encoding_header,
|
||||
params=request.GET,
|
||||
disable_compression=False,
|
||||
)
|
||||
status = int(status.split(" ")[0])
|
||||
return HttpResponse(
|
||||
output,
|
||||
status=status,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
def options(self, request, *args, **kwargs):
|
||||
return HttpResponse(
|
||||
status=200,
|
||||
headers={"Allow": "OPTIONS,GET"},
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue