Skip to content

Commit 962ecaf

Browse files
committed
Add zone sync metrics
1 parent ab4e55f commit 962ecaf

File tree

8 files changed

+342
-34
lines changed

8 files changed

+342
-34
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Usage of ./nginx-prometheus-exporter:
9898
* [Stream Server Zones](http://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_stream_server_zone).
9999
* [HTTP Upstreams](http://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_http_upstream). Note: for the `state` metric, the string values are converted to float64 using the following rule: `"up"` -> `1.0`, `"draining"` -> `2.0`, `"down"` -> `3.0`, `"unavail"` –> `4.0`, `"checking"` –> `5.0`, `"unhealthy"` -> `6.0`.
100100
* [Stream Upstreams](http://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_stream_upstream). Note: for the `state` metric, the string values are converted to float64 using the following rule: `"up"` -> `1.0`, `"down"` -> `3.0`, `"unavail"` –> `4.0`, `"checking"` –> `5.0`, `"unhealthy"` -> `6.0`.
101+
* [Stream Zone Sync](http://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_stream_zone_sync).
101102
* `nginxplus_up` -- shows the status of the last metric scrape: `1` for a successful scrape and `0` for a failed one.
102103
103104

collector/nginx_plus.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"log"
55
"sync"
66

7-
plusclient "github.com/nginxinc/nginx-plus-go-sdk/client"
7+
plusclient "github.com/nginxinc/nginx-plus-go-client/client"
88
"github.com/prometheus/client_golang/prometheus"
99
)
1010

@@ -18,6 +18,7 @@ type NginxPlusCollector struct {
1818
streamServerZoneMetrics map[string]*prometheus.Desc
1919
streamUpstreamMetrics map[string]*prometheus.Desc
2020
streamUpstreamServerMetrics map[string]*prometheus.Desc
21+
streamZoneSyncMetrics map[string]*prometheus.Desc
2122
upMetric prometheus.Gauge
2223
mutex sync.Mutex
2324
}
@@ -100,6 +101,15 @@ func NewNginxPlusCollector(nginxClient *plusclient.NginxClient, namespace string
100101
"health_checks_fails": newStreamUpstreamServerMetric(namespace, "health_checks_fails", "Failed health checks"),
101102
"health_checks_unhealthy": newStreamUpstreamServerMetric(namespace, "health_checks_unhealthy", "How many times the server became unhealthy (state 'unhealthy')"),
102103
},
104+
streamZoneSyncMetrics: map[string]*prometheus.Desc{
105+
"bytes_in": newStreamZoneSyncMetric(namespace, "bytes_in", "Bytes received by this node"),
106+
"bytes_out": newStreamZoneSyncMetric(namespace, "bytes_out", "Bytes sent by this node"),
107+
"msgs_in": newStreamZoneSyncMetric(namespace, "msgs_in", "Total messages received by this node"),
108+
"msgs_out": newStreamZoneSyncMetric(namespace, "msgs_out", "Total messages sent by this node"),
109+
"nodes_online": newStreamZoneSyncMetric(namespace, "nodes_online", "Number of peers this node is conected to"),
110+
"records_pending": newStreamZoneSyncZoneMetric(namespace, "records_pending", "The number of records that need to be sent to the cluster"),
111+
"records_total": newStreamZoneSyncZoneMetric(namespace, "records_total", "The total number of records stored in the shared memory zone"),
112+
},
103113
upMetric: newUpMetric(namespace),
104114
}
105115
}
@@ -130,6 +140,9 @@ func (c *NginxPlusCollector) Describe(ch chan<- *prometheus.Desc) {
130140
for _, m := range c.streamUpstreamServerMetrics {
131141
ch <- m
132142
}
143+
for _, m := range c.streamZoneSyncMetrics {
144+
ch <- m
145+
}
133146
}
134147

135148
// Collect fetches metrics from NGINX Plus and sends them to the provided channel.
@@ -289,6 +302,24 @@ func (c *NginxPlusCollector) Collect(ch chan<- prometheus.Metric) {
289302
ch <- prometheus.MustNewConstMetric(c.streamUpstreamMetrics["zombies"],
290303
prometheus.GaugeValue, float64(upstream.Zombies), name)
291304
}
305+
306+
for name, zone := range stats.StreamZoneSync.Zones {
307+
ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["records_pending"],
308+
prometheus.GaugeValue, float64(zone.RecordsPending), name)
309+
ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["records_total"],
310+
prometheus.GaugeValue, float64(zone.RecordsTotal), name)
311+
}
312+
313+
ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["bytes_in"],
314+
prometheus.CounterValue, float64(stats.StreamZoneSync.Status.BytesIn))
315+
ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["bytes_out"],
316+
prometheus.CounterValue, float64(stats.StreamZoneSync.Status.BytesOut))
317+
ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["msgs_in"],
318+
prometheus.CounterValue, float64(stats.StreamZoneSync.Status.MsgsIn))
319+
ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["msgs_out"],
320+
prometheus.CounterValue, float64(stats.StreamZoneSync.Status.MsgsOut))
321+
ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["nodes_online"],
322+
prometheus.GaugeValue, float64(stats.StreamZoneSync.Status.NodesOnline))
292323
}
293324

