Skip to content

Commit

Permalink
Move metric definition to the same file as other metrics (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthenw authored May 11, 2018
1 parent 79dfe2e commit 517f1ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
16 changes: 1 addition & 15 deletions httpapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import (
"time"

"github.com/julienschmidt/httprouter"
"github.com/prometheus/client_golang/prometheus"
"github.com/serverless/event-gateway/function"
"github.com/serverless/event-gateway/subscription"
)

func init() {
prometheus.MustRegister(requestDuration)
}

// StartConfigAPI creates a new configuration API server and listens for requests.
func StartConfigAPI(functions function.Service, subscriptions subscription.Service, config ServerConfig) {
router := httprouter.New()
Expand Down Expand Up @@ -43,21 +38,12 @@ func StartConfigAPI(functions function.Service, subscriptions subscription.Servi
}()
}

var requestDuration = prometheus.NewHistogram(
prometheus.HistogramOpts{
Namespace: "gateway",
Subsystem: "config",
Name: "request_duration_seconds",
Help: "Bucketed histogram of request duration of Config API requests",
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 16),
})

type metricsReporter struct {
Handler http.Handler
}

func (m metricsReporter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
start := time.Now()
m.Handler.ServeHTTP(w, r)
requestDuration.Observe(time.Since(start).Seconds())
metricConfigRequestDuration.Observe(time.Since(start).Seconds())
}
10 changes: 10 additions & 0 deletions httpapi/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ func init() {
prometheus.MustRegister(metricSubscriptions)

prometheus.MustRegister(metricConfigRequests)
prometheus.MustRegister(metricConfigRequestDuration)
}

// Functions
Expand Down Expand Up @@ -40,3 +41,12 @@ var metricConfigRequests = prometheus.NewCounterVec(
Name: "requests_total",
Help: "Total of Config API requests.",
}, []string{"space", "resource", "operation"})

var metricConfigRequestDuration = prometheus.NewHistogram(
prometheus.HistogramOpts{
Namespace: "gateway",
Subsystem: "config",
Name: "request_duration_seconds",
Help: "Bucketed histogram of request duration of Config API requests",
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 16),
})

0 comments on commit 517f1ec

Please sign in to comment.