Skip to content

Мониторинг сервера

Сервер REST API предоставляет следующие эндпоинты с метриками, совместимыми с Prometheus:

  • GET /monitoring/metrics - метрики сервера, такие как количество запросов на каждый путь и статус ответа, использование CPU и RAM(оперативной памяти) и т. д.

Эти эндпоинты включаются и настраиваются с помощью следующих параметров:

Bases: BaseModel

Monitoring Settings.

See starlette-exporter <https://github.com/stephenhillier/starlette_exporter#options>_ documentation.

.. note::

You can pass here any extra option supported by ``starlette-exporter``,
even if it is not mentioned in documentation.

Examples

.. code-block:: yaml :caption: config.yml

server:
    monitoring:
        enabled: True
        labels:
            instance: "production"
        skip_paths:
            - "/some/path"
        skip_methods:
            - OPTIONS
        group_paths: True
        filter_unhandled_paths: True

        # custom option passed directly to starlette-exporter
Source code in syncmaster/server/settings/server/monitoring.py
 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class MonitoringSettings(BaseModel):
    """Monitoring Settings.

    See `starlette-exporter <https://github.com/stephenhillier/starlette_exporter#options>`_ documentation.

    .. note::

        You can pass here any extra option supported by ``starlette-exporter``,
        even if it is not mentioned in documentation.

    Examples
    --------

    .. code-block:: yaml
        :caption: config.yml

        server:
            monitoring:
                enabled: True
                labels:
                    instance: "production"
                skip_paths:
                    - "/some/path"
                skip_methods:
                    - OPTIONS
                group_paths: True
                filter_unhandled_paths: True

                # custom option passed directly to starlette-exporter
    """

    enabled: bool = Field(default=True, description="Set to ``True`` to enable middleware")
    labels: dict[str, str] = Field(
        default_factory=dict,
        description="""Custom labels added to all metrics, e.g. ``{"instance": "production"}``""",
    )
    skip_paths: set[str] = Field(
        default_factory=set,
        description="Custom paths should be skipped from metrics, like ``/some/endpoint``",
    )
    skip_methods: set[str] = Field(
        default={"OPTIONS"},
        description="HTTP methods which should be excluded from metrics",
    )
    # Starting from starlette-exporter 0.18, group_paths and filter_unhandled_paths are set to True by default:
    # https://github.com/stephenhillier/starlette_exporter/issues/79
    group_paths: bool = Field(
        default=True,
        description=textwrap.dedent(
            """
            If ``True`` (recommended), add request path to metrics literally as described
            in OpenAPI schema, e.g. ``v1//groups/{id}``, without substitution with path real values.

            If ``False``, all real request paths to metrics, e.g. ``v1//groups/123``.
            """,
        ),
    )
    filter_unhandled_paths: bool = Field(
        default=True,
        description=textwrap.dedent(
            """
            If ``True``, add metrics for paths only mentioned in OpenAPI schema.

            If ``False``, add all requested paths to metrics.
            """,
        ),
    )

    model_config = ConfigDict(extra="allow")