Skip to content

Commit 09f6d99

Browse files
committed
PoC of N+ reporting metrics
This one depends on pending PR in nginx-plus-go-client: nginx/nginx-plus-go-client#528
1 parent 458945a commit 09f6d99

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

collector/nginx_plus.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,19 @@ func NewNginxPlusCollector(nginxClient *plusclient.NginxClient, namespace string
274274
nginxClient: nginxClient,
275275
logger: logger,
276276
totalMetrics: map[string]*prometheus.Desc{
277-
"connections_accepted": newGlobalMetric(namespace, "connections_accepted", "Accepted client connections", constLabels),
278-
"connections_dropped": newGlobalMetric(namespace, "connections_dropped", "Dropped client connections", constLabels),
279-
"connections_active": newGlobalMetric(namespace, "connections_active", "Active client connections", constLabels),
280-
"connections_idle": newGlobalMetric(namespace, "connections_idle", "Idle client connections", constLabels),
281-
"http_requests_total": newGlobalMetric(namespace, "http_requests_total", "Total http requests", constLabels),
282-
"http_requests_current": newGlobalMetric(namespace, "http_requests_current", "Current http requests", constLabels),
283-
"ssl_handshakes": newGlobalMetric(namespace, "ssl_handshakes", "Successful SSL handshakes", constLabels),
284-
"ssl_handshakes_failed": newGlobalMetric(namespace, "ssl_handshakes_failed", "Failed SSL handshakes", constLabels),
285-
"ssl_session_reuses": newGlobalMetric(namespace, "ssl_session_reuses", "Session reuses during SSL handshake", constLabels),
286-
"license_active_till": newGlobalMetric(namespace, "license_expiration_timestamp_seconds", "License expiration date (expressed as Unix Epoch Time)", constLabels),
277+
"connections_accepted": newGlobalMetric(namespace, "connections_accepted", "Accepted client connections", constLabels),
278+
"connections_dropped": newGlobalMetric(namespace, "connections_dropped", "Dropped client connections", constLabels),
279+
"connections_active": newGlobalMetric(namespace, "connections_active", "Active client connections", constLabels),
280+
"connections_idle": newGlobalMetric(namespace, "connections_idle", "Idle client connections", constLabels),
281+
"http_requests_total": newGlobalMetric(namespace, "http_requests_total", "Total http requests", constLabels),
282+
"http_requests_current": newGlobalMetric(namespace, "http_requests_current", "Current http requests", constLabels),
283+
"ssl_handshakes": newGlobalMetric(namespace, "ssl_handshakes", "Successful SSL handshakes", constLabels),
284+
"ssl_handshakes_failed": newGlobalMetric(namespace, "ssl_handshakes_failed", "Failed SSL handshakes", constLabels),
285+
"ssl_session_reuses": newGlobalMetric(namespace, "ssl_session_reuses", "Session reuses during SSL handshake", constLabels),
286+
"license_active_till": newGlobalMetric(namespace, "license_expiration_timestamp_seconds", "License expiration date (expressed as Unix Epoch Time)", constLabels),
287+
"license_reporting_healthy": newGlobalMetric(namespace, "license_reporting_healthy", "Indicates whether the reporting state is still considered healthy despite recent failed attempts", constLabels),
288+
"license_reporting_fails": newGlobalMetric(namespace, "license_reporting_fails_count", "Number of failed reporting attempts, reset each time the usage report is successfully sent", constLabels),
289+
"license_reporting_grace_period": newGlobalMetric(namespace, "license_reporting_grace_period_seconds", "Number of seconds before traffic processing is stopped after unsuccessful report attempt", constLabels),
287290
},
288291
serverZoneMetrics: map[string]*prometheus.Desc{
289292
"processing": newServerZoneMetric(namespace, "processing", "Client requests that are currently being processed", variableLabelNames.ServerZoneVariableLabelNames, constLabels),
@@ -661,6 +664,21 @@ func (c *NginxPlusCollector) Collect(ch chan<- prometheus.Metric) {
661664
} else {
662665
ch <- prometheus.MustNewConstMetric(c.totalMetrics["license_active_till"],
663666
prometheus.GaugeValue, float64(license.ActiveTill))
667+
668+
if license.Reporting != nil {
669+
if license.Reporting.Healthy {
670+
ch <- prometheus.MustNewConstMetric(c.totalMetrics["license_reporting_healthy"],
671+
prometheus.GaugeValue, float64(1))
672+
} else {
673+
ch <- prometheus.MustNewConstMetric(c.totalMetrics["license_reporting_healthy"],
674+
prometheus.GaugeValue, float64(0))
675+
}
676+
ch <- prometheus.MustNewConstMetric(c.totalMetrics["license_reporting_fails"],
677+
prometheus.GaugeValue, float64(license.Reporting.Fails))
678+
679+
ch <- prometheus.MustNewConstMetric(c.totalMetrics["license_reporting_grace_period"],
680+
prometheus.GaugeValue, float64(license.Reporting.Grace))
681+
}
664682
}
665683

666684
for name, zone := range stats.ServerZones {

0 commit comments

Comments
 (0)