From f0cd88f3fc35175294ffdb45bfa3bfff1de5137e Mon Sep 17 00:00:00 2001 From: s3lph Date: Tue, 3 Mar 2020 22:10:41 +0100 Subject: [PATCH 1/2] Add Prometheus-style metrics --- matemat/webserver/pagelets/__init__.py | 1 + matemat/webserver/pagelets/metrics.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 matemat/webserver/pagelets/metrics.py diff --git a/matemat/webserver/pagelets/__init__.py b/matemat/webserver/pagelets/__init__.py index 629cd5f..96b8234 100644 --- a/matemat/webserver/pagelets/__init__.py +++ b/matemat/webserver/pagelets/__init__.py @@ -11,6 +11,7 @@ from .touchkey import touchkey_page from .buy import buy from .deposit import deposit from .admin import admin +from .metrics import metrics from .moduser import moduser from .modproduct import modproduct from .userbootstrap import userbootstrap diff --git a/matemat/webserver/pagelets/metrics.py b/matemat/webserver/pagelets/metrics.py new file mode 100644 index 0000000..62206ed --- /dev/null +++ b/matemat/webserver/pagelets/metrics.py @@ -0,0 +1,23 @@ +from bottle import abort, response, route + +from matemat.db import MatematDatabase +from matemat.webserver.config import get_app_config + + +@route('/metrics') +def metrics(): + config = get_app_config() + if config.get('MetricsEnabled', '0') != '1': + return abort(403, + 'Prometheus metrics are disable in configuration. ' + 'If you believe this is an error, contact your administrator.') + with MatematDatabase(config['DatabaseFile']) as db: + products = db.list_products() + m = '''# TYPE matemat_beverage_supply_count gauge +# HELP matemat_beverage_supply_count Number of bottles available +''' + for product in products: + name = product.name.replace('"', '\\"') + m += f'matemat_beverage_supply_count{{product="{name}"}} {product.stock}\n' + response.headers['Content-Type'] = 'text/plain' + return m From 669be9c9e4ae5a6a1cb8c836d003ff0c052350b3 Mon Sep 17 00:00:00 2001 From: s3lph Date: Tue, 3 Mar 2020 22:15:43 +0100 Subject: [PATCH 2/2] Prepare release v0.2.4 --- CHANGELOG.md | 13 +++++++++++++ matemat/__init__.py | 2 +- package/archlinux/PKGBUILD | 2 +- package/debian/matemat/DEBIAN/control | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3569157..ecf0cf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Matemat Changelog + +## Version 0.2.4 + +Feature release + +### Changes + + +- Feature: Quick-and-dirty Prometheus metrics exporter + + + + ## Version 0.2.3 diff --git a/matemat/__init__.py b/matemat/__init__.py index 12dad7e..5e42c43 100644 --- a/matemat/__init__.py +++ b/matemat/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.2.3' +__version__ = '0.2.4' diff --git a/package/archlinux/PKGBUILD b/package/archlinux/PKGBUILD index 68994c7..e41b2e1 100644 --- a/package/archlinux/PKGBUILD +++ b/package/archlinux/PKGBUILD @@ -2,7 +2,7 @@ # Maintainer: s3lph pkgname=matemat -pkgver=0.2.3 +pkgver=0.2.4 pkgrel=1 arch=('any') diff --git a/package/debian/matemat/DEBIAN/control b/package/debian/matemat/DEBIAN/control index ad4b86d..43e9faa 100644 --- a/package/debian/matemat/DEBIAN/control +++ b/package/debian/matemat/DEBIAN/control @@ -1,5 +1,5 @@ Package: matemat -Version: 0.2.3 +Version: 0.2.4 Maintainer: s3lph Section: web Priority: optional