Skip to content

Commit

Permalink
Add prometheus /metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Ledez committed Oct 2, 2023
1 parent c717f13 commit 09942e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ install_requires =
OpenTimelineIO==0.15.0
orjson==3.9.7
pillow==10.0.1
prometheus-client==0.17.1
psutil==5.9.5
psycopg[binary]==3.1.12
pygelf==0.4.2
Expand Down
23 changes: 23 additions & 0 deletions zou/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import flask_fs
import traceback
import time
import threading

from flask import Flask, jsonify, current_app
from flasgger import Swagger
Expand All @@ -10,6 +12,9 @@
from flask_migrate import Migrate
from flask_mail import Mail

from werkzeug.middleware.dispatcher import DispatcherMiddleware
import prometheus_client

from jwt import ExpiredSignatureError
from babel.core import UnknownLocaleError
from meilisearch.errors import (
Expand Down Expand Up @@ -58,6 +63,21 @@
app, template=swagger.swagger_template, config=swagger.swagger_config
)

BACKGROUND_TASKS = prometheus_client.Counter(
"background_tasks_total", "Background tasks executed."
)


def background_task():
"""Background task to simulate and update metrics"""
while True:
time.sleep(5) # Run every 5 seconds
BACKGROUND_TASKS.inc() # Increment our counter


app.wsgi_app = DispatcherMiddleware(
app.wsgi_app, {"/metrics": prometheus_client.make_wsgi_app()}
)

if config.SENTRY_DEBUG_URL:

Expand Down Expand Up @@ -168,5 +188,8 @@ def load_api():
fs.mkdir_p(app.config["TMP_DIR"])
configure_auth()

t = threading.Thread(target=background_task)
t.start()


load_api()

0 comments on commit 09942e5

Please sign in to comment.