-
-
Notifications
You must be signed in to change notification settings - Fork 976
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add OpenMetrics renderer for metrics
This makes it compatible with Prometheus. Fixes #9285
- Loading branch information
Showing
5 changed files
with
42 additions
and
0 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,28 @@ | ||
# Copyright © Michal Čihař <michal@weblate.org> | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from rest_framework.renderers import BaseRenderer | ||
|
||
|
||
class OpenMetricsRenderer(BaseRenderer): | ||
media_type = "application/openmetrics-text" | ||
format = "openmetrics" | ||
charset = "utf-8" | ||
render_style = "text" | ||
|
||
def render(self, data, accepted_media_type=None, renderer_context=None): | ||
result = [] | ||
for key, value in data.items(): | ||
if isinstance(value, str): | ||
# Strings not supported | ||
continue | ||
if isinstance(value, int | float): | ||
result.append(f"{key} {value}") | ||
elif isinstance(value, dict): | ||
# Celery queues | ||
for queue, stat in value.items(): | ||
result.append(f'{key}(queue="{queue}") {stat}') | ||
|
||
result.append("# EOF") | ||
return "\n".join(result) |
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