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) brk := client.breaker.Get(uri)
if err = brk.Allow(); err != nil { if err = brk.Allow(); err != nil {
code = "breaker" code = "breaker"
_metricClientReqCodeTotal.Inc(uri, code) _metricClientReqCodeTotal.Inc(uri, req.Method, code)
return return
} }
defer client.onBreaker(brk, &err) defer client.onBreaker(brk, &err)
// stat // stat
now := time.Now() now := time.Now()
defer func() { defer func() {
_metricClientReqDur.Observe(int64(time.Since(now)/time.Millisecond), uri) _metricClientReqDur.Observe(int64(time.Since(now)/time.Millisecond), uri, req.Method)
if code != "" { if code != "" {
_metricClientReqCodeTotal.Inc(uri, code) _metricClientReqCodeTotal.Inc(uri, req.Method, code)
} }
}() }()
// get config // get config

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

@ -13,7 +13,7 @@ var (
Subsystem: "requests", Subsystem: "requests",
Name: "duration_ms", Name: "duration_ms",
Help: "http server requests 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}, Buckets: []float64{5, 10, 25, 50, 100, 250, 500, 1000},
}) })
_metricServerReqCodeTotal = metric.NewCounterVec(&metric.CounterVecOpts{ _metricServerReqCodeTotal = metric.NewCounterVec(&metric.CounterVecOpts{
@ -21,21 +21,21 @@ var (
Subsystem: "requests", Subsystem: "requests",
Name: "code_total", Name: "code_total",
Help: "http server requests error count.", Help: "http server requests error count.",
Labels: []string{"path", "caller", "code"}, Labels: []string{"path", "caller", "method", "code"},
}) })
_metricServerBBR = metric.NewCounterVec(&metric.CounterVecOpts{ _metricServerBBR = metric.NewCounterVec(&metric.CounterVecOpts{
Namespace: serverNamespace, Namespace: serverNamespace,
Subsystem: "", Subsystem: "",
Name: "bbr_total", Name: "bbr_total",
Help: "http server bbr total.", Help: "http server bbr total.",
Labels: []string{"url"}, Labels: []string{"url", "method"},
}) })
_metricClientReqDur = metric.NewHistogramVec(&metric.HistogramVecOpts{ _metricClientReqDur = metric.NewHistogramVec(&metric.HistogramVecOpts{
Namespace: clientNamespace, Namespace: clientNamespace,
Subsystem: "requests", Subsystem: "requests",
Name: "duration_ms", Name: "duration_ms",
Help: "http client requests 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}, Buckets: []float64{5, 10, 25, 50, 100, 250, 500, 1000},
}) })
_metricClientReqCodeTotal = metric.NewCounterVec(&metric.CounterVecOpts{ _metricClientReqCodeTotal = metric.NewCounterVec(&metric.CounterVecOpts{
@ -43,6 +43,6 @@ var (
Subsystem: "requests", Subsystem: "requests",
Name: "code_total", Name: "code_total",
Help: "http client requests code count.", 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) limiter := b.group.Get(uri)
done, err := limiter.Allow(c) done, err := limiter.Allow(c)
if err != nil { if err != nil {
_metricServerBBR.Inc(uri) _metricServerBBR.Inc(uri, c.Request.Method)
c.JSON(nil, err) c.JSON(nil, err)
c.Abort() c.Abort()
return return

Loading…
Cancel
Save