internal MultiThreadedAverageValueStatistic(StatisticName name)
     : base(name)
 {
     totalSum = CounterStatistic.FindOrCreate(new StatisticName(String.Format("{0}.{1}", name.Name, "TotalSum.Hidden")), false, CounterStorage.DontStore);
     numItems = CounterStatistic.FindOrCreate(new StatisticName(String.Format("{0}.{1}", name.Name, "NumItems.Hidden")), false, CounterStorage.DontStore);
 }
示例#2
0
        private void AgentThreadProc()
        {
            var agent = this;

            if (agent == null)
            {
                throw new InvalidOperationException("Agent thread started with incorrect parameter type");
            }

            try
            {
                LogStatus(agent.Log, "Starting AsyncAgent {0} on managed thread {1}", agent.Name, Thread.CurrentThread.ManagedThreadId);
                CounterStatistic.SetOrleansManagedThread(); // do it before using CounterStatistic.
                CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.RUNTIME_THREADS_ASYNC_AGENT_PERAGENTTYPE, agent.type)).Increment();
                CounterStatistic.FindOrCreate(StatisticNames.RUNTIME_THREADS_ASYNC_AGENT_TOTAL_THREADS_CREATED).Increment();
                agent.Run();
            }
            catch (Exception exc)
            {
                if (agent.State == ThreadState.Running) // If we're stopping, ignore exceptions
                {
                    var log = agent.Log;
                    switch (agent.OnFault)
                    {
                    case FaultBehavior.CrashOnFault:
                        Console.WriteLine(
                            "The {0} agent has thrown an unhandled exception, {1}. The process will be terminated.",
                            agent.Name, exc);
                        log.Error(ErrorCode.Runtime_Error_100023,
                                  "AsynchAgent Run method has thrown an unhandled exception. The process will be terminated.",
                                  exc);
                        log.Fail(ErrorCode.Runtime_Error_100024, "Terminating process because of an unhandled exception caught in AsynchAgent.Run.");
                        break;

                    case FaultBehavior.IgnoreFault:
                        log.Error(ErrorCode.Runtime_Error_100025, "AsynchAgent Run method has thrown an unhandled exception. The agent will exit.",
                                  exc);
                        agent.State = ThreadState.Stopped;
                        break;

                    case FaultBehavior.RestartOnFault:
                        log.Error(ErrorCode.Runtime_Error_100026,
                                  "AsynchAgent Run method has thrown an unhandled exception. The agent will be restarted.",
                                  exc);
                        agent.State = ThreadState.Stopped;
                        try
                        {
                            agent.Start();
                        }
                        catch (Exception ex)
                        {
                            log.Error(ErrorCode.Runtime_Error_100027, "Unable to restart AsynchAgent", ex);
                            agent.State = ThreadState.Stopped;
                        }
                        break;
                    }
                }
            }
            finally
            {
                CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.RUNTIME_THREADS_ASYNC_AGENT_PERAGENTTYPE, agent.type)).DecrementBy(1);
                agent.Log.Info(ErrorCode.Runtime_Error_100328, "Stopping AsyncAgent {0} that runs on managed thread {1}", agent.Name, Thread.CurrentThread.ManagedThreadId);
            }
        }
