-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
268 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,8 @@ jobs: | |
- py38 | ||
- py39 | ||
- py310 | ||
- py311 | ||
- py312 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
authors = ( | ||
("Vladislav Bakaev", "[email protected]"), | ||
("Dmitry Orlov", "[email protected]"), | ||
("Pavel Mosein", "[email protected]"), | ||
) | ||
|
||
authors_email = ", ".join(email for _, email in authors) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,73 @@ | ||
from dataclasses import dataclass | ||
import time | ||
from contextlib import contextmanager | ||
from dataclasses import dataclass, field | ||
from typing import Sequence | ||
|
||
|
||
@dataclass(frozen=True) | ||
class Metrics: | ||
class DriverMetrics: | ||
max: int | ||
min: int | ||
idle: int | ||
used: int | ||
host: str | ||
|
||
|
||
@dataclass(frozen=True) | ||
class HasqlMetrics: | ||
pool: int | ||
pool_time: float | ||
acquire: int | ||
acquire_time: float | ||
add_connections: dict[str, int] | ||
remove_connections: dict[str, int] | ||
|
||
|
||
@dataclass | ||
class CalculateMetrics: | ||
_pool: int = 0 | ||
_pool_time: int = 0 | ||
_acquire: int = 0 | ||
_acquire_time: int = 0 | ||
_add_connections: dict[str, int] = field(default_factory=dict) | ||
_remove_connections: dict[str, int] = field(default_factory=dict) | ||
|
||
def metrics(self) -> HasqlMetrics: | ||
return HasqlMetrics( | ||
pool=self._pool, | ||
pool_time=self._pool_time, | ||
acquire=self._acquire, | ||
acquire_time=self._acquire, | ||
add_connections=self._add_connections, | ||
remove_connections=self._remove_connections, | ||
) | ||
|
||
@contextmanager | ||
def with_get_pool(self): | ||
self._pool += 1 | ||
tt = time.monotonic() | ||
yield | ||
self._pool_time += time.monotonic() - tt | ||
|
||
@contextmanager | ||
def with_acquire(self): | ||
self._acquire += 1 | ||
tt = time.monotonic() | ||
yield | ||
self._acquire_time += time.monotonic() - tt | ||
|
||
def add_connection(self, dsn: str): | ||
self._add_connections[dsn] = ( | ||
self._add_connections.get(dsn, 0) + 1 | ||
) | ||
|
||
def remove_connection(self, dsn: str): | ||
self._remove_connections[dsn] = ( | ||
self._remove_connections.get(dsn, 0) + 1 | ||
) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class Metrics: | ||
drivers: Sequence[DriverMetrics] | ||
hasql: HasqlMetrics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.