294325
var upstreamServerStates = map[string]float64{
@@ -323,3 +354,11 @@ func newUpstreamServerMetric(namespace string, metricName string, docString stri
323354
func newStreamUpstreamServerMetric(namespace string, metricName string, docString string) *prometheus.Desc {
324355
return prometheus.NewDesc(prometheus.BuildFQName(namespace, "stream_upstream_server", metricName), docString, []string{"upstream", "server"}, nil)
325356
}
357+
358+
func newStreamZoneSyncMetric(namespace string, metricName string, docString string) *prometheus.Desc {
359+
return prometheus.NewDesc(prometheus.BuildFQName(namespace, "stream_zone_sync_status", metricName), docString, nil, nil)
360+
}
361+
362+
func newStreamZoneSyncZoneMetric(namespace string, metricName string, docString string) *prometheus.Desc {
363+
return prometheus.NewDesc(prometheus.BuildFQName(namespace, "stream_zone_sync_zone", metricName), docString, []string{"zone"}, nil)
364+
}

exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"syscall"
1313
"time"
1414

15-
plusclient "github.com/nginxinc/nginx-plus-go-sdk/client"
15+
plusclient "github.com/nginxinc/nginx-plus-go-client/client"
1616
"github.com/nginxinc/nginx-prometheus-exporter/client"
1717
"github.com/nginxinc/nginx-prometheus-exporter/collector"
1818
"github.com/prometheus/client_golang/prometheus"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ module github.com/nginxinc/nginx-prometheus-exporter
33
go 1.12
44

55
require (
6-
github.com/nginxinc/nginx-plus-go-sdk v0.0.0-20180910131828-47154e1ef115
6+
github.com/nginxinc/nginx-plus-go-client v0.0.0-20190529112308-8f20f677a8bf
77
github.com/prometheus/client_golang v0.9.2
88
)

go.sum

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM
44
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
55
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
66
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
7-
github.com/nginxinc/nginx-plus-go-sdk v0.0.0-20180910131828-47154e1ef115 h1:CWauBkD0d1oC7C4sZ+MeggmcYMVK0WHQZZFjsys0Cq0=
8-
github.com/nginxinc/nginx-plus-go-sdk v0.0.0-20180910131828-47154e1ef115/go.mod h1:QqHe+Px9tTm7GOQUBDQGDQHA9m/J+J3JjHbxgri5gSw=
7+
github.com/nginxinc/nginx-plus-go-client v0.0.0-20190326123225-e0cdc4be0c7f h1:3DdSFnaXSvhgn9RhiptJiudBHmFq+wDRccrJwhrwHlg=
8+
github.com/nginxinc/nginx-plus-go-client v0.0.0-20190522143815-28e3fc49525c h1:xyY2/MuxVbzzEXAJkaFWERM3RtCaz/IX/jBOJZkZVc4=
9+
github.com/nginxinc/nginx-plus-go-client v0.0.0-20190522143815-28e3fc49525c/go.mod h1:DBAmdDP71tOhgFPdCMVusegzdKmLVpVL0nVcMX17pbY=
10+
github.com/nginxinc/nginx-plus-go-client v0.0.0-20190524095408-9fb6bf19a64e h1:7DbTRinSESf1WTnnGxoD7o0bvnFHIxVINTaMNYVFiHo=
11+
github.com/nginxinc/nginx-plus-go-client v0.0.0-20190524144844-4d90184fc765 h1:SwxKOmnP+AELWdMDac0N7x7dN1vxoKjK5i2x2qYjOGQ=
12+
github.com/nginxinc/nginx-plus-go-client v0.0.0-20190524144844-4d90184fc765/go.mod h1:DBAmdDP71tOhgFPdCMVusegzdKmLVpVL0nVcMX17pbY=
13+
github.com/nginxinc/nginx-plus-go-client v0.0.0-20190529112308-8f20f677a8bf h1:QFUdFoJTsB60JpskBNicEQhu220DEL7UV8SJKUwdi3o=
14+
github.com/nginxinc/nginx-plus-go-client v0.0.0-20190529112308-8f20f677a8bf/go.mod h1:DBAmdDP71tOhgFPdCMVusegzdKmLVpVL0nVcMX17pbY=
915
github.com/prometheus/client_golang v0.9.2 h1:awm861/B8OKDd2I/6o1dy3ra4BamzKhYOiGItCeZ740=
1016
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
1117
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8=

0 commit comments

Comments
 (0)