File tree 2 files changed +14
-0
lines changed
2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 4
4
from flask_sqlalchemy import SQLAlchemy
5
5
from flask_migrate import Migrate
6
6
from flask_restx import Api , Resource , fields
7
+ from prometheus_flask_exporter import PrometheusMetrics
7
8
from sqlalchemy import text
8
9
from sqlalchemy .exc import IntegrityError , SQLAlchemyError
9
10
10
11
app = Flask ("__name__" )
12
+ metrics = PrometheusMetrics (app )
13
+
11
14
if settings .database .get ("connection_string" ) is None :
12
15
db_creds = f"{ settings .database .username } :{ settings .database .password } "
13
16
db_host = settings .database .host
@@ -362,5 +365,15 @@ def get(self):
362
365
return [container .to_dict () for container in containers ], 200
363
366
364
367
368
+ # register routes to the prometheus metrics
369
+ metrics .register_default (
370
+ metrics .counter (
371
+ "by_path_counter" ,
372
+ "Request count by request paths" ,
373
+ labels = {"path" : lambda : request .path },
374
+ )
375
+ )
376
+
377
+
365
378
if __name__ == "__main__" :
366
379
app .run (debug = True )
Original file line number Diff line number Diff line change 3
3
Flask-SQLAlchemy
4
4
Flask-Migrate
5
5
flask-restx
6
+ prometheus-flask-exporter
6
7
psycopg2-binary
7
8
requests
You can’t perform that action at this time.
0 commit comments