Skip to content

Commit 4d90184

Browse files
committed
Add zone sync endpoint to stats
1 parent 9fb6bf1 commit 4d90184

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

client/nginx.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type Stats struct {
8888
Upstreams Upstreams
8989
StreamServerZones StreamServerZones
9090
StreamUpstreams StreamUpstreams
91+
StreamZoneSync StreamZoneSync
9192
}
9293

9394
// NginxInfo contains general information about NGINX Plus.
@@ -149,6 +150,27 @@ type StreamServerZone struct {
149150
Sent uint64
150151
}
151152

153+
// StreamZoneSync represents the sync information per each shared memory zone and the sync information per node in a cluster
154+
type StreamZoneSync struct {
155+
Zones map[string]SyncZone
156+
Status StreamZoneSyncStatus
157+
}
158+
159+
// SyncZone represents the syncronization status of a shared memory zone
160+
type SyncZone struct {
161+
RecordsPending uint64 `json:"records_pending"`
162+
RecordsTotal uint64 `json:"records_total"`
163+
}
164+
165+
// StreamZoneSyncStatus represents the status of a shared memory zone
166+
type StreamZoneSyncStatus struct {
167+
BytesIn uint64 `json:"bytes_in"`
168+
MsgsIn uint64 `json:"msgs_in"`
169+
MsgsOut uint64 `json:"msgs_out"`
170+
BytesOut uint64 `json:"bytes_out"`
171+
NodesOnline uint64 `json:"nodes_online"`
172+
}
173+
152174
// Responses represents HTTP response related stats.
153175
type Responses struct {
154176
Responses1xx uint64 `json:"1xx"`
@@ -728,6 +750,11 @@ func (client *NginxClient) GetStats() (*Stats, error) {
728750
return nil, fmt.Errorf("failed to get stats: %v", err)
729751
}
730752

753+
streamZoneSync, err := client.getStreamZoneSync()
754+
if err != nil {
755+
return nil, fmt.Errorf("failed to get stats: %v", err)
756+
}
757+
731758
return &Stats{
732759
NginxInfo: *info,
733760
Connections: *cons,
@@ -737,6 +764,7 @@ func (client *NginxClient) GetStats() (*Stats, error) {
737764
StreamServerZones: *streamZones,
738765
Upstreams: *upstreams,
739766
StreamUpstreams: *streamUpstreams,
767+
StreamZoneSync: *streamZoneSync,
740768
}, nil
741769
}
742770

@@ -822,6 +850,22 @@ func (client *NginxClient) getStreamUpstreams() (*StreamUpstreams, error) {
822850
return &upstreams, nil
823851
}
824852

853+
func (client *NginxClient) getStreamZoneSync() (*StreamZoneSync, error) {
854+
var streamZoneSync StreamZoneSync
855+
err := client.get("stream/zone_sync", &streamZoneSync)
856+
if err != nil {
857+
if err, ok := err.(*internalError); ok {
858+
859+
if err.Code == pathNotFoundCode {
860+
return &streamZoneSync, nil
861+
}
862+
}
863+
return nil, fmt.Errorf("failed to get stream zone sync: %v", err)
864+
}
865+
866+
return &streamZoneSync, err
867+
}
868+
825869
// KeyValPairs are the key-value pairs stored in a zone.
826870
type KeyValPairs map[string]string
827871

0 commit comments

Comments
 (0)