Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement basic prometheus metric endpoint #11

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions rekuper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_restx import Api, Resource, fields
from prometheus_flask_exporter import PrometheusMetrics
from sqlalchemy import text
from sqlalchemy.exc import IntegrityError, SQLAlchemyError

app = Flask("__name__")
metrics = PrometheusMetrics(app)

if settings.database.get("connection_string") is None:
db_creds = f"{settings.database.username}:{settings.database.password}"
db_host = settings.database.host
Expand Down Expand Up @@ -362,5 +365,15 @@ def get(self):
return [container.to_dict() for container in containers], 200


# register routes to the prometheus metrics
metrics.register_default(
metrics.counter(
"by_path_counter",
"Request count by request paths",
labels={"path": lambda: request.path},
)
)


if __name__ == "__main__":
app.run(debug=True)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ Flask
Flask-SQLAlchemy
Flask-Migrate
flask-restx
prometheus-flask-exporter
psycopg2-binary
requests