Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VS/VSR Prometheus metrics #724

Merged
merged 7 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/prometheus.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ The Ingress Controller exports the following metrics:
* `controller_nginx_reload_errors_total`. Number of unsuccessful NGINX reloads.
* `controller_nginx_last_reload_status`. Status of the last NGINX reload, 0 meaning down and 1 up.
* `controller_nginx_last_reload_milliseconds`. Duration in milliseconds of the last NGINX reload.
* `controller_ingress_resources_total`. Number of handled Ingress resources. This metric includes the label type, that groups the Ingress resources by their type (regular, [minion or master](./../examples/mergeable-ingress-types))
* `controller_ingress_resources_total`. Number of handled Ingress resources. This metric includes the label type, that groups the Ingress resources by their type (regular, [minion or master](./../examples/mergeable-ingress-types)). **Note**: The metric doesn't count minions without a master.
* `controller_virtualserver_resources_total`. Number of handled VirtualServer resources.
* `controller_virtualserverroute_resources_total`. Number of handled VirtualServerRoute resources. **Note**: Only counts VirtualServerRoutes that have a reference from a VirtualServer.
* `controller_virtualserverroute_resources_total`. Number of handled VirtualServerRoute resources. **Note**: The metric counts only VirtualServerRoutes that have a reference from a VirtualServer.

**Note**: all metrics have the namespace nginx_ingress. For example, nginx_ingress_controller_nginx_reloads_total.
4 changes: 2 additions & 2 deletions internal/configs/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,8 @@ func (cnf *Configurator) GetIngressCounts() map[string]int {
return counters
}

