# Monitoring NGINX Ingress Controller with VTS metrics > 原文:[https://docs.gitlab.com/ee/user/project/integrations/prometheus_library/nginx_ingress_vts.html](https://docs.gitlab.com/ee/user/project/integrations/prometheus_library/nginx_ingress_vts.html) * [Requirements](#requirements) * [Metrics supported](#metrics-supported) * [Configuring NGINX Ingress monitoring](#configuring-nginx-ingress-monitoring) * [About managed NGINX Ingress deployments](#about-managed-nginx-ingress-deployments) * [Manually setting up NGINX Ingress for Prometheus monitoring](#manually-setting-up-nginx-ingress-for-prometheus-monitoring) * [Specifying the Environment label](#specifying-the-environment-label) # Monitoring NGINX Ingress Controller with VTS metrics[](#monitoring-nginx-ingress-controller-with-vts-metrics "Permalink") 在 GitLab 9.5 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/13438) . **注意:** [NGINX Ingress 版本 0.16](nginx_ingress.html)及更高[版本](nginx_ingress.html)具有内置的 Prometheus 度量标准,该度量标准与基于 VTS 的度量标准不同. GitLab 支持自动检测和监视 Kubernetes NGINX Ingress 控制器. 这是通过利用[版本 0.9.0](https://github.com/kubernetes/ingress-nginx/blob/master/Changelog.md#09-beta1)至[0.15.x 中](https://github.com/kubernetes/ingress-nginx/blob/master/Changelog.md#0150)随附的 VTS Prometheus 度量标准导出程序来[提供的](https://github.com/kubernetes/ingress-nginx/blob/master/Changelog.md#0150) . ## Requirements[](#requirements "Permalink") [Prometheus 集成](../prometheus.html)必须处于活动状态. ## Metrics supported[](#metrics-supported "Permalink") | Name | Query | | --- | --- | | 吞吐量(要求/秒) | `sum(rate(nginx_upstream_responses_total{upstream=~"%{kube_namespace}-%{ci_environment_slug}-.*"}[2m])) by (status_code)` | | 延迟(毫秒) | `avg(nginx_upstream_response_msecs_avg{upstream=~"%{kube_namespace}-%{ci_environment_slug}-.*"})` | | HTTP 错误率(%) | `sum(rate(nginx_upstream_responses_total{status_code="5xx", upstream=~"%{kube_namespace}-%{ci_environment_slug}-.*"}[2m])) / sum(rate(nginx_upstream_responses_total{upstream=~"%{kube_namespace}-%{ci_environment_slug}-.*"}[2m])) * 100` | ## Configuring NGINX Ingress monitoring[](#configuring-nginx-ingress-monitoring "Permalink") 如果您已经使用 GitLab 的[Kubernetes 集群集成](../../clusters/index.html#installing-applications)部署了 NGINX Ingress,则 Prometheus 将[自动对其进行监视](#about-managed-nginx-ingress-deployments) . 对于其他部署,需要根据您的安装进行[一些配置](#manually-setting-up-nginx-ingress-for-prometheus-monitoring) : * NGINX Ingress 的版本应为 0.9.0 或更高版本,并启用指标. * NGINX Ingress 应该标注为 Prometheus 监视. * Prometheus 应该配置为监视带注释的容器. ### About managed NGINX Ingress deployments[](#about-managed-nginx-ingress-deployments "Permalink") NGINX Ingress is deployed into the `gitlab-managed-apps` namespace, using the [official Helm chart](https://github.com/helm/charts/tree/master/stable/nginx-ingress). NGINX Ingress will be [externally reachable via the Load Balancer’s Endpoint](../../../clusters/applications.html#ingress). 通过设置以下内容,将 NGINX 配置为进行 Prometheus 监视: * `enable-vts-status: "true"` ,以导出 Prometheus 指标. * `prometheus.io/scrape: "true"` ,以启用自动发现. * `prometheus.io/port: "10254"` ,以指定度量标准端口. 与 GitLab 部署的 Prometheus 服务结合使用时,将自动收集响应指标. ### Manually setting up NGINX Ingress for Prometheus monitoring[](#manually-setting-up-nginx-ingress-for-prometheus-monitoring "Permalink") [NGINX Ingress 的](https://github.com/kubernetes/ingress-nginx) 0.9.0 及更高版本具有对导出 Prometheus 指标的内置支持. 要启用,必须传递 ConfigMap 设置: `enable-vts-status: "true"` . 启用后,Prometheus 指标端点将开始在端口 10254 上运行. 接下来,需要对 Ingress 进行注释,以进行 Prometheus 监视. 需要添加两个新的注释: * `prometheus.io/scrape: "true"` * `prometheus.io/port: "10254"` 管理这些设置取决于如何部署 NGINX Ingress. 如果您通过[官方 Helm 图表](https://github.com/helm/charts/tree/master/stable/nginx-ingress)进行了部署,则可以使用`controller.stats.enabled`以及所需的注释来启用指标. 或者,也可以直接在[Kubernetes 仪表板中](https://github.com/kubernetes/dashboard)编辑 NGINX Ingress YAML. ## Specifying the Environment label[](#specifying-the-environment-label "Permalink") 为了隔离并仅显示给定环境的相关指标,GitLab 需要一种方法来检测关联了哪些标签. 为此,GitLab 将搜索带有适当标签的指标. 在这种情况下, `upstream`标签的格式必须为`--*` . 如果您使用[自动部署](../../../../topics/autodevops/stages.html#auto-deploy)来部署您的应用程序,则将自动使用此格式,并且无需您执行任何操作即可检测到指标.