~homeworkprod/byceps

ref: d216b81aa0b76a6874eaa35c4a5c6595a7351075 byceps/byceps/metrics/application.py -rw-r--r-- 1010 bytes
d216b81a — Jochen Kupperschmidt Inline `byceps.util.system.get_env_value` into sole callsite 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
byceps.metrics.application
~~~~~~~~~~~~~~~~~~~~~~~~~~

This allows to provide the metrics in a separate application. This might
be desired for performance and/or security reasons.

Run like this (inside a virtual environment)::

    $ DATABASE_URI=your-database-uri-here FLASK_APP=app_metrics flask run --port 8090

Metrics then become available at `http://127.0.0.1/metrics`.

:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from flask import Flask

from ..database import db
from ..util.framework.blueprint import register_blueprint


def create_app(database_uri):
    """Create the actual Flask application."""
    app = Flask(__name__)

    app.config['SQLALCHEMY_DATABASE_URI'] = database_uri

    # Disable Flask-SQLAlchemy's tracking of object modifications.
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    # Initialize database.
    db.init_app(app)

    register_blueprint(app, 'monitoring.metrics', '/metrics')

    return app