Skip to content

Commit 2b02f44

Browse files
committed
Export proxy metrics to prometheus
Signed-off-by: Eugene Tretiak <[email protected]>
1 parent 58370a5 commit 2b02f44

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,34 @@ The exporter collects a number of statistics from the server:
8787
# TYPE memcached_malloced_bytes gauge
8888
# HELP memcached_max_connections Maximum number of clients allowed.
8989
# TYPE memcached_max_connections gauge
90+
# HELP memcached_proxy_backend_failed Number of backends currently in a failed state.
91+
# TYPE memcached_proxy_backend_failed gauge
92+
# HELP memcached_proxy_backend_marked_bad_total Total times a backend was marked unhealthy by the proxy.
93+
# TYPE memcached_proxy_backend_marked_bad_total counter
94+
# HELP memcached_proxy_backend_total Number of backend servers configured in proxy mode.
95+
# TYPE memcached_proxy_backend_total gauge
96+
# HELP memcached_proxy_config_reload_fails_total Total failed attempts to reload the proxy configuration.
97+
# TYPE memcached_proxy_config_reload_fails_total counter
98+
# HELP memcached_proxy_config_reloads_total Total attempts to reload the proxy configuration.
99+
# TYPE memcached_proxy_config_reloads_total counter
100+
# HELP memcached_proxy_config_cron_fails_total Total errors from the proxy’s Lua cron hooks.
101+
# TYPE memcached_proxy_config_cron_fails_total counter
102+
# HELP memcached_proxy_config_cron_runs_total Total times the proxy’s Lua cron hooks have run.
103+
# TYPE memcached_proxy_config_cron_runs_total counter
104+
# HELP memcached_proxy_conn_errors_total Total number of backend connection errors in proxy mode.
105+
# TYPE memcached_proxy_conn_errors_total counter
106+
# HELP memcached_proxy_conn_oom_total Total number of times the proxy ran out of memory allocating a connection.
107+
# TYPE memcached_proxy_conn_oom_total counter
108+
# HELP memcached_proxy_conn_requests_total Total number of times the proxy opened a backend connection.
109+
# TYPE memcached_proxy_conn_requests_total counter
110+
# HELP memcached_proxy_req_active Number of in-flight requests currently forwarded by the proxy.
111+
# TYPE memcached_proxy_req_active gauge
112+
# HELP memcached_proxy_request_failed_depth_total Total requests dropped due to backend depth limits.
113+
# TYPE memcached_proxy_request_failed_depth_total counter
90114
# HELP memcached_read_bytes_total Total number of bytes read by this server from network.
91115
# TYPE memcached_read_bytes_total counter
116+
# HELP memcached_round_robin_fallback_total Total times the proxy fell back to round-robin routing.
117+
# TYPE memcached_round_robin_fallback_total counter
92118
# HELP memcached_slab_chunk_size_bytes Number of bytes allocated to each chunk within this slab class.
93119
# TYPE memcached_slab_chunk_size_bytes gauge
94120
# HELP memcached_slab_chunks_free Number of chunks not yet allocated items.
@@ -149,6 +175,8 @@ The exporter collects a number of statistics from the server:
149175
# TYPE memcached_slab_warm_items gauge
150176
# HELP memcached_time_seconds current UNIX time according to the server.
151177
# TYPE memcached_time_seconds gauge
178+
# HELP memcached_unexpected_napi_ids_total Total unexpected internal event-loop IDs seen by the proxy.
179+
# TYPE memcached_unexpected_napi_ids_total counter
152180
# HELP memcached_up Could the memcached server be reached.
153181
# TYPE memcached_up gauge
154182
# HELP memcached_uptime_seconds Number of seconds since the server started.

