From d15dd2795c962b9fc7c5e55e1c7ff7ebdeddce44 Mon Sep 17 00:00:00 2001 From: Gerson Alexander Pardo Gamez Date: Sat, 3 Jun 2017 15:24:45 -0500 Subject: [PATCH 1/3] added statusCode in FilterMonitorFunc --- admin.go | 6 +++--- router.go | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/admin.go b/admin.go index 875cd0e8..8d28c10c 100644 --- a/admin.go +++ b/admin.go @@ -37,7 +37,7 @@ var beeAdminApp *adminApp // FilterMonitorFunc is default monitor filter when admin module is enable. // if this func returns, admin module records qbs for this request by condition of this function logic. // usage: -// func MyFilterMonitor(method, requestPath string, t time.Duration) bool { +// func MyFilterMonitor(method, requestPath string, t time.Duration, statusCode int) bool { // if method == "POST" { // return false // } @@ -50,7 +50,7 @@ var beeAdminApp *adminApp // return true // } // beego.FilterMonitorFunc = MyFilterMonitor. -var FilterMonitorFunc func(string, string, time.Duration) bool +var FilterMonitorFunc func(string, string, time.Duration, int) bool func init() { beeAdminApp = &adminApp{ @@ -62,7 +62,7 @@ func init() { beeAdminApp.Route("/healthcheck", healthcheck) beeAdminApp.Route("/task", taskStatus) beeAdminApp.Route("/listconf", listConf) - FilterMonitorFunc = func(string, string, time.Duration) bool { return true } + FilterMonitorFunc = func(string, string, time.Duration, int) bool { return true } } // AdminIndex is the default http.Handler for admin module. diff --git a/router.go b/router.go index 72476ae8..c6da4f9b 100644 --- a/router.go +++ b/router.go @@ -849,7 +849,11 @@ Admin: //admin module record QPS if BConfig.Listen.EnableAdmin { timeDur := time.Since(startTime) - if FilterMonitorFunc(r.Method, r.URL.Path, timeDur) { + statusCode := context.ResponseWriter.Status + if statusCode == 0 { + statusCode = 200 + } + if FilterMonitorFunc(r.Method, r.URL.Path, timeDur, statusCode) { if runRouter != nil { go toolbox.StatisticsMap.AddStatistics(r.Method, r.URL.Path, runRouter.Name(), timeDur) } else { From 7f2e3feb3c485cebd5b8c6ee309884160d6cad37 Mon Sep 17 00:00:00 2001 From: Gerson Alexander Pardo Gamez Date: Mon, 5 Jun 2017 18:21:31 -0500 Subject: [PATCH 2/3] added pattern to FilterMonitorFunc --- admin.go | 4 ++-- router.go | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/admin.go b/admin.go index 8d28c10c..e6f9c3f9 100644 --- a/admin.go +++ b/admin.go @@ -50,7 +50,7 @@ var beeAdminApp *adminApp // return true // } // beego.FilterMonitorFunc = MyFilterMonitor. -var FilterMonitorFunc func(string, string, time.Duration, int) bool +var FilterMonitorFunc func(string, string, time.Duration, string, int) bool func init() { beeAdminApp = &adminApp{ @@ -62,7 +62,7 @@ func init() { beeAdminApp.Route("/healthcheck", healthcheck) beeAdminApp.Route("/task", taskStatus) beeAdminApp.Route("/listconf", listConf) - FilterMonitorFunc = func(string, string, time.Duration, int) bool { return true } + FilterMonitorFunc = func(string, string, time.Duration, string, int) bool { return true } } // AdminIndex is the default http.Handler for admin module. diff --git a/router.go b/router.go index c6da4f9b..874fb109 100644 --- a/router.go +++ b/router.go @@ -849,11 +849,15 @@ Admin: //admin module record QPS if BConfig.Listen.EnableAdmin { timeDur := time.Since(startTime) + pattern := "" + if routerInfo != nil { + pattern = routerInfo.pattern + } statusCode := context.ResponseWriter.Status if statusCode == 0 { statusCode = 200 } - if FilterMonitorFunc(r.Method, r.URL.Path, timeDur, statusCode) { + if FilterMonitorFunc(r.Method, r.URL.Path, timeDur, pattern, statusCode) { if runRouter != nil { go toolbox.StatisticsMap.AddStatistics(r.Method, r.URL.Path, runRouter.Name(), timeDur) } else { From c903de41e404aad3ee5501d2af0c4ce36a0bcee9 Mon Sep 17 00:00:00 2001 From: Gerson Alexander Pardo Gamez Date: Wed, 12 Jul 2017 09:51:37 -0500 Subject: [PATCH 3/3] updated sample for FilterMonitorFunc added pattern to sample --- admin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin.go b/admin.go index e6f9c3f9..0688dcbc 100644 --- a/admin.go +++ b/admin.go @@ -37,7 +37,7 @@ var beeAdminApp *adminApp // FilterMonitorFunc is default monitor filter when admin module is enable. // if this func returns, admin module records qbs for this request by condition of this function logic. // usage: -// func MyFilterMonitor(method, requestPath string, t time.Duration, statusCode int) bool { +// func MyFilterMonitor(method, requestPath string, t time.Duration, pattern string, statusCode int) bool { // if method == "POST" { // return false // }