mirror of
https://github.com/openfaas/faas.git
synced 2025-06-23 23:33:25 +00:00
Function-based metrics for CE
OpenFaaS CE exposes metrics about function invocations and about the gateway itself. OpenFaaS Pro has a richer set of metrics including HTTP RED. See also: https://docs.openfaas.com/architecture/metrics/ Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
@ -17,20 +17,6 @@ type HTTPNotifier interface {
|
||||
Notify(method string, URL string, originalURL string, statusCode int, event string, duration time.Duration)
|
||||
}
|
||||
|
||||
// PrometheusServiceNotifier notifier for core service endpoints
|
||||
type PrometheusServiceNotifier struct {
|
||||
ServiceMetrics *metrics.ServiceMetricOptions
|
||||
}
|
||||
|
||||
// Notify about service metrics
|
||||
func (psn PrometheusServiceNotifier) Notify(method string, URL string, originalURL string, statusCode int, event string, duration time.Duration) {
|
||||
code := fmt.Sprintf("%d", statusCode)
|
||||
path := urlToLabel(URL)
|
||||
|
||||
psn.ServiceMetrics.Counter.WithLabelValues(method, path, code).Inc()
|
||||
psn.ServiceMetrics.Histogram.WithLabelValues(method, path, code).Observe(duration.Seconds())
|
||||
}
|
||||
|
||||
func urlToLabel(path string) string {
|
||||
if len(path) > 0 {
|
||||
path = strings.TrimRight(path, "/")
|
||||
|
Reference in New Issue
Block a user