mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-14 07:34:43 +08:00
增加DB和HTTP调用时间
This commit is contained in:
@@ -33,9 +33,9 @@ type ControllerMapsType map[string]reflect.Value
|
||||
|
||||
type HttpServerService struct {
|
||||
service.BaseService
|
||||
httpserver network.HttpServer
|
||||
port uint16
|
||||
|
||||
httpserver network.HttpServer
|
||||
port uint16
|
||||
PrintRequestTime bool
|
||||
controllerMaps ControllerMapsType
|
||||
certfile string
|
||||
keyfile string
|
||||
@@ -48,7 +48,6 @@ func (slf *HttpServerService) OnInit() error {
|
||||
if slf.ishttps == true {
|
||||
slf.httpserver.SetHttps(slf.certfile, slf.keyfile)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -89,7 +88,6 @@ func (slf *HttpServerService) OnDestory() error {
|
||||
}
|
||||
|
||||
func (slf *HttpServerService) OnSetupService(iservice service.IService) {
|
||||
//
|
||||
rpc.RegisterName(iservice.GetServiceName(), "HTTP_", iservice)
|
||||
}
|
||||
|
||||
@@ -97,6 +95,19 @@ func (slf *HttpServerService) OnRemoveService(iservice service.IService) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
func (slf *HttpServerService) IsPrintRequestTime() bool {
|
||||
if slf.PrintRequestTime == true {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
}
|
||||
|
||||
func (slf *HttpServerService) SetPrintRequestTime(isPrint bool) {
|
||||
slf.PrintRequestTime = isPrint
|
||||
}
|
||||
|
||||
func (slf *HttpServerService) httpHandler(w http.ResponseWriter, r *http.Request) {
|
||||
writeError := func(status int, msg string) {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
@@ -142,7 +153,14 @@ func (slf *HttpServerService) httpHandler(w http.ResponseWriter, r *http.Request
|
||||
request := HttpRequest{r.Header, string(msg)}
|
||||
var resp HttpRespone
|
||||
|
||||
TimeFuncStart := time.Now()
|
||||
err = cluster.InstanceClusterMgr().Call(strCallPath, &request, &resp)
|
||||
|
||||
TimeFuncPass := time.Since(TimeFuncStart)
|
||||
if slf.IsPrintRequestTime() {
|
||||
service.GetLogger().Printf(service.LEVER_INFO, "HttpServer Time : %s IP : %S url : %s", TimeFuncPass, strCallPath)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json;charset=utf-8")
|
||||
if err != nil {
|
||||
resp.Respone = []byte(fmt.Sprint(err))
|
||||
|
||||
Reference in New Issue
Block a user