示例#3
0
        internal static void Init(bool silo)
        {
            if (silo)
            {
                LocalMessagesSent    = CounterStatistic.FindOrCreate(StatisticNames.MESSAGING_SENT_LOCALMESSAGES);
                ConnectedClientCount = CounterStatistic.FindOrCreate(StatisticNames.GATEWAY_CONNECTED_CLIENTS, false);
            }

            MessagesSentTotal        = CounterStatistic.FindOrCreate(StatisticNames.MESSAGING_SENT_MESSAGES_TOTAL);
            MessagesSentPerDirection = new CounterStatistic[Enum.GetValues(typeof(Message.Directions)).Length];
            foreach (var direction in Enum.GetValues(typeof(Message.Directions)))
            {
                MessagesSentPerDirection[(int)direction] = CounterStatistic.FindOrCreate(
                    new StatisticName(StatisticNames.MESSAGING_SENT_MESSAGES_PER_DIRECTION, Enum.GetName(typeof(Message.Directions), direction)));
            }

            MessagesReceived             = CounterStatistic.FindOrCreate(StatisticNames.MESSAGING_RECEIVED_MESSAGES_TOTAL);
            MessagesReceivedPerDirection = new CounterStatistic[Enum.GetValues(typeof(Message.Directions)).Length];
            foreach (var direction in Enum.GetValues(typeof(Message.Directions)))
            {
                MessagesReceivedPerDirection[(int)direction] = CounterStatistic.FindOrCreate(
                    new StatisticName(StatisticNames.MESSAGING_RECEIVED_MESSAGES_PER_DIRECTION, Enum.GetName(typeof(Message.Directions), direction)));
            }

            TotalBytesSent      = CounterStatistic.FindOrCreate(StatisticNames.MESSAGING_SENT_BYTES_TOTAL);
            totalBytesReceived  = CounterStatistic.FindOrCreate(StatisticNames.MESSAGING_RECEIVED_BYTES_TOTAL);
            HeaderBytesSent     = CounterStatistic.FindOrCreate(StatisticNames.MESSAGING_SENT_BYTES_HEADER);
            headerBytesReceived = CounterStatistic.FindOrCreate(StatisticNames.MESSAGING_RECEIVED_BYTES_HEADER);
            FailedSentMessages  = new CounterStatistic[Enum.GetValues(typeof(Message.Directions)).Length];
            DroppedSentMessages = new CounterStatistic[Enum.GetValues(typeof(Message.Directions)).Length];
            RejectedMessages    = new CounterStatistic[Enum.GetValues(typeof(Message.Directions)).Length];

            ReroutedMessages = new CounterStatistic[Enum.GetValues(typeof(Message.Directions)).Length];
            foreach (var direction in Enum.GetValues(typeof(Message.Directions)))
            {
                ReroutedMessages[(int)direction] = CounterStatistic.FindOrCreate(
                    new StatisticName(StatisticNames.MESSAGING_REROUTED_PER_DIRECTION, Enum.GetName(typeof(Message.Directions), direction)));
            }

            sentMsgSizeHistogram    = ExponentialHistogramValueStatistic.Create_ExponentialHistogram(StatisticNames.MESSAGING_SENT_MESSAGESIZEHISTOGRAM, NUM_MSG_SIZE_HISTOGRAM_CATEGORIES);
            receiveMsgSizeHistogram = ExponentialHistogramValueStatistic.Create_ExponentialHistogram(StatisticNames.MESSAGING_RECEIVED_MESSAGESIZEHISTOGRAM, NUM_MSG_SIZE_HISTOGRAM_CATEGORIES);

            expiredAtSendCounter     = CounterStatistic.FindOrCreate(StatisticNames.MESSAGING_EXPIRED_ATSENDER);
            expiredAtReceiveCounter  = CounterStatistic.FindOrCreate(StatisticNames.MESSAGING_EXPIRED_ATRECEIVER);
            expiredAtDispatchCounter = CounterStatistic.FindOrCreate(StatisticNames.MESSAGING_EXPIRED_ATDISPATCH);
            expiredAtInvokeCounter   = CounterStatistic.FindOrCreate(StatisticNames.MESSAGING_EXPIRED_ATINVOKE);
            expiredAtRespondCounter  = CounterStatistic.FindOrCreate(StatisticNames.MESSAGING_EXPIRED_ATRESPOND);

            perSocketDirectionStatsSend    = new PerSocketDirectionStats[Enum.GetValues(typeof(SocketDirection)).Length];
            perSocketDirectionStatsReceive = new PerSocketDirectionStats[Enum.GetValues(typeof(SocketDirection)).Length];
            if (silo)
            {
                perSocketDirectionStatsSend[(int)SocketDirection.SiloToSilo]         = new PerSocketDirectionStats(true, SocketDirection.SiloToSilo);
                perSocketDirectionStatsSend[(int)SocketDirection.GatewayToClient]    = new PerSocketDirectionStats(true, SocketDirection.GatewayToClient);
                perSocketDirectionStatsReceive[(int)SocketDirection.SiloToSilo]      = new PerSocketDirectionStats(false, SocketDirection.SiloToSilo);
                perSocketDirectionStatsReceive[(int)SocketDirection.GatewayToClient] = new PerSocketDirectionStats(false, SocketDirection.GatewayToClient);
            }
            else
            {
                perSocketDirectionStatsSend[(int)SocketDirection.ClientToGateway]    = new PerSocketDirectionStats(true, SocketDirection.ClientToGateway);
                perSocketDirectionStatsReceive[(int)SocketDirection.ClientToGateway] = new PerSocketDirectionStats(false, SocketDirection.ClientToGateway);
            }

            perSiloSendCounters              = new ConcurrentDictionary <string, CounterStatistic>();
            perSiloReceiveCounters           = new ConcurrentDictionary <string, CounterStatistic>();
            perSiloPingSendCounters          = new ConcurrentDictionary <string, CounterStatistic>();
            perSiloPingReceiveCounters       = new ConcurrentDictionary <string, CounterStatistic>();
            perSiloPingReplyReceivedCounters = new ConcurrentDictionary <string, CounterStatistic>();
            perSiloPingReplyMissedCounters   = new ConcurrentDictionary <string, CounterStatistic>();
        }