Skip to content

Add zone sync metrics and update go-client version #50

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

Merged
merged 1 commit into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Usage of ./nginx-prometheus-exporter:
* [Stream Server Zones](http://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_stream_server_zone).
* [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`.
* [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`.
* [Stream Zone Sync](http://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_stream_zone_sync).
* `nginxplus_up` -- shows the status of the last metric scrape: `1` for a successful scrape and `0` for a failed one.


Expand Down
41 changes: 40 additions & 1 deletion collector/nginx_plus.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log"
"sync"

plusclient "github.com/nginxinc/nginx-plus-go-sdk/client"
plusclient "github.com/nginxinc/nginx-plus-go-client/client"
"github.com/prometheus/client_golang/prometheus"
)

Expand All @@ -18,6 +18,7 @@ type NginxPlusCollector struct {
streamServerZoneMetrics map[string]*prometheus.Desc
streamUpstreamMetrics map[string]*prometheus.Desc
streamUpstreamServerMetrics map[string]*prometheus.Desc
streamZoneSyncMetrics map[string]*prometheus.Desc
upMetric prometheus.Gauge
mutex sync.Mutex
}
Expand Down Expand Up @@ -100,6 +101,15 @@ func NewNginxPlusCollector(nginxClient *plusclient.NginxClient, namespace string
"health_checks_fails": newStreamUpstreamServerMetric(namespace, "health_checks_fails", "Failed health checks"),
"health_checks_unhealthy": newStreamUpstreamServerMetric(namespace, "health_checks_unhealthy", "How many times the server became unhealthy (state 'unhealthy')"),
},
streamZoneSyncMetrics: map[string]*prometheus.Desc{
"bytes_in": newStreamZoneSyncMetric(namespace, "bytes_in", "Bytes received by this node"),
"bytes_out": newStreamZoneSyncMetric(namespace, "bytes_out", "Bytes sent by this node"),
"msgs_in": newStreamZoneSyncMetric(namespace, "msgs_in", "Total messages received by this node"),
"msgs_out": newStreamZoneSyncMetric(namespace, "msgs_out", "Total messages sent by this node"),
"nodes_online": newStreamZoneSyncMetric(namespace, "nodes_online", "Number of peers this node is conected to"),
"records_pending": newStreamZoneSyncZoneMetric(namespace, "records_pending", "The number of records that need to be sent to the cluster"),
"records_total": newStreamZoneSyncZoneMetric(namespace, "records_total", "The total number of records stored in the shared memory zone"),
},
upMetric: newUpMetric(namespace),
}
}
Expand Down Expand Up @@ -130,6 +140,9 @@ func (c *NginxPlusCollector) Describe(ch chan<- *prometheus.Desc) {
for _, m := range c.streamUpstreamServerMetrics {
ch <- m
}
for _, m := range c.streamZoneSyncMetrics {
ch <- m
}
}

// Collect fetches metrics from NGINX Plus and sends them to the provided channel.
Expand Down Expand Up @@ -289,6 +302,24 @@ func (c *NginxPlusCollector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(c.streamUpstreamMetrics["zombies"],
prometheus.GaugeValue, float64(upstream.Zombies), name)
}

for name, zone := range stats.StreamZoneSync.Zones {
ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["records_pending"],
prometheus.GaugeValue, float64(zone.RecordsPending), name)
ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["records_total"],
prometheus.GaugeValue, float64(zone.RecordsTotal), name)
}

ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["bytes_in"],
prometheus.CounterValue, float64(stats.StreamZoneSync.Status.BytesIn))
ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["bytes_out"],
prometheus.CounterValue, float64(stats.StreamZoneSync.Status.BytesOut))
ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["msgs_in"],
prometheus.CounterValue, float64(stats.StreamZoneSync.Status.MsgsIn))
ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["msgs_out"],
prometheus.CounterValue, float64(stats.StreamZoneSync.Status.MsgsOut))
ch <- prometheus.MustNewConstMetric(c.streamZoneSyncMetrics["nodes_online"],
prometheus.GaugeValue, float64(stats.StreamZoneSync.Status.NodesOnline))
}

var upstreamServerStates = map[string]float64{
Expand Down Expand Up @@ -323,3 +354,11 @@ func newUpstreamServerMetric(namespace string, metricName string, docString stri
func newStreamUpstreamServerMetric(namespace string, metricName string, docString string) *prometheus.Desc {
return prometheus.NewDesc(prometheus.BuildFQName(namespace, "stream_upstream_server", metricName), docString, []string{"upstream", "server"}, nil)
}

func newStreamZoneSyncMetric(namespace string, metricName string, docString string) *prometheus.Desc {
return prometheus.NewDesc(prometheus.BuildFQName(namespace, "stream_zone_sync_status", metricName), docString, nil, nil)
}

func newStreamZoneSyncZoneMetric(namespace string, metricName string, docString string) *prometheus.Desc {
return prometheus.NewDesc(prometheus.BuildFQName(namespace, "stream_zone_sync_zone", metricName), docString, []string{"zone"}, nil)
}
2 changes: 1 addition & 1 deletion exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"syscall"
"time"

plusclient "github.com/nginxinc/nginx-plus-go-sdk/client"
plusclient "github.com/nginxinc/nginx-plus-go-client/client"
"github.com/nginxinc/nginx-prometheus-exporter/client"
"github.com/nginxinc/nginx-prometheus-exporter/collector"
"github.com/prometheus/client_golang/prometheus"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/nginxinc/nginx-prometheus-exporter
go 1.12

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