Skip to content

Commit

Permalink
implement basic prometheus metric endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rplevka committed Nov 21, 2024
1 parent 2995639 commit 8a41a08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit 8a41a08

Please sign in to comment.