~roshless/nnrss

1d0c090620782aa50408b30d2701a44942800232 — Roshless 1 year, 14 days ago 08f72a4
feat: add prometheus metrics

works properly only on 1 worker for now
3 files changed, 15 insertions(+), 1 deletions(-)

M dist/config.ini
M nnrss/__init__.py
M nnrss/config.py
M dist/config.ini => dist/config.ini +1 -0
@@ 2,6 2,7 @@
api_enabled = False
interface_enabled = True 
registration_enabled = False
metrics_enabled = True

# example command for good secret key
# python -c "import os; print(os.urandom(24))"

M nnrss/__init__.py => nnrss/__init__.py +6 -0
@@ 16,6 16,12 @@ def create_app():
        app.register_blueprint(API, url_prefix="/api")
    if ACCOUNT.interface_enabled:
        app.register_blueprint(DEFAULT_WEB, url_prefix="/")
    if ACCOUNT.metrics_enabled:
        from prometheus_flask_exporter import NO_PREFIX
        from prometheus_flask_exporter.multiprocess import PrometheusMetrics

        metrics = PrometheusMetrics(app, defaults_prefix=NO_PREFIX)
        metrics.info("app_version", "Application version", version=__version__)

    app.secret_key = ACCOUNT.get_secret_key()


M nnrss/config.py => nnrss/config.py +8 -1
@@ 12,7 12,8 @@ class ConfigManager:
    api_enabled = False
    interface_enabled = True
    registration_enabled = False
    secret_key = urandom(24)
    metrics_enabled = True
    secret_key: bytes = urandom(24)

    backend = "postgresql"
    db_username = "username"


@@ 33,6 34,9 @@ class ConfigManager:
        self.registration_enabled = loaded_config.getboolean(
            self.section_access, "registration_enabled"
        )
        self.metrics_enabled = loaded_config.getboolean(
            self.section_access, "metrics_enabled"
        )

        self.secret_key = loaded_config[self.section_access]["secret_key"]



@@ 92,6 96,9 @@ class ConfigManager:
    def is_registration_enabled(self):
        return self.registration_enabled

    def is_metrics_enabled(self):
        return self.metrics_enabled

    def get_secret_key(self):
        return self.secret_key