diff --git a/controllers/nginx/pkg/metric/collector/status.go b/controllers/nginx/pkg/metric/collector/status.go index e68e08b5d..4d66f7eb5 100644 --- a/controllers/nginx/pkg/metric/collector/status.go +++ b/controllers/nginx/pkg/metric/collector/status.go @@ -81,6 +81,7 @@ type filterZone struct { InBytes float64 `json:"inBytes"` OutBytes float64 `json:"outBytes"` Cache cache `json:"cache"` + RequestMsec float64 `json:"requestMsec"` Responses response `json:"responses"` } diff --git a/controllers/nginx/pkg/metric/collector/vts.go b/controllers/nginx/pkg/metric/collector/vts.go index 33eeac492..632083eab 100644 --- a/controllers/nginx/pkg/metric/collector/vts.go +++ b/controllers/nginx/pkg/metric/collector/vts.go @@ -37,23 +37,24 @@ type ( } vtsData struct { - bytes *prometheus.Desc - cache *prometheus.Desc - connections *prometheus.Desc - responses *prometheus.Desc - requests *prometheus.Desc - filterZoneBytes *prometheus.Desc - filterZoneResponses *prometheus.Desc - filterZoneCache *prometheus.Desc - upstreamBackup *prometheus.Desc - upstreamBytes *prometheus.Desc - upstreamDown *prometheus.Desc - upstreamFailTimeout *prometheus.Desc - upstreamMaxFails *prometheus.Desc - upstreamResponses *prometheus.Desc - upstreamRequests *prometheus.Desc - upstreamResponseMsec *prometheus.Desc - upstreamWeight *prometheus.Desc + bytes *prometheus.Desc + cache *prometheus.Desc + connections *prometheus.Desc + responses *prometheus.Desc + requests *prometheus.Desc + filterZoneBytes *prometheus.Desc + filterZoneResponses *prometheus.Desc + filterZoneRequestMsec *prometheus.Desc + filterZoneCache *prometheus.Desc + upstreamBackup *prometheus.Desc + upstreamBytes *prometheus.Desc + upstreamDown *prometheus.Desc + upstreamFailTimeout *prometheus.Desc + upstreamMaxFails *prometheus.Desc + upstreamResponses *prometheus.Desc + upstreamRequests *prometheus.Desc + upstreamResponseMsec *prometheus.Desc + upstreamWeight *prometheus.Desc } ) @@ -97,17 +98,22 @@ func NewNGINXVTSCollector(watchNamespace, ingressClass string, port int, path st filterZoneBytes: prometheus.NewDesc( prometheus.BuildFQName(ns, "", "filterzone_bytes_total"), "Nginx bytes count", - []string{"ingress_class", "namespace", "server_zone", "key", "direction"}, nil), + []string{"ingress_class", "namespace", "server_zone", "country", "filter_name", "filter_key", "direction"}, nil), filterZoneResponses: prometheus.NewDesc( prometheus.BuildFQName(ns, "", "filterzone_responses_total"), "The number of responses with status codes 1xx, 2xx, 3xx, 4xx, and 5xx.", - []string{"ingress_class", "namespace", "server_zone", "key", "status_code"}, nil), + []string{"ingress_class", "namespace", "server_zone", "country", "filter_name", "filter_key", "status_code"}, nil), + + filterZoneRequestMsec: prometheus.NewDesc( + prometheus.BuildFQName(ns, "", "filterzone_request_msecs_avg"), + "The average of only filter zone request processing times in milliseconds.", + []string{"ingress_class", "namespace", "server_zone", "country", "filter_name", "filter_key"}, nil), filterZoneCache: prometheus.NewDesc( prometheus.BuildFQName(ns, "", "filterzone_cache_total"), "Nginx cache count", - []string{"ingress_class", "namespace", "server_zone", "key", "type"}, nil), + []string{"ingress_class", "namespace", "server_zone", "country", "filter_name", "filter_key", "type"}, nil), upstreamBackup: prometheus.NewDesc( prometheus.BuildFQName(ns, "", "upstream_backup"), @@ -247,15 +253,17 @@ func (p vtsCollector) scrapeVts(ch chan<- prometheus.Metric) { prometheus.CounterValue, zone.OutBytes, p.ingressClass, p.watchNamespace, name, "out") } - for serverZone, keys := range nginxMetrics.FilterZones { - for name, zone := range keys { - reflectMetrics(&zone.Responses, p.data.filterZoneResponses, ch, p.ingressClass, p.watchNamespace, serverZone, name) - reflectMetrics(&zone.Cache, p.data.filterZoneCache, ch, p.ingressClass, p.watchNamespace, serverZone, name) + for filterName, filterKeys := range nginxMetrics.FilterZones { + for filterKey, zone := range filterKeys { + reflectMetrics(&zone.Responses, p.data.filterZoneResponses, ch, p.ingressClass, p.watchNamespace, filterName, filterKey, filterName, filterKey) + reflectMetrics(&zone.Cache, p.data.filterZoneCache, ch, p.ingressClass, p.watchNamespace, filterName, filterKey, filterName, filterKey) + ch <- prometheus.MustNewConstMetric(p.data.filterZoneRequestMsec, + prometheus.CounterValue, zone.RequestMsec, p.ingressClass, p.watchNamespace, filterName, filterKey, filterName, filterKey) ch <- prometheus.MustNewConstMetric(p.data.filterZoneBytes, - prometheus.CounterValue, zone.InBytes, p.ingressClass, p.watchNamespace, serverZone, name, "in") + prometheus.CounterValue, zone.InBytes, p.ingressClass, p.watchNamespace, filterName, filterKey, filterName, filterKey, "in") ch <- prometheus.MustNewConstMetric(p.data.filterZoneBytes, - prometheus.CounterValue, zone.OutBytes, p.ingressClass, p.watchNamespace, serverZone, name, "out") + prometheus.CounterValue, zone.OutBytes, p.ingressClass, p.watchNamespace, filterName, filterKey, filterName, filterKey, "out") } } } diff --git a/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl b/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl index f3ac79fb2..0475de3e7 100644 --- a/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl +++ b/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl @@ -783,6 +783,16 @@ stream { proxy_set_header Accept-Encoding ""; {{ end }} + {{ if $all.Cfg.EnableVtsStatus }} + {{ if $location.Service }} + vhost_traffic_status_filter_by_set_key {{ $location.Service.ObjectMeta.Namespace }} kubernetes::namespace; + vhost_traffic_status_filter_by_set_key {{ $location.Service.ObjectMeta.Namespace }}.{{ $location.Service.ObjectMeta.Name }} kubernetes::service; + {{ end }} + {{ if $location.Ingress }} + vhost_traffic_status_filter_by_set_key {{ $location.Ingress.ObjectMeta.Namespace }}.{{ $location.Ingress.ObjectMeta.Name }} kubernetes::ingress; + {{ end }} + {{ end }} + {{/* Add any additional configuration defined */}} {{ $location.ConfigurationSnippet }} diff --git a/core/pkg/ingress/controller/controller.go b/core/pkg/ingress/controller/controller.go index 84d9155be..7bd130c53 100644 --- a/core/pkg/ingress/controller/controller.go +++ b/core/pkg/ingress/controller/controller.go @@ -970,6 +970,7 @@ func (ic *GenericController) createServers(data []*extensions.Ingress, Backend: un, Proxy: ngxProxy, Service: &apiv1.Service{}, + Ingress: ing, }, }, SSLPassthrough: sslpt,