MCPcopy
hub / github.com/openfaas/faas / Collect

Method Collect

gateway/metrics/exporter.go:54–77  ·  view source on GitHub ↗

Collect collects data to be consumed by prometheus

(ch chan<- prometheus.Metric)

Source from the content-addressed store, hash-verified

52
53// Collect collects data to be consumed by prometheus
54func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
55 e.metricOptions.GatewayFunctionInvocation.Collect(ch)
56 e.metricOptions.GatewayFunctionsHistogram.Collect(ch)
57
58 e.metricOptions.GatewayFunctionInvocationStarted.Collect(ch)
59
60 e.metricOptions.ServiceReplicasGauge.Reset()
61
62 for _, service := range e.services {
63 var serviceName string
64 if len(service.Namespace) > 0 {
65 serviceName = fmt.Sprintf("%s.%s", service.Name, service.Namespace)
66 } else {
67 serviceName = service.Name
68 }
69
70 // Set current replica count
71 e.metricOptions.ServiceReplicasGauge.
72 WithLabelValues(serviceName).
73 Set(float64(service.Replicas))
74 }
75
76 e.metricOptions.ServiceReplicasGauge.Collect(ch)
77}
78
79// StartServiceWatcher starts a ticker and collects service replica counts to expose to prometheus
80func (e *Exporter) StartServiceWatcher(endpointURL url.URL, metricsOptions MetricOptions, label string, interval time.Duration) {

Calls 1

SetMethod · 0.65