Use Gauge instead of Counter for connections_active Prometheus metric
This commit is contained in:
parent
213b8c8267
commit
13d0f0ddab
2 changed files with 13 additions and 15 deletions
|
@ -89,7 +89,7 @@ func NewNGINXStatus(podName, namespace, ingressClass string) (NGINXStatusCollect
|
|||
p.data = &nginxStatusData{
|
||||
connectionsTotal: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(PrometheusNamespace, subSystem, "connections_total"),
|
||||
"total number of connections with state {active, accepted, handled}",
|
||||
"total number of connections with state {accepted, handled}",
|
||||
[]string{"state"}, constLabels),
|
||||
|
||||
requestsTotal: prometheus.NewDesc(
|
||||
|
@ -99,7 +99,7 @@ func NewNGINXStatus(podName, namespace, ingressClass string) (NGINXStatusCollect
|
|||
|
||||
connections: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(PrometheusNamespace, subSystem, "connections"),
|
||||
"current number of client connections with state {reading, writing, waiting}",
|
||||
"current number of client connections with state {active, reading, writing, waiting}",
|
||||
[]string{"state"}, constLabels),
|
||||
}
|
||||
|
||||
|
@ -180,14 +180,14 @@ func (p nginxStatusCollector) scrape(ch chan<- prometheus.Metric) {
|
|||
|
||||
s := parse(string(data))
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(p.data.connectionsTotal,
|
||||
prometheus.CounterValue, float64(s.Active), "active")
|
||||
ch <- prometheus.MustNewConstMetric(p.data.connectionsTotal,
|
||||
prometheus.CounterValue, float64(s.Accepted), "accepted")
|
||||
ch <- prometheus.MustNewConstMetric(p.data.connectionsTotal,
|
||||
prometheus.CounterValue, float64(s.Handled), "handled")
|
||||
ch <- prometheus.MustNewConstMetric(p.data.requestsTotal,
|
||||
prometheus.CounterValue, float64(s.Requests))
|
||||
ch <- prometheus.MustNewConstMetric(p.data.connections,
|
||||
prometheus.GaugeValue, float64(s.Active), "active")
|
||||
ch <- prometheus.MustNewConstMetric(p.data.connections,
|
||||
prometheus.GaugeValue, float64(s.Reading), "reading")
|
||||
ch <- prometheus.MustNewConstMetric(p.data.connections,
|
||||
|
|
|
@ -41,10 +41,9 @@ func TestStatusCollector(t *testing.T) {
|
|||
mock: `
|
||||
`,
|
||||
want: `
|
||||
# HELP nginx_ingress_controller_nginx_process_connections_total total number of connections with state {active, accepted, handled}
|
||||
# HELP nginx_ingress_controller_nginx_process_connections_total total number of connections with state {accepted, handled}
|
||||
# TYPE nginx_ingress_controller_nginx_process_connections_total counter
|
||||
nginx_ingress_controller_nginx_process_connections_total{controller_class="nginx",controller_namespace="default",controller_pod="pod",state="accepted"} 0
|
||||
nginx_ingress_controller_nginx_process_connections_total{controller_class="nginx",controller_namespace="default",controller_pod="pod",state="active"} 0
|
||||
nginx_ingress_controller_nginx_process_connections_total{controller_class="nginx",controller_namespace="default",controller_pod="pod",state="handled"} 0
|
||||
`,
|
||||
metrics: []string{"nginx_ingress_controller_nginx_process_connections_total"},
|
||||
|
@ -52,16 +51,15 @@ func TestStatusCollector(t *testing.T) {
|
|||
{
|
||||
name: "should return metrics for total connections",
|
||||
mock: `
|
||||
Active connections: 1
|
||||
Active connections: 15
|
||||
server accepts handled requests
|
||||
1 2 3
|
||||
1 2 3
|
||||
Reading: 4 Writing: 5 Waiting: 6
|
||||
`,
|
||||
want: `
|
||||
# HELP nginx_ingress_controller_nginx_process_connections_total total number of connections with state {active, accepted, handled}
|
||||
# HELP nginx_ingress_controller_nginx_process_connections_total total number of connections with state {accepted, handled}
|
||||
# TYPE nginx_ingress_controller_nginx_process_connections_total counter
|
||||
nginx_ingress_controller_nginx_process_connections_total{controller_class="nginx",controller_namespace="default",controller_pod="pod",state="accepted"} 1
|
||||
nginx_ingress_controller_nginx_process_connections_total{controller_class="nginx",controller_namespace="default",controller_pod="pod",state="active"} 1
|
||||
nginx_ingress_controller_nginx_process_connections_total{controller_class="nginx",controller_namespace="default",controller_pod="pod",state="handled"} 2
|
||||
`,
|
||||
metrics: []string{"nginx_ingress_controller_nginx_process_connections_total"},
|
||||
|
@ -69,21 +67,21 @@ func TestStatusCollector(t *testing.T) {
|
|||
{
|
||||
name: "should return nginx metrics all available metrics",
|
||||
mock: `
|
||||
Active connections: 1
|
||||
Active connections: 15
|
||||
server accepts handled requests
|
||||
1 2 3
|
||||
1 2 3
|
||||
Reading: 4 Writing: 5 Waiting: 6
|
||||
`,
|
||||
want: `
|
||||
# HELP nginx_ingress_controller_nginx_process_connections current number of client connections with state {reading, writing, waiting}
|
||||
# HELP nginx_ingress_controller_nginx_process_connections current number of client connections with state {active, reading, writing, waiting}
|
||||
# TYPE nginx_ingress_controller_nginx_process_connections gauge
|
||||
nginx_ingress_controller_nginx_process_connections{controller_class="nginx",controller_namespace="default",controller_pod="pod",state="active"} 15
|
||||
nginx_ingress_controller_nginx_process_connections{controller_class="nginx",controller_namespace="default",controller_pod="pod",state="reading"} 4
|
||||
nginx_ingress_controller_nginx_process_connections{controller_class="nginx",controller_namespace="default",controller_pod="pod",state="waiting"} 6
|
||||
nginx_ingress_controller_nginx_process_connections{controller_class="nginx",controller_namespace="default",controller_pod="pod",state="writing"} 5
|
||||
# HELP nginx_ingress_controller_nginx_process_connections_total total number of connections with state {active, accepted, handled}
|
||||
# HELP nginx_ingress_controller_nginx_process_connections_total total number of connections with state {accepted, handled}
|
||||
# TYPE nginx_ingress_controller_nginx_process_connections_total counter
|
||||
nginx_ingress_controller_nginx_process_connections_total{controller_class="nginx",controller_namespace="default",controller_pod="pod",state="accepted"} 1
|
||||
nginx_ingress_controller_nginx_process_connections_total{controller_class="nginx",controller_namespace="default",controller_pod="pod",state="active"} 1
|
||||
nginx_ingress_controller_nginx_process_connections_total{controller_class="nginx",controller_namespace="default",controller_pod="pod",state="handled"} 2
|
||||
# HELP nginx_ingress_controller_nginx_process_requests_total total number of client requests
|
||||
# TYPE nginx_ingress_controller_nginx_process_requests_total counter
|
||||
|
|
Loading…
Reference in a new issue