pkg/exporter/exporter.go

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ type Exporter struct {
130130
extstoreBytesFragmented *prometheus.Desc
131131
extstoreIOQueueDepth *prometheus.Desc
132132
acceptingConnections *prometheus.Desc
133+
proxyConnRequests *prometheus.Desc
134+
proxyConnErrors *prometheus.Desc
135+
proxyConnOOM *prometheus.Desc
136+
proxyReqActive *prometheus.Desc
137+
proxyConfigReloads *prometheus.Desc
138+
proxyConfigReloadFails *prometheus.Desc
139+
proxyConfigCronRuns *prometheus.Desc
140+
proxyConfigCronFails *prometheus.Desc
141+
proxyBackendTotal *prometheus.Desc
142+
proxyBackendMarkedBad *prometheus.Desc
143+
proxyBackendFailed *prometheus.Desc
144+
proxyRequestFailedDepth *prometheus.Desc
145+
roundRobinFallback *prometheus.Desc
146+
unexpectedNapiIDs *prometheus.Desc
133147
}
134148

135149
// New returns an initialized exporter.
@@ -673,6 +687,76 @@ func New(server string, timeout time.Duration, logger *slog.Logger, tlsConfig *t
673687
nil,
674688
nil,
675689
),
690+
proxyConnRequests: prometheus.NewDesc(
691+
prometheus.BuildFQName(Namespace, "", "proxy_conn_requests_total"),
692+
"Total number of times the proxy opened a backend connection.",
693+
nil, nil,
694+
),
695+
proxyConnErrors: prometheus.NewDesc(
696+
prometheus.BuildFQName(Namespace, "", "proxy_conn_errors_total"),
697+
"Total number of backend connection errors in proxy mode.",
698+
nil, nil,
699+
),
700+
proxyConnOOM: prometheus.NewDesc(
701+
prometheus.BuildFQName(Namespace, "", "proxy_conn_oom_total"),
702+
"Total number of times the proxy ran out of memory allocating a connection.",
703+
nil, nil,
704+
),
705+
proxyReqActive: prometheus.NewDesc(
706+
prometheus.BuildFQName(Namespace, "", "proxy_req_active"),
707+
"Number of in-flight requests currently forwarded by the proxy.",
708+
nil, nil,
709+
),
710+
proxyConfigReloads: prometheus.NewDesc(
711+
prometheus.BuildFQName(Namespace, "", "proxy_config_reloads_total"),
712+
"Total attempts to reload the proxy configuration.",
713+
nil, nil,
714+
),
715+
proxyConfigReloadFails: prometheus.NewDesc(
716+
prometheus.BuildFQName(Namespace, "", "proxy_config_reload_fails_total"),
717+
"Total failed attempts to reload the proxy configuration.",
718+
nil, nil,
719+
),
720+
proxyConfigCronRuns: prometheus.NewDesc(
721+
prometheus.BuildFQName(Namespace, "", "proxy_config_cron_runs_total"),
722+
"Total times the proxy’s Lua cron hooks have run.",
723+
nil, nil,
724+
),
725+
proxyConfigCronFails: prometheus.NewDesc(
726+
prometheus.BuildFQName(Namespace, "", "proxy_config_cron_fails_total"),
727+
"Total errors from the proxy’s Lua cron hooks.",
728+
nil, nil,
729+
),
730+
proxyBackendTotal: prometheus.NewDesc(
731+
prometheus.BuildFQName(Namespace, "", "proxy_backend_total"),
732+
"Number of backend servers configured in proxy mode.",
733+
nil, nil,
734+
),
735+
proxyBackendMarkedBad: prometheus.NewDesc(
736+
prometheus.BuildFQName(Namespace, "", "proxy_backend_marked_bad_total"),
737+
"Total times a backend was marked unhealthy by the proxy.",
738+
nil, nil,
739+
),
740+
proxyBackendFailed: prometheus.NewDesc(
741+
prometheus.BuildFQName(Namespace, "", "proxy_backend_failed"),
742+
"Number of backends currently in a failed state.",
743+
nil, nil,
744+
),
745+
proxyRequestFailedDepth: prometheus.NewDesc(
746+
prometheus.BuildFQName(Namespace, "", "proxy_request_failed_depth_total"),
747+
"Total requests dropped due to backend depth limits.",
748+
nil, nil,
749+
),
750+
roundRobinFallback: prometheus.NewDesc(
751+
prometheus.BuildFQName(Namespace, "", "round_robin_fallback_total"),
752+
"Total times the proxy fell back to round-robin routing.",
753+
nil, nil,
754+
),
755+
unexpectedNapiIDs: prometheus.NewDesc(
756+
prometheus.BuildFQName(Namespace, "", "unexpected_napi_ids_total"),
757+
"Total unexpected internal event-loop IDs seen by the proxy.",
758+
nil, nil,
759+
),
676760
}
677761
}
678762

