-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: extract module with builtin metrics
- Loading branch information
1 parent
6003044
commit 726fefb
Showing
4 changed files
with
86 additions
and
74 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
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from prometheus_aioexporter import MetricConfig | ||
|
||
# metric for counting database errors | ||
DB_ERRORS_METRIC_NAME = "database_errors" | ||
_DB_ERRORS_METRIC_CONFIG = MetricConfig( | ||
name=DB_ERRORS_METRIC_NAME, | ||
description="Number of database errors", | ||
type="counter", | ||
config={"increment": True}, | ||
) | ||
|
||
# metric for counting performed queries | ||
QUERIES_METRIC_NAME = "queries" | ||
_QUERIES_METRIC_CONFIG = MetricConfig( | ||
name=QUERIES_METRIC_NAME, | ||
description="Number of database queries", | ||
type="counter", | ||
labels=("query", "status"), | ||
config={"increment": True}, | ||
) | ||
# metric for tracking last query execution timestamp | ||
QUERY_TIMESTAMP_METRIC_NAME = "query_timestamp" | ||
_QUERY_TIMESTAMP_METRIC_CONFIG = MetricConfig( | ||
name=QUERY_TIMESTAMP_METRIC_NAME, | ||
description="Query last execution timestamp", | ||
type="gauge", | ||
labels=("query",), | ||
) | ||
# metric for counting queries execution latency | ||
QUERY_LATENCY_METRIC_NAME = "query_latency" | ||
_QUERY_LATENCY_METRIC_CONFIG = MetricConfig( | ||
name=QUERY_LATENCY_METRIC_NAME, | ||
description="Query execution latency", | ||
type="histogram", | ||
labels=("query",), | ||
) | ||
BUILTIN_METRICS = frozenset( | ||
( | ||
DB_ERRORS_METRIC_NAME, | ||
QUERIES_METRIC_NAME, | ||
QUERY_LATENCY_METRIC_NAME, | ||
QUERY_TIMESTAMP_METRIC_NAME, | ||
) | ||
) | ||
|
||
|
||
def get_builtin_metric_configs( | ||
extra_labels: frozenset[str], | ||
) -> dict[str, MetricConfig]: | ||
"""Return configuration for builtin metrics.""" | ||
return { | ||
metric_config.name: MetricConfig( | ||
metric_config.name, | ||
metric_config.description, | ||
metric_config.type, | ||
labels=set(metric_config.labels) | extra_labels, | ||
config=metric_config.config, | ||
) | ||
for metric_config in ( | ||
_DB_ERRORS_METRIC_CONFIG, | ||
_QUERIES_METRIC_CONFIG, | ||
_QUERY_LATENCY_METRIC_CONFIG, | ||
_QUERY_TIMESTAMP_METRIC_CONFIG, | ||
) | ||
} |
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