Skip to content

Commit

Permalink
Merge pull request #4 from zengnjin/server-agent_monitor
Browse files Browse the repository at this point in the history
access.log & metrics
  • Loading branch information
zengnjin authored Dec 25, 2017
2 parents 3a3a884 + 59573d9 commit 188c528
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
12 changes: 11 additions & 1 deletion filter/accessLog.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@ func (t *AccessLogEndPointFilter) NewFilter(url *motan.URL) motan.Filter {

// Filter : Filter
func (t *AccessLogEndPointFilter) Filter(caller motan.Caller, request motan.Request) motan.Response {
role := "server"
var ip string
switch caller.(type) {
case motan.Provider:
role = "server-agent"
ip =request.GetAttachment(motan.HostKey)
case motan.EndPoint:
role = "client-agent"
ip =caller.GetURL().Host
}
start := time.Now()
response := t.GetNext().Filter(caller, request)
success := true
if response.GetException() != nil {
success = false
}
vlog.Infof("access log--server:%s:%d,pt:%d, req:%s,%s,%s,%d, res:%d,%t,%+v\n", caller.GetURL().Host, caller.GetURL().Port, time.Since(start)/1000000, request.GetServiceName(),
vlog.Infof("access log--%s:%s:%d,pt:%d, req:%s,%s,%s,%d, res:%d,%t,%+v\n", role, ip, caller.GetURL().Port, time.Since(start)/1000000, request.GetServiceName(),
request.GetMethod(), request.GetMethodDesc(), request.GetRequestID(), response.GetProcessTime(), success, response.GetException())
return response
}
Expand Down
11 changes: 9 additions & 2 deletions filter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func (m *MetricsFilter) GetNext() motan.EndPointFilter {
}

func (m *MetricsFilter) Filter(caller motan.Caller, request motan.Request) motan.Response {
role := "server"
switch caller.(type){
case motan.Provider:
role = "server-agent"
case motan.EndPoint:
role = "client-agent"
}

start := time.Now()

response := m.GetNext().Filter(caller, request)
Expand All @@ -62,8 +70,7 @@ func (m *MetricsFilter) Filter(caller motan.Caller, request motan.Request) motan
return '_'
}
return r
}, fmt.Sprintf("%s:%s:%s:%s", request.GetAttachments()["M_s"], request.GetAttachments()["M_g"], request.GetAttachments()["M_p"], request.GetMethod()))

}, fmt.Sprintf("motan-%s:%s:%s:%s:%s", role,request.GetAttachments()["M_s"], request.GetAttachments()["M_g"], request.GetAttachments()["M_p"], request.GetMethod()))
keyCount := key + ".total_count"
metrics.AddCounter(keyCount, 1) //total_count

Expand Down
21 changes: 11 additions & 10 deletions metrics/graphite.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,33 +65,34 @@ func genGraphiteMessages(localIP string, snap metrics.Registry) []string {
switch m := i.(type) {

case metrics.Counter:
segment = fmt.Sprintf("motan-agent.%s.%s.%s.byhost.%s.%s:%d|c\n",
segment = fmt.Sprintf("%s.%s.%s.byhost.%s.%s:%d|c\n",
pni[0], pni[1], pni[2], localIP, pni[3], m.Count())
fmt.Println(segment)
case metrics.Meter:
segment = fmt.Sprintf("motan-agent.%s.%s.%s.byhost.%s.%s:%d.00|c\n",
segment = fmt.Sprintf("%s.%s.%s.byhost.%s.%s:%d.00|c\n",
pni[0], pni[1], pni[2], localIP, pni[3], m.Count())
case metrics.Timer:
/*TODO
*/
case metrics.Gauge:
segment = fmt.Sprintf("motan-agent.%s.%s.%s.byhost.%s.%s:%d|kv\n",
segment = fmt.Sprintf("%s.%s.%s.byhost.%s.%s:%d|kv\n",
pni[0], pni[1], pni[2], localIP, pni[3], m.Value())
// case metrics.GaugeFloat64:
case metrics.Histogram:
ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999, 0.9999})
segment = fmt.Sprintf("motan-agent.%s.%s.%s.byhost.%s.%s.%s:%.2f|kv\n",
segment = fmt.Sprintf("%s.%s.%s.byhost.%s.%s.%s:%.2f|kv\n",
pni[0], pni[1], pni[2], localIP, pni[3], "p50", ps[0])
segment += fmt.Sprintf("motan-agent.%s.%s.%s.byhost.%s.%s.%s:%.2f|kv\n",
segment += fmt.Sprintf("%s.%s.%s.byhost.%s.%s.%s:%.2f|kv\n",
pni[0], pni[1], pni[2], localIP, pni[3], "p75", ps[1])
segment += fmt.Sprintf("motan-agent.%s.%s.%s.byhost.%s.%s.%s:%.2f|kv\n",
segment += fmt.Sprintf("%s.%s.%s.byhost.%s.%s.%s:%.2f|kv\n",
pni[0], pni[1], pni[2], localIP, pni[3], "p95", ps[2])
segment += fmt.Sprintf("motan-agent.%s.%s.%s.byhost.%s.%s.%s:%.2f|kv\n",
segment += fmt.Sprintf("%s.%s.%s.byhost.%s.%s.%s:%.2f|kv\n",
pni[0], pni[1], pni[2], localIP, pni[3], "p99", ps[3])
segment += fmt.Sprintf("motan-agent.%s.%s.%s.byhost.%s.%s.%s:%.2f|kv\n",
segment += fmt.Sprintf("%s.%s.%s.byhost.%s.%s.%s:%.2f|kv\n",
pni[0], pni[1], pni[2], localIP, pni[3], "p999", ps[4])
segment += fmt.Sprintf("motan-agent.%s.%s.%s.byhost.%s.%s.%s:%.2f|kv\n",
segment += fmt.Sprintf("%s.%s.%s.byhost.%s.%s.%s:%.2f|kv\n",
pni[0], pni[1], pni[2], localIP, pni[3], "p9999", ps[5])
segment += fmt.Sprintf("motan-agent.%s.%s.%s.byhost.%s.%s.%s:%.2f|ms\n",
segment += fmt.Sprintf("%s.%s.%s.byhost.%s.%s.%s:%.2f|ms\n",
pni[0], pni[1], pni[2], localIP, pni[3], "avg_time", m.Mean())

default:
Expand Down
2 changes: 1 addition & 1 deletion provider/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (h *HTTPProvider) Call(request motan.Request) motan.Response {
ErrMsg: fmt.Sprintf("%s", err), ErrType: http.StatusServiceUnavailable}
return resp
}
vlog.Infof("HTTPProvider read to call: Method:%s, URL:%s", httpReqMethod, httpReqURL)
//vlog.Infof("HTTPProvider read to call: Method:%s, URL:%s", httpReqMethod, httpReqURL)
queryStr := ""
if getQueryStr, err := buildQueryStr(request, h.url); err == nil {
queryStr = getQueryStr
Expand Down

0 comments on commit 188c528

Please sign in to comment.