|
|
@ -9,7 +9,7 @@ |
|
|
|
|
|
|
|
from typing import Callable |
|
|
|
|
|
|
|
from prometheus_client import Counter, Histogram |
|
|
|
from prometheus_client import Counter, Histogram, Summary |
|
|
|
|
|
|
|
|
|
|
|
_COUNTERS = { |
|
|
@ -50,6 +50,13 @@ _HISTOGRAMS = { |
|
|
|
), |
|
|
|
} |
|
|
|
|
|
|
|
_SUMMARIES = { |
|
|
|
"breached_password_check": Summary( |
|
|
|
"tildes_breached_password_check_seconds", |
|
|
|
"Time spent checking whether a password is in the breached list", |
|
|
|
), |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def incr_counter(name: str, amount: int = 1, **labels: str) -> None: |
|
|
|
"""Increment a Prometheus counter.""" |
|
|
@ -80,3 +87,21 @@ def get_histogram(name: str, **labels: str) -> Histogram: |
|
|
|
def histogram_timer(name: str) -> Callable: |
|
|
|
"""Return the .time() decorator for a Prometheus histogram.""" |
|
|
|
return get_histogram(name).time() |
|
|
|
|
|
|
|
|
|
|
|
def get_summary(name: str, **labels: str) -> Summary: |
|
|
|
"""Return an (optionally labeled) Prometheus summary by name.""" |
|
|
|
try: |
|
|
|
hist = _SUMMARIES[name] |
|
|
|
except KeyError: |
|
|
|
raise ValueError("Invalid summary name") |
|
|
|
|
|
|
|
if labels: |
|
|
|
hist = hist.labels(**labels) |
|
|
|
|
|
|
|
return hist |
|
|
|
|
|
|
|
|
|
|
|
def summary_timer(name: str) -> Callable: |
|
|
|
"""Return the .time() decorator for a Prometheus summary.""" |
|
|
|
return get_summary(name).time() |