示例#1
0
        ServerProcessing IServerChannelSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)
        {
            long   startTicks  = TimeUtil.NOW();
            string uri         = null;
            long   inputLength = 0L;

            if (requestStream != null && requestHeaders != null)
            {
                uri = requestHeaders["__RequestUri"].ToString();
            }
            ServerProcessing process = this.nextSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream);

            if (null != responseMsg)
            {
                object methodName = responseMsg.Properties["__MethodName"];
                if (uri != null && methodName != null)
                {
                    string cmdName = uri.ToString() + methodName.ToString();
                    CmdMonitor.RecordCmdDetail(cmdName, TimeUtil.NOW() - startTicks, inputLength, responseStream.Length, TCPProcessCmdResults.RESULT_OK);
                }
                else
                {
                    LogManager.WriteExceptionUseCache(string.Format("IServerChannelSink.ProcessMessage#uri={0},methodName={1}", uri, methodName));
                }
            }
            else
            {
                LogManager.WriteExceptionUseCache(string.Format("IServerChannelSink.ProcessMessage#uri={0},responseMsg=null", uri));
            }
            return(process);
        }
示例#2
0
 public void BeforeSendReply(ref Message reply, object correlationState)
 {
     MessageInspector.cmdInfo cmd = (MessageInspector.cmdInfo)correlationState;
     if (null != cmd)
     {
         CmdMonitor.RecordCmdDetail(cmd.cmdName, TimeUtil.NOW() - cmd.receiveTicks, (long)cmd.cmdSize, TCPProcessCmdResults.RESULT_OK);
     }
 }
示例#3
0
 static CmdMonitor()
 {
     CmdMonitor.Reset();
 }
示例#4
0
 public static void ShowServerTCPInfo(object obj)
 {
     try
     {
         string[] cmd    = obj as string[];
         bool     clear  = cmd.Contains("/c");
         bool     detail = cmd.Contains("/d");
         DateTime now    = TimeUtil.NowDateTime();
         SysConOut.WriteLine(string.Format("当前时间:{0},统计时长:{1}", now.ToString("yyyy-MM-dd HH:mm:ss"), (now - CmdMonitor.StartTime).ToString()));
         if (clear)
         {
             detail = true;
             CmdMonitor.StartTime = now;
         }
         SysConOut.WriteLine(string.Format("总处理指令个数 {0}", CmdMonitor.TotalHandledCmdsNum));
         SysConOut.WriteLine(string.Format("指令处理耗时详情", new object[0]));
         try
         {
             if (detail)
             {
                 if (Console.WindowWidth < 160)
                 {
                     Console.WindowWidth = 160;
                 }
             }
             else if (Console.WindowWidth >= 88)
             {
                 Console.WindowWidth = 88;
             }
         }
         catch
         {
         }
         int count = 0;
         lock (CmdMonitor.mutex)
         {
             foreach (PorcessCmdMoniter i in CmdMonitor.cmdMoniter)
             {
                 if (i.processNum != 0)
                 {
                     Console.ForegroundColor = count % 5 + ConsoleColor.Green;
                     if (detail)
                     {
                         if (count++ == 0)
                         {
                             SysConOut.WriteLine(string.Format("{0, -48}{1, 6}{2, 7}{3, 7} {4, 7} {5, 4} {6, 4} {7, 5}", new object[]
                             {
                                 "消息",
                                 "已处理次数",
                                 "平均处理时长",
                                 "总计消耗时长",
                                 "总计字节数",
                                 "发送次数",
                                 "发送字节数",
                                 "失败/成功/数据"
                             }));
                         }
                         string info = string.Format("{0, -50}{1, 11}{2, 13:0.##}{3, 13:0.##} {4, 13:0.##} {5, 8} {6, 12} {7, 4}/{8}/{9}", new object[]
                         {
                             CmdMonitor.GetCmdName(i),
                             i.processNum,
                             TimeUtil.TimeMS(i.avgProcessTime(), 2),
                             TimeUtil.TimeMS(i.processTotalTime, 2),
                             i.GetTotalBytes(),
                             i.SendNum,
                             i.OutPutBytes,
                             i.Num_Faild,
                             i.Num_OK,
                             i.Num_WithData
                         });
                         SysConOut.WriteLine(info);
                     }
                     else
                     {
                         if (count++ == 0)
                         {
                             SysConOut.WriteLine(string.Format("{0, -48}{1, 6}{2, 7}{3, 7}", new object[]
                             {
                                 "消息",
                                 "已处理次数",
                                 "平均处理时长",
                                 "总计消耗时长"
                             }));
                         }
                         string info = string.Format("{0, -50}{1, 11}{2, 13:0.##}{3, 13:0.##}", new object[]
                         {
                             CmdMonitor.GetCmdName(i),
                             i.processNum,
                             TimeUtil.TimeMS(i.avgProcessTime(), 2),
                             TimeUtil.TimeMS(i.processTotalTime, 2)
                         });
                         SysConOut.WriteLine(info);
                     }
                     if (clear)
                     {
                         i.Reset();
                     }
                 }
             }
             Console.ForegroundColor = ConsoleColor.White;
         }
     }
     catch (Exception ex)
     {
         LogManager.WriteException(ex.ToString());
     }
 }