mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat: Implement statistics class & additional metrics
The new module/class helps us constructing queries and count records to expose various statistics on the homepage. We also utilize for some new prometheus metrics (package and user gauges). Record counts are being cached with Redis. Signed-off-by: moson <moson@archlinux.org>
This commit is contained in:
parent
347c2ce721
commit
44c158b8c2
7 changed files with 143 additions and 89 deletions
|
@ -1,6 +1,6 @@
|
|||
from typing import Any, Callable, Optional
|
||||
|
||||
from prometheus_client import Counter
|
||||
from prometheus_client import Counter, Gauge
|
||||
from prometheus_fastapi_instrumentator import Instrumentator
|
||||
from prometheus_fastapi_instrumentator.metrics import Info
|
||||
from starlette.routing import Match, Route
|
||||
|
@ -11,10 +11,26 @@ logger = aur_logging.get_logger(__name__)
|
|||
_instrumentator = Instrumentator()
|
||||
|
||||
|
||||
# Custom metrics
|
||||
SEARCH_REQUESTS = Counter(
|
||||
"aur_search_requests", "Number of search requests by cache hit/miss", ["cache"]
|
||||
)
|
||||
USERS = Gauge(
|
||||
"aur_users", "Number of AUR users by type", ["type"], multiprocess_mode="livemax"
|
||||
)
|
||||
PACKAGES = Gauge(
|
||||
"aur_packages",
|
||||
"Number of AUR packages by state",
|
||||
["state"],
|
||||
multiprocess_mode="livemax",
|
||||
)
|
||||
|
||||
|
||||
def instrumentator():
|
||||
return _instrumentator
|
||||
|
||||
|
||||
# FastAPI metrics
|
||||
# Taken from https://github.com/stephenhillier/starlette_exporter
|
||||
# Their license is included in LICENSES/starlette_exporter.
|
||||
# The code has been modified to remove child route checks
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue