net http metrics add uri method. (#453)

pull/462/head
shunza 5 years ago committed by Tony
parent 99eb3efa02
commit 07e25cf875
  1. 6
      pkg/net/http/blademaster/client.go
  2. 4
      pkg/net/http/blademaster/logger.go
  3. 10
      pkg/net/http/blademaster/metrics.go
  4. 2
      pkg/net/http/blademaster/ratelimit.go

@ -213,16 +213,16 @@ func (client *Client) Raw(c context.Context, req *xhttp.Request, v ...string) (b
brk := client.breaker.Get(uri)
if err = brk.Allow(); err != nil {
code = "breaker"
_metricClientReqCodeTotal.Inc(uri, code)
_metricClientReqCodeTotal.Inc(uri, req.Method, code)
return
}
defer client.onBreaker(brk, &err)
// stat
now := time.Now()
defer func() {
_metricClientReqDur.Observe(int64(time.Since(now)/time.Millisecond), uri)
_metricClientReqDur.Observe(int64(time.Since(now)/time.Millisecond), uri, req.Method)
if code != "" {
_metricClientReqCodeTotal.Inc(uri, code)
_metricClientReqCodeTotal.Inc(uri, req.Method, code)
}
}()
// get config

@ -35,8 +35,8 @@ func Logger() HandlerFunc {
}
if len(c.RoutePath) > 0 {
_metricServerReqCodeTotal.Inc(c.RoutePath[1:], caller, strconv.FormatInt(int64(cerr.Code()), 10))
_metricServerReqDur.Observe(int64(dt/time.Millisecond), c.RoutePath[1:], caller)
_metricServerReqCodeTotal.Inc(c.RoutePath[1:], caller, req.Method, strconv.FormatInt(int64(cerr.Code()), 10))
_metricServerReqDur.Observe(int64(dt/time.Millisecond), c.RoutePath[1:], caller, req.Method)
}
lf := log.Infov

@ -13,7 +13,7 @@ var (
Subsystem: "requests",
Name: "duration_ms",
Help: "http server requests duration(ms).",
Labels: []string{"path", "caller"},
Labels: []string{"path", "caller", "method"},
Buckets: []float64{5, 10, 25, 50, 100, 250, 500, 1000},
})
_metricServerReqCodeTotal = metric.NewCounterVec(&metric.CounterVecOpts{
@ -21,21 +21,21 @@ var (
Subsystem: "requests",
Name: "code_total",
Help: "http server requests error count.",
Labels: []string{"path", "caller", "code"},
Labels: []string{"path", "caller", "method", "code"},
})
_metricServerBBR = metric.NewCounterVec(&metric.CounterVecOpts{
Namespace: serverNamespace,
Subsystem: "",
Name: "bbr_total",
Help: "http server bbr total.",
Labels: []string{"url"},
Labels: []string{"url", "method"},
})
_metricClientReqDur = metric.NewHistogramVec(&metric.HistogramVecOpts{
Namespace: clientNamespace,
Subsystem: "requests",
Name: "duration_ms",
Help: "http client requests duration(ms).",
Labels: []string{"path"},
Labels: []string{"path", "method"},
Buckets: []float64{5, 10, 25, 50, 100, 250, 500, 1000},
})
_metricClientReqCodeTotal = metric.NewCounterVec(&metric.CounterVecOpts{
@ -43,6 +43,6 @@ var (
Subsystem: "requests",
Name: "code_total",
Help: "http client requests code count.",
Labels: []string{"path", "code"},
Labels: []string{"path", "method", "code"},
})
)

@ -39,7 +39,7 @@ func (b *RateLimiter) Limit() HandlerFunc {
limiter := b.group.Get(uri)
done, err := limiter.Allow(c)
if err != nil {
_metricServerBBR.Inc(uri)
_metricServerBBR.Inc(uri, c.Request.Method)
c.JSON(nil, err)
c.Abort()
return

Loading…
Cancel
Save