File: using_prometheus_exporter.py

package info (click to toggle)
litestar 2.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,568 kB
  • sloc: python: 70,588; makefile: 254; javascript: 104; sh: 60
file content (13 lines) | stat: -rw-r--r-- 676 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
from litestar import Litestar
from litestar.plugins.prometheus import PrometheusConfig, PrometheusController


def create_app(group_path: bool = False):
    # Default app name and prefix is litestar.
    prometheus_config = PrometheusConfig(group_path=group_path)

    # By default the metrics are available in prometheus format and the path is set to '/metrics'.
    # If you want to change the path and format you can do it by subclassing the PrometheusController class.

    # Creating the litestar app instance with our custom PrometheusConfig and PrometheusController.
    return Litestar(route_handlers=[PrometheusController], middleware=[prometheus_config.middleware])