# Monitoring NGINX Ingress Controller > 原文:[https://docs.gitlab.com/ee/user/project/integrations/prometheus_library/nginx_ingress.html](https://docs.gitlab.com/ee/user/project/integrations/prometheus_library/nginx_ingress.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[](#monitoring-nginx-ingress-controller "Permalink") 在 GitLab 11.7 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/22133) . **注意:** 0.16.0 之前的 NGINX Ingress 版本提供了一个随附的[VTS Prometheus 指标导出器](nginx_ingress_vts.html) ,该导出器导出的指标与内置指标不同. GitLab 支持自动检测和监视 Kubernetes NGINX Ingress 控制器. 这是通过利用 Kubernetes NGINX Ingress 控制器[版本 0.16.0](https://github.com/kubernetes/ingress-nginx/blob/master/Changelog.md#0160)及更高[版本随附](https://github.com/kubernetes/ingress-nginx/blob/master/Changelog.md#0160)的内置 Prometheus 指标来提供的. ## Requirements[](#requirements "Permalink") [Prometheus integration](../prometheus.html) must be active. ## Metrics supported[](#metrics-supported "Permalink") | Name | Query | | --- | --- | | 吞吐量(要求/秒) | `sum(label_replace(rate(nginx_ingress_controller_requests{namespace="%{kube_namespace}",ingress=~".*%{ci_environment_slug}.*"}[2m]), "status_code", "${1}xx", "status", "(.)..")) by (status_code)` | | 延迟(毫秒) | `sum(rate(nginx_ingress_controller_ingress_upstream_latency_seconds_sum{namespace="%{kube_namespace}",ingress=~".*%{ci_environment_slug}.*"}[2m])) / sum(rate(nginx_ingress_controller_ingress_upstream_latency_seconds_count{namespace="%{kube_namespace}",ingress=~".*%{ci_environment_slug}.*"}[2m])) * 1000` | | HTTP 错误率(%) | `sum(rate(nginx_ingress_controller_requests{status=~"5.*",namespace="%{kube_namespace}",ingress=~".*%{ci_environment_slug}.*"}[2m])) / sum(rate(nginx_ingress_controller_requests{namespace="%{kube_namespace}",ingress=~".*%{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.16.0 或更高,并启用指标. * NGINX Ingress 应该标注为 Prometheus 监视. * Prometheus 应该配置为监视带注释的容器. ### About managed NGINX Ingress deployments[](#about-managed-nginx-ingress-deployments "Permalink") 使用[官方 Helm 图表将](https://github.com/helm/charts/tree/master/stable/nginx-ingress) NGINX Ingress 部署到`gitlab-managed-apps`命名空间中. NGINX Ingress 将[通过 Load Balancer 的 Endpoint](../../../clusters/applications.html#ingress)在[外部访问](../../../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 YML. ## Specifying the Environment label[](#specifying-the-environment-label "Permalink") 为了隔离并仅显示给定环境的相关指标,GitLab 需要一种方法来检测关联了哪些标签. 为此,GitLab 将搜索带有适当标签的指标. 在这种情况下, `ingress`标签必须为`` . 如果您使用[自动部署](../../../../topics/autodevops/stages.html#auto-deploy)来部署您的应用程序,则将自动使用此格式,并且无需您执行任何操作即可检测到指标.