@@ -769,6 +853,20 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
769853
ch <- e.extstoreBytesLimit
770854
ch <- e.extstoreIOQueueDepth
771855
ch <- e.acceptingConnections
856+
ch <- e.proxyConnRequests
857+
ch <- e.proxyConnErrors
858+
ch <- e.proxyConnOOM
859+
ch <- e.proxyReqActive
860+
ch <- e.proxyConfigReloads
861+
ch <- e.proxyConfigReloadFails
862+
ch <- e.proxyConfigCronRuns
863+
ch <- e.proxyConfigCronFails
864+
ch <- e.proxyBackendTotal
865+
ch <- e.proxyBackendMarkedBad
866+
ch <- e.proxyBackendFailed
867+
ch <- e.proxyRequestFailedDepth
868+
ch <- e.roundRobinFallback
869+
ch <- e.unexpectedNapiIDs
772870
}
773871

774872
// Collect fetches the statistics from the configured memcached server, and
@@ -901,6 +999,30 @@ func (e *Exporter) parseStats(ch chan<- prometheus.Metric, stats map[net.Addr]me
901999
}
9021000
}
9031001

1002+
// proxy stats are only included if memcached server is in proxy mode. Take the presence of the
1003+
// proxy_backend_total key as a signal that they all should be there and do the parsing
1004+
if _, ok := s["proxy_backend_total"]; ok {
1005+
err = firstError(
1006+
e.parseAndNewMetric(ch, e.proxyConnRequests, prometheus.CounterValue, s, "proxy_conn_requests"),
1007+
e.parseAndNewMetric(ch, e.proxyConnErrors, prometheus.CounterValue, s, "proxy_conn_errors"),
1008+
e.parseAndNewMetric(ch, e.proxyConnOOM, prometheus.CounterValue, s, "proxy_conn_oom"),
1009+
e.parseAndNewMetric(ch, e.proxyReqActive, prometheus.GaugeValue, s, "proxy_req_active"),
1010+
e.parseAndNewMetric(ch, e.proxyConfigReloads, prometheus.CounterValue, s, "proxy_config_reloads"),
1011+
e.parseAndNewMetric(ch, e.proxyConfigReloadFails, prometheus.CounterValue, s, "proxy_config_reload_fails"),
1012+
e.parseAndNewMetric(ch, e.proxyConfigCronRuns, prometheus.CounterValue, s, "proxy_config_cron_runs"),
1013+
e.parseAndNewMetric(ch, e.proxyConfigCronFails, prometheus.CounterValue, s, "proxy_config_cron_fails"),
1014+
e.parseAndNewMetric(ch, e.proxyBackendTotal, prometheus.GaugeValue, s, "proxy_backend_total"),
1015+
e.parseAndNewMetric(ch, e.proxyBackendMarkedBad, prometheus.CounterValue, s, "proxy_backend_marked_bad"),
1016+
e.parseAndNewMetric(ch, e.proxyBackendFailed, prometheus.GaugeValue, s, "proxy_backend_failed"),
1017+
e.parseAndNewMetric(ch, e.proxyRequestFailedDepth, prometheus.CounterValue, s, "proxy_request_failed_depth"),
1018+
e.parseAndNewMetric(ch, e.roundRobinFallback, prometheus.CounterValue, s, "round_robin_fallback"),
1019+
e.parseAndNewMetric(ch, e.unexpectedNapiIDs, prometheus.CounterValue, s, "unexpected_napi_ids"),
1020+
)
1021+
if err != nil {
1022+
parseError = err
1023+
}
1024+
}
1025+
9041026
err = firstError(
9051027
e.parseTimevalAndNewMetric(ch, e.rusageUser, prometheus.CounterValue, s, "rusage_user"),
9061028
e.parseTimevalAndNewMetric(ch, e.rusageSystem, prometheus.CounterValue, s, "rusage_system"),

0 commit comments

Comments
 (0)