Skip to content

Commit

Permalink
Split request_count metric by contentType
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-t committed May 17, 2016
1 parent bff4e12 commit c5147bd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions pkg/apiserver/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ var (
requestCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "apiserver_request_count",
Help: "Counter of apiserver requests broken out for each verb, API resource, client, and HTTP response code.",
Help: "Counter of apiserver requests broken out for each verb, API resource, client, and HTTP response contentType and code.",
},
[]string{"verb", "resource", "client", "code"},
[]string{"verb", "resource", "client", "contentType", "code"},
)
requestLatencies = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Expand Down Expand Up @@ -66,9 +66,9 @@ func Register() {
prometheus.MustRegister(requestLatenciesSummary)
}

func Monitor(verb, resource *string, client string, httpCode int, reqStart time.Time) {
func Monitor(verb, resource *string, client, contentType string, httpCode int, reqStart time.Time) {
elapsed := float64((time.Since(reqStart)) / time.Microsecond)
requestCounter.WithLabelValues(*verb, *resource, client, codeToString(httpCode)).Inc()
requestCounter.WithLabelValues(*verb, *resource, client, contentType, codeToString(httpCode)).Inc()
requestLatencies.WithLabelValues(*verb, *resource).Observe(elapsed)
requestLatenciesSummary.WithLabelValues(*verb, *resource).Observe(elapsed)
}
Expand Down Expand Up @@ -99,7 +99,7 @@ func InstrumentRouteFunc(verb, resource string, routeFunc restful.RouteFunction)
response.ResponseWriter = rw

routeFunc(request, response)
Monitor(&verb, &resource, utilnet.GetHTTPClient(request.Request), delegate.status, now)
Monitor(&verb, &resource, utilnet.GetHTTPClient(request.Request), rw.Header().Get("Content-Type"), delegate.status, now)
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var apiResource string
var httpCode int
reqStart := time.Now()
defer metrics.Monitor(&verb, &apiResource, net.GetHTTPClient(req), httpCode, reqStart)
defer metrics.Monitor(&verb, &apiResource, net.GetHTTPClient(req), w.Header().Get("Content-Type"), httpCode, reqStart)

requestInfo, err := r.requestInfoResolver.GetRequestInfo(req)
if err != nil || !requestInfo.IsResourceRequest {
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/api_server_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

var KnownApiServerMetrics = map[string][]string{
"apiserver_request_count": {"verb", "resource", "client", "code"},
"apiserver_request_count": {"verb", "resource", "client", "contentType", "code"},
"apiserver_request_latencies_bucket": {"verb", "resource", "le"},
"apiserver_request_latencies_count": {"verb", "resource"},
"apiserver_request_latencies_sum": {"verb", "resource"},
Expand Down

0 comments on commit c5147bd

Please sign in to comment.