// GetVSCounts returns the total count of Vs/Vsr resources that are handled by the Ingress Controller
func (cnf *Configurator) GetVSCounts() (vsCount int, vsrCount int) {
// GetVirtualServerCounts returns the total count of VS/VSR resources that are handled by the Ingress Controller
func (cnf *Configurator) GetVirtualServerCounts() (vsCount int, vsrCount int) {
vsCount = len(cnf.virtualServers)
for _, vs := range cnf.virtualServers {
vsrCount += len(vs.VirtualServerRoutes)
Expand Down
14 changes: 7 additions & 7 deletions internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,10 @@ func (lbc *LoadBalancerController) sync(task task) {
lbc.syncExternalService(task)
case virtualserver:
lbc.syncVirtualServer(task)
lbc.updateVsMetrics()
lbc.updateVirtualServerMetrics()
case virtualServerRoute:
lbc.syncVirtualServerRoute(task)
lbc.updateVsMetrics()
lbc.updateVirtualServerMetrics()
}
}

Expand Down Expand Up @@ -849,14 +849,14 @@ func (lbc *LoadBalancerController) syncIng(task task) {
func (lbc *LoadBalancerController) updateIngressMetrics() {
counters := lbc.configurator.GetIngressCounts()
for nType, count := range counters {
lbc.metricsCollector.SetIngressResources(nType, count)
lbc.metricsCollector.SetIngress(nType, count)
}
}

func (lbc *LoadBalancerController) updateVsMetrics() {
vsCount, vsrCount := lbc.configurator.GetVSCounts()
lbc.metricsCollector.SetVsResources(vsCount)
lbc.metricsCollector.SetVsrResources(vsrCount)
func (lbc *LoadBalancerController) updateVirtualServerMetrics() {
vsCount, vsrCount := lbc.configurator.GetVirtualServerCounts()
lbc.metricsCollector.SetVirtualServer(vsCount)
lbc.metricsCollector.SetVirtualServerRoute(vsrCount)
}

// syncExternalService does not sync all services.
Expand Down
60 changes: 30 additions & 30 deletions internal/metrics/collectors/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ var labelNamesController = []string{"type"}

// ControllerCollector is an interface for the metrics of the Controller
type ControllerCollector interface {
SetIngressResources(ingressType string, count int)
SetVsResources(count int)
SetVsrResources(count int)
SetIngress(ingressType string, count int)
Dean-Coakley marked this conversation as resolved.
Show resolved Hide resolved
SetVirtualServer(count int)
SetVirtualServerRoute(count int)
Register(registry *prometheus.Registry) error
}

// ControllerMetricsCollector implements the ControllerCollector interface and prometheus.Collector interface
type ControllerMetricsCollector struct {
ingressResourcesTotal *prometheus.GaugeVec
vsResourcesTotal prometheus.Gauge
vsrResourcesTotal prometheus.Gauge
ingressesTotal *prometheus.GaugeVec
virtualServersTotal prometheus.Gauge
virtualServerRoutesTotal prometheus.Gauge
}

// NewControllerMetricsCollector creates a new ControllerMetricsCollector
Expand Down Expand Up @@ -47,39 +47,39 @@ func NewControllerMetricsCollector() *ControllerMetricsCollector {
)

return &ControllerMetricsCollector{
ingressResourcesTotal: ingResTotal,
vsResourcesTotal: vsResTotal,
vsrResourcesTotal: vsrResTotal,
ingressesTotal: ingResTotal,
virtualServersTotal: vsResTotal,
virtualServerRoutesTotal: vsrResTotal,
}
}

// SetIngressResources sets the value of the ingress resources gauge for a given type
func (cc *ControllerMetricsCollector) SetIngressResources(ingressType string, count int) {
cc.ingressResourcesTotal.WithLabelValues(ingressType).Set(float64(count))
// SetIngress sets the value of the ingress resources gauge for a given type
func (cc *ControllerMetricsCollector) SetIngress(ingressType string, count int) {
cc.ingressesTotal.WithLabelValues(ingressType).Set(float64(count))
}

// SetVsResources sets the value of the VS resources gauge
func (cc *ControllerMetricsCollector) SetVsResources(count int) {
cc.vsResourcesTotal.Set(float64(count))
// SetVirtualServer sets the value of the VirtualServer resources gauge
func (cc *ControllerMetricsCollector) SetVirtualServer(count int) {
cc.virtualServersTotal.Set(float64(count))
}

// SetVsrResources sets the value of the VSR resources gauge
func (cc *ControllerMetricsCollector) SetVsrResources(count int) {
cc.vsrResourcesTotal.Set(float64(count))
// SetVirtualServerRoute sets the value of the VirtualServerRoute resources gauge
func (cc *ControllerMetricsCollector) SetVirtualServerRoute(count int) {
cc.virtualServerRoutesTotal.Set(float64(count))
}

// Describe implements prometheus.Collector interface Describe method
func (cc *ControllerMetricsCollector) Describe(ch chan<- *prometheus.Desc) {
cc.ingressResourcesTotal.Describe(ch)
cc.vsResourcesTotal.Describe(ch)
cc.vsrResourcesTotal.Describe(ch)
cc.ingressesTotal.Describe(ch)
cc.virtualServersTotal.Describe(ch)
cc.virtualServerRoutesTotal.Describe(ch)
}

// Collect implements the prometheus.Collector interface Collect method
func (cc *ControllerMetricsCollector) Collect(ch chan<- prometheus.Metric) {
cc.ingressResourcesTotal.Collect(ch)
cc.vsResourcesTotal.Collect(ch)
cc.vsrResourcesTotal.Collect(ch)
cc.ingressesTotal.Collect(ch)
cc.virtualServersTotal.Collect(ch)
cc.virtualServerRoutesTotal.Collect(ch)
}

// Register registers all the metrics of the collector
Expand All @@ -98,11 +98,11 @@ func NewControllerFakeCollector() *ControllerFakeCollector {
// Register implements a fake Register
func (cc *ControllerFakeCollector) Register(registry *prometheus.Registry) error { return nil }

// SetIngressResources implements a fake SetIngressResources
func (cc *ControllerFakeCollector) SetIngressResources(ingressType string, count int) {}
// SetIngress implements a fake SetIngress
func (cc *ControllerFakeCollector) SetIngress(ingressType string, count int) {}

// SetVsResources implements a fake SetVsResources
func (cc *ControllerFakeCollector) SetVsResources(count int) {}
// SetVirtualServer implements a fake SetVirtualServer
func (cc *ControllerFakeCollector) SetVirtualServer(count int) {}

// SetVsrResources implements a fake SetVsrResources
func (cc *ControllerFakeCollector) SetVsrResources(count int) {}
// SetVirtualServerRoute implements a fake SetVirtualServerRoute
func (cc *ControllerFakeCollector) SetVirtualServerRoute(count int) {}