Skip to content

Commit 7c45b23

Browse files
Fix bugs in exporter
1 parent 5231f69 commit 7c45b23

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

collector/nginx_plus.go

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,22 @@ func (c *NginxPlusCollector) getStreamUpstreamServerPeerLabelValues(peer string)
198198
type VariableLabelNames struct {
199199
UpstreamServerVariableLabelNames []string
200200
ServerZoneVariableLabelNames []string
201-
StreamServerZoneVariableLabelNames []string
202201
UpstreamServerPeerVariableLabelNames []string
203202
StreamUpstreamServerPeerVariableLabelNames []string
203+
StreamServerZoneVariableLabelNames []string
204204
StreamUpstreamServerVariableLabelNames []string
205205
}
206206

207207
// NewVariableLabels creates a new struct for VariableNames for the collector
208-
func NewVariableLabelNames(upstreamServerVariableLabelNames []string, serverZoneVariableLabelNames []string,
209-
upstreamServerPeerVariableLabelNames []string, streamUpstreamServerVariableLabelNames []string) VariableLabelNames {
208+
func NewVariableLabelNames(upstreamServerVariableLabelNames []string, serverZoneVariableLabelNames []string, upstreamServerPeerVariableLabelNames []string,
209+
streamUpstreamServerVariableLabelNames []string, streamServerZoneLabels []string, streamUpstreamServerPeerVariableLabelNames []string) VariableLabelNames {
210210
return VariableLabelNames{
211-
UpstreamServerVariableLabelNames: upstreamServerVariableLabelNames,
212-
ServerZoneVariableLabelNames: serverZoneVariableLabelNames,
213-
UpstreamServerPeerVariableLabelNames: upstreamServerPeerVariableLabelNames,
214-
StreamUpstreamServerVariableLabelNames: streamUpstreamServerVariableLabelNames,
211+
UpstreamServerVariableLabelNames: upstreamServerVariableLabelNames,
212+
ServerZoneVariableLabelNames: serverZoneVariableLabelNames,
213+
UpstreamServerPeerVariableLabelNames: upstreamServerPeerVariableLabelNames,
214+
StreamUpstreamServerVariableLabelNames: streamUpstreamServerVariableLabelNames,
215+
StreamServerZoneVariableLabelNames: streamServerZoneLabels,
216+
StreamUpstreamServerPeerVariableLabelNames: streamUpstreamServerPeerVariableLabelNames,
215217
}
216218
}
217219

@@ -223,6 +225,7 @@ func NewNginxPlusCollector(nginxClient *plusclient.NginxClient, namespace string
223225
variableLabelNames: variableLabelNames,
224226
upstreamServerLabels: make(map[string][]string),
225227
serverZoneLabels: make(map[string][]string),
228+
streamServerZoneLabels: make(map[string][]string),
226229
upstreamServerPeerLabels: make(map[string][]string),
227230
streamUpstreamServerPeerLabels: make(map[string][]string),
228231
streamUpstreamServerLabels: make(map[string][]string),
@@ -239,26 +242,26 @@ func NewNginxPlusCollector(nginxClient *plusclient.NginxClient, namespace string
239242
"ssl_session_reuses": newGlobalMetric(namespace, "ssl_session_reuses", "Session reuses during SSL handshake", constLabels),
240243
},
241244
serverZoneMetrics: map[string]*prometheus.Desc{
242-
"processing": newServerZoneMetric(namespace, "processing", "Client requests that are currently being processed", variableLabelNames.StreamServerZoneVariableLabelNames, constLabels),
243-
"requests": newServerZoneMetric(namespace, "requests", "Total client requests", variableLabelNames.StreamServerZoneVariableLabelNames, constLabels),
244-
"responses_1xx": newServerZoneMetric(namespace, "responses", "Total responses sent to clients", variableLabelNames.StreamServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "1xx"})),
245-
"responses_2xx": newServerZoneMetric(namespace, "responses", "Total responses sent to clients", variableLabelNames.StreamServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "2xx"})),
246-
"responses_3xx": newServerZoneMetric(namespace, "responses", "Total responses sent to clients", variableLabelNames.StreamServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "3xx"})),
247-
"responses_4xx": newServerZoneMetric(namespace, "responses", "Total responses sent to clients", variableLabelNames.StreamServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "4xx"})),
248-
"responses_5xx": newServerZoneMetric(namespace, "responses", "Total responses sent to clients", variableLabelNames.StreamServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "5xx"})),
249-
"discarded": newServerZoneMetric(namespace, "discarded", "Requests completed without sending a response", variableLabelNames.StreamServerZoneVariableLabelNames, constLabels),
250-
"received": newServerZoneMetric(namespace, "received", "Bytes received from clients", variableLabelNames.StreamServerZoneVariableLabelNames, constLabels),
251-
"sent": newServerZoneMetric(namespace, "sent", "Bytes sent to clients", variableLabelNames.StreamServerZoneVariableLabelNames, constLabels),
245+
"processing": newServerZoneMetric(namespace, "processing", "Client requests that are currently being processed", variableLabelNames.ServerZoneVariableLabelNames, constLabels),
246+
"requests": newServerZoneMetric(namespace, "requests", "Total client requests", variableLabelNames.ServerZoneVariableLabelNames, constLabels),
247+
"responses_1xx": newServerZoneMetric(namespace, "responses", "Total responses sent to clients", variableLabelNames.ServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "1xx"})),
248+
"responses_2xx": newServerZoneMetric(namespace, "responses", "Total responses sent to clients", variableLabelNames.ServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "2xx"})),
249+
"responses_3xx": newServerZoneMetric(namespace, "responses", "Total responses sent to clients", variableLabelNames.ServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "3xx"})),
250+
"responses_4xx": newServerZoneMetric(namespace, "responses", "Total responses sent to clients", variableLabelNames.ServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "4xx"})),
251+
"responses_5xx": newServerZoneMetric(namespace, "responses", "Total responses sent to clients", variableLabelNames.ServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "5xx"})),
252+
"discarded": newServerZoneMetric(namespace, "discarded", "Requests completed without sending a response", variableLabelNames.ServerZoneVariableLabelNames, constLabels),
253+
"received": newServerZoneMetric(namespace, "received", "Bytes received from clients", variableLabelNames.ServerZoneVariableLabelNames, constLabels),
254+
"sent": newServerZoneMetric(namespace, "sent", "Bytes sent to clients", variableLabelNames.ServerZoneVariableLabelNames, constLabels),
252255
},
253256
streamServerZoneMetrics: map[string]*prometheus.Desc{
254-
"processing": newStreamServerZoneMetric(namespace, "processing", "Client connections that are currently being processed", variableLabelNames.ServerZoneVariableLabelNames, constLabels),
255-
"connections": newStreamServerZoneMetric(namespace, "connections", "Total connections", variableLabelNames.ServerZoneVariableLabelNames, constLabels),
256-
"sessions_2xx": newStreamServerZoneMetric(namespace, "sessions", "Total sessions completed", variableLabelNames.ServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "2xx"})),
257-
"sessions_4xx": newStreamServerZoneMetric(namespace, "sessions", "Total sessions completed", variableLabelNames.ServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "4xx"})),
258-
"sessions_5xx": newStreamServerZoneMetric(namespace, "sessions", "Total sessions completed", variableLabelNames.ServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "5xx"})),
259-
"discarded": newStreamServerZoneMetric(namespace, "discarded", "Connections completed without creating a session", variableLabelNames.ServerZoneVariableLabelNames, constLabels),
260-
"received": newStreamServerZoneMetric(namespace, "received", "Bytes received from clients", variableLabelNames.ServerZoneVariableLabelNames, constLabels),
261-
"sent": newStreamServerZoneMetric(namespace, "sent", "Bytes sent to clients", variableLabelNames.ServerZoneVariableLabelNames, constLabels),
257+
"processing": newStreamServerZoneMetric(namespace, "processing", "Client connections that are currently being processed", variableLabelNames.StreamServerZoneVariableLabelNames, constLabels),
258+
"connections": newStreamServerZoneMetric(namespace, "connections", "Total connections", variableLabelNames.StreamServerZoneVariableLabelNames, constLabels),
259+
"sessions_2xx": newStreamServerZoneMetric(namespace, "sessions", "Total sessions completed", variableLabelNames.StreamServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "2xx"})),
260+
"sessions_4xx": newStreamServerZoneMetric(namespace, "sessions", "Total sessions completed", variableLabelNames.StreamServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "4xx"})),
261+
"sessions_5xx": newStreamServerZoneMetric(namespace, "sessions", "Total sessions completed", variableLabelNames.StreamServerZoneVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "5xx"})),
262+
"discarded": newStreamServerZoneMetric(namespace, "discarded", "Connections completed without creating a session", variableLabelNames.StreamServerZoneVariableLabelNames, constLabels),
263+
"received": newStreamServerZoneMetric(namespace, "received", "Bytes received from clients", variableLabelNames.StreamServerZoneVariableLabelNames, constLabels),
264+
"sent": newStreamServerZoneMetric(namespace, "sent", "Bytes sent to clients", variableLabelNames.StreamServerZoneVariableLabelNames, constLabels),
262265
},
263266
upstreamMetrics: map[string]*prometheus.Desc{
264267
"keepalives": newUpstreamMetric(namespace, "keepalives", "Idle keepalive connections", constLabels),

exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ func main() {
380380
if err != nil {
381381
log.Fatalf("Could not create Nginx Plus Client: %v", err)
382382
}
383-
variableLabelNames := collector.NewVariableLabelNames(nil, nil, nil, nil)
383+
variableLabelNames := collector.NewVariableLabelNames(nil, nil, nil, nil, nil, nil)
384384
registry.MustRegister(collector.NewNginxPlusCollector(plusClient.(*plusclient.NginxClient), "nginxplus", variableLabelNames, constLabels.labels))
385385
} else {
386386
ossClient, err := createClientWithRetries(func() (interface{}, error) {

0 commit comments

Comments
 (0)