Aka (赤 - red in japanese) Stats.
Unified module for keeping stats in Redis.
The goal is to have an easy way to measure an application, and then expose these metrics through a HTTP API, either to process it in some web ui, or expose it to Prometheus.
from aka_stats import Stats, timer
with Stats() as stats:
t = timer()
...
stats("task_done", next(t).stat)
Or for asynchronouse code:
from aka_stats import Stats, timer
async def process_device(device_id: str):
async with Stats() as stat:
t = timer()
...
stats("task_done", next(t).stat, extra_labels={"device_id": device_id})
And add this package to your project:
poetry add aka-stats
Check out the usage guide here: Usage.md
Information how to write a formatter is here: PrometheusFormatter.md
Check out this guide here: Included HTTP API
This module is also a pytest plugin, providing a fixture mock_stats
which collects stats instead of writing them
to Redis.
def test_something(mock_stats):
do_something()
assert mock_stats[0] == (1612550961, "test", 1, None)
And the module with function:
def do_something():
with Stats() as stats:
stat("test", 1)