跳到主要内容

静态配置

默认情况下,prometheus 配置已在默认配置中预先配置。

需要更新的文件取决于网关部署方式:

对于宿主机或 Docker 部署,配置以下设置:

config.yaml
plugin_attr:
prometheus: # Plugin: prometheus attributes
export_uri: /apisix/prometheus/metrics # Set the URI for the Prometheus metrics endpoint.
metric_prefix: apisix_ # Set the prefix for Prometheus metrics generated by APISIX.
enable_export_server: true # Enable the Prometheus export server.
export_addr: # Set the address for the Prometheus export server.
ip: 127.0.0.1 # Set the IP.
port: 9091 # Set the port.
refresh_interval: 15 # Only available in APISIX.
# Set the interval for refreshing cached metric data, in seconds.
fetch_metric_timeout: 5 # Only available in API7 Enterprise.
# Timeout for fetching metrics in seconds. If exceeded, the API only returns
# basic metrics, including nginx_http_current_connections, http_requests_total,
# etcd_reachable, prometheus_disable, node_info, etcd_modify_indexes,
# shared_dict_capacity_bytes, and shared_dict_free_space_bytes.
allow_degradation: false # Only available in API7 Enterprise.
# If true, allow degradation when shared memory is insufficient.
degradation_pause_steps: [ 60 ] # Only available in API7 Enterprise.
# Time to skip the execution of the plugin in seconds when the plugin is in
# degradation while reclaiming the shared memory used by the plugin.
# metrics: # Create extra labels for metrics.
# http_status: # These metrics will be prefixed with `apisix_`.
# extra_labels: # Set the extra labels for http_status metrics.
# - upstream_addr: $upstream_addr
# - 100
# - 1000
# - 10000
# llm_completion_tokens_buckets: # 自 API7 Enterprise 3.9.14 版本起可用。
# # 设置 `apisix_llm_completion_tokens_dist` 直方图的 buckets,单位为 token。
# - 100
# - 1000
# - 10000

然后重新加载网关以使更改生效。

你可以使用内置变量创建 extra_labels。更多详情,请参阅添加额外标签

参数

请参阅 插件通用配置 了解所有插件可用的配置选项。

  • prefer_name

    boolean


    default: false


    如果为 true,则在 Prometheus 指标中导出路由/服务名称而不是其 ID。

插件元数据

以下插件元数据仅在 API7 企业版中可用。

插件元数据通过 Admin API 或声明式配置进行配置,与渲染到 config.yaml 的 Helm values 中的 plugin_attr 相互独立。

  • disabled_labels

    object


    应禁用的标签,以减少指标数量并防止资源瓶颈。

    • status

      array[string]


      vaild vaule:

      Any combination of code, route, route_id, matched_uri, matched_host, service, service_id, consumer, node, request_type, request_llm_model, llm_model, mcp_request_type, and mcp_tool_name


      要为 apisix_http_status 指标禁用的标签。

      自 API7 Enterprise 3.9.7 版本起,还支持禁用 request_typerequest_llm_modelllm_model 标签。

      自 API7 Enterprise 3.9.14 版本起,还支持禁用 mcp_request_typemcp_tool_name 标签。

    • latency

      array[string]


      vaild vaule:

      Any combination of type, route, route_id, service, service_id, consumer, node, request_type, request_llm_model, llm_model, mcp_request_type, and mcp_tool_name


      要为 apisix_http_latency 指标禁用的标签。

      自 API7 Enterprise 3.9.7 版本起,还支持禁用 request_typerequest_llm_modelllm_model 标签。

      自 API7 Enterprise 3.9.14 版本起,还支持禁用 mcp_request_typemcp_tool_name 标签。

    • bandwidth

      array[string]


      vaild vaule:

      Any combination of type, route, route_id, service, service_id, consumer, node, request_type, request_llm_model, llm_model, mcp_request_type, and mcp_tool_name


      要为 apisix_bandwidth 指标禁用的标签。

      自 API7 Enterprise 3.9.7 版本起,还支持禁用 request_typerequest_llm_modelllm_model 标签。

      自 API7 Enterprise 3.9.14 版本起,还支持禁用 mcp_request_typemcp_tool_name 标签。

    • llm_latency

      array[string]


      vaild vaule:

      Any combination of type, route, route_id, service, service_id, consumer, node, request_type, request_llm_model, and llm_model


      要为 apisix_llm_latency 指标禁用的标签。

      自 API7 Enterprise 3.9.7 版本起可用。

      自 API7 Enterprise 3.9.14 版本起,还支持禁用 type 标签。

    • llm_prompt_tokens

      array[string]


      vaild vaule:

      Any combination of route, route_id, matched_uri, matched_host, service, service_id, consumer, node, request_type, request_llm_model, and llm_model


      要为 apisix_llm_prompt_tokens 指标禁用的标签。

      自 API7 Enterprise 3.9.7 版本起可用。

    • llm_completion_tokens

      array[string]


      vaild vaule:

      Any combination of route, route_id, matched_uri, matched_host, service, service_id, consumer, node, request_type, request_llm_model, and llm_model


      要为 apisix_llm_completion_tokens 指标禁用的标签。

      自 API7 Enterprise 3.9.7 版本起可用。

    • llm_active_connections

      array[string]


      vaild vaule:

      Any combination of route, route_id, matched_uri, matched_host, service, service_id, consumer, node, request_type, request_llm_model, and llm_model


      要为 apisix_llm_active_connections 指标禁用的标签。

      自 API7 Enterprise 3.9.7 版本起可用。

    • llm_prompt_tokens_dist

      array[string]


      vaild vaule:

      Any combination of route, route_id, matched_uri, matched_host, service, service_id, consumer, node, request_type, request_llm_model, and llm_model


      要为 apisix_llm_prompt_tokens_dist 指标禁用的标签。

      自 API7 Enterprise 3.9.14 版本起可用。

    • llm_completion_tokens_dist

      array[string]


      vaild vaule:

      Any combination of route, route_id, matched_uri, matched_host, service, service_id, consumer, node, request_type, request_llm_model, and llm_model


      要为 apisix_llm_completion_tokens_dist 指标禁用的标签。

      自 API7 Enterprise 3.9.14 版本起可用。