mirror of
https://github.com/openfaas/faas.git
synced 2025-06-17 12:46:59 +00:00
Instrument system calls
Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
parent
1cc767e898
commit
64a3f4e495
@ -140,6 +140,30 @@ func copyHeaders(destination http.Header, source *http.Header) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PrometheusServiceNotifier struct {
|
||||||
|
ServiceMetrics *metrics.ServiceMetricOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify about service metrics
|
||||||
|
func (psn PrometheusServiceNotifier) Notify(method string, URL string, originalURL string, statusCode int, duration time.Duration) {
|
||||||
|
code := fmt.Sprintf("%d", statusCode)
|
||||||
|
psn.ServiceMetrics.Counter.WithLabelValues(code).Inc()
|
||||||
|
|
||||||
|
psn.ServiceMetrics.Histogram.WithLabelValues(method, urlToLabel(URL), code).Observe(duration.Seconds())
|
||||||
|
}
|
||||||
|
|
||||||
|
var invalidChars = regexp.MustCompile(`[^a-zA-Z0-9]+`)
|
||||||
|
|
||||||
|
// converts a URL path to a string compatible with Prometheus label value.
|
||||||
|
func urlToLabel(path string) string {
|
||||||
|
result := invalidChars.ReplaceAllString(path, "_")
|
||||||
|
result = strings.ToLower(strings.Trim(result, "_"))
|
||||||
|
if result == "" {
|
||||||
|
result = "root"
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// PrometheusFunctionNotifier records metrics to Prometheus
|
// PrometheusFunctionNotifier records metrics to Prometheus
|
||||||
type PrometheusFunctionNotifier struct {
|
type PrometheusFunctionNotifier struct {
|
||||||
Metrics *metrics.MetricOptions
|
Metrics *metrics.MetricOptions
|
||||||
|
@ -64,8 +64,12 @@ func main() {
|
|||||||
prometheusNotifier := handlers.PrometheusFunctionNotifier{
|
prometheusNotifier := handlers.PrometheusFunctionNotifier{
|
||||||
Metrics: &metricsOptions,
|
Metrics: &metricsOptions,
|
||||||
}
|
}
|
||||||
|
prometheusServiceNotifier := handlers.PrometheusServiceNotifier{
|
||||||
|
ServiceMetrics: metricsOptions.ServiceMetrics,
|
||||||
|
}
|
||||||
|
|
||||||
functionNotifiers := []handlers.HTTPNotifier{loggingNotifier, prometheusNotifier}
|
functionNotifiers := []handlers.HTTPNotifier{loggingNotifier, prometheusNotifier}
|
||||||
forwardingNotifiers := []handlers.HTTPNotifier{loggingNotifier}
|
forwardingNotifiers := []handlers.HTTPNotifier{loggingNotifier, prometheusServiceNotifier}
|
||||||
|
|
||||||
urlResolver := handlers.SingleHostBaseURLResolver{BaseURL: config.FunctionsProviderURL.String()}
|
urlResolver := handlers.SingleHostBaseURLResolver{BaseURL: config.FunctionsProviderURL.String()}
|
||||||
var functionURLResolver handlers.BaseURLResolver
|
var functionURLResolver handlers.BaseURLResolver
|
||||||
|
Loading…
x
Reference in New Issue
Block a user