ServerSummary IWorkItem.CollectServerSummary(NodeSummary nodeSummary)
        {
            if (m_AppServer == null)
            {
                var stoppedSummary = GetStoppedSummary();
                stoppedSummary.CollectedTime = DateTime.Now;
                return stoppedSummary;
            }

            var currentSummary = m_AppServer.CollectServerSummary(nodeSummary);
            m_PrevSummary = currentSummary;
            return currentSummary;
        }
예제 #2
0
        private void OnPerformanceTimerCallback(object state)
        {
            int availableWorkingThreads, availableCompletionPortThreads;
            ThreadPool.GetAvailableThreads(out availableWorkingThreads, out availableCompletionPortThreads);

            int maxWorkingThreads;
            int maxCompletionPortThreads;
            ThreadPool.GetMaxThreads(out maxWorkingThreads, out maxCompletionPortThreads);

            var globalPerfData = new NodeSummary
            {
                AvailableWorkingThreads = availableWorkingThreads,
                AvailableCompletionPortThreads = availableCompletionPortThreads,
                MaxCompletionPortThreads = maxCompletionPortThreads,
                MaxWorkingThreads = maxWorkingThreads,
                CpuUsage = m_CpuUsagePC.NextValue() / m_CpuCores,
                TotalThreadCount = (int)m_ThreadCountPC.NextValue(),
                WorkingSet = (long)m_WorkingSetPC.NextValue()
            };

            var perfBuilder = new StringBuilder();

            perfBuilder.AppendLine("---------------------------------------------------");
            perfBuilder.AppendLine(string.Format("CPU Usage: {0}%, Physical Memory Usage: {1:N}, Total Thread Count: {2}", globalPerfData.CpuUsage.ToString("0.00"), globalPerfData.WorkingSet, globalPerfData.TotalThreadCount));
            perfBuilder.AppendLine(string.Format("AvailableWorkingThreads: {0}, AvailableCompletionPortThreads: {1}", globalPerfData.AvailableWorkingThreads, globalPerfData.AvailableCompletionPortThreads));
            perfBuilder.AppendLine(string.Format("MaxWorkingThreads: {0}, MaxCompletionPortThreads: {1}", globalPerfData.MaxWorkingThreads, globalPerfData.MaxCompletionPortThreads));

            for (var i = 0; i < m_AppServers.Length; i++)
            {
                var s = m_AppServers[i];

                var serverState = s.CollectServerSummary(globalPerfData);
                var stateTypeMetadata = GetSummaryTypeMetatdata(serverState.GetType());

                perfBuilder.AppendLine(string.Format("{0} ----------------------------------", s.Name));

                for (var j = 0; j < stateTypeMetadata.Count; j++)
                {
                    var property = stateTypeMetadata[j];
                    if (!string.IsNullOrEmpty(property.Value.Format))
                        perfBuilder.AppendLine(string.Format("{0}: {1}", property.Value.Name, string.Format(property.Value.Format, property.Key.GetValue(serverState, m_ParaArray))));
                    else
                        perfBuilder.AppendLine(string.Format("{0}: {1}", property.Value.Name, property.Key.GetValue(serverState, m_ParaArray)));
                }
            }

            m_PerfLog.Info(perfBuilder.ToString());
        }
예제 #3
0
 /// <summary>
 /// Collects the server summary.
 /// </summary>
 /// <param name="nodeSummary">The node summary.</param>
 /// <returns></returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public ServerSummary CollectServerSummary(NodeSummary nodeSummary)
 {
     return m_AppServer.CollectServerSummary(nodeSummary);
 }
        private void OnPerformanceTimerCallback(object state)
        {
            int availableWorkingThreads, availableCompletionPortThreads;
            ThreadPool.GetAvailableThreads(out availableWorkingThreads, out availableCompletionPortThreads);

            int maxWorkingThreads;
            int maxCompletionPortThreads;
            ThreadPool.GetMaxThreads(out maxWorkingThreads, out maxCompletionPortThreads);

            NodeSummary globalPerfData = null;

            var retry = false;

            while(true)
            {
                try
                {
                    globalPerfData = new NodeSummary
                    {
                        AvailableWorkingThreads = availableWorkingThreads,
                        AvailableCompletionPortThreads = availableCompletionPortThreads,
                        MaxCompletionPortThreads = maxCompletionPortThreads,
                        MaxWorkingThreads = maxWorkingThreads,
                        CpuUsage = m_CpuUsagePC.NextValue() / m_CpuCores,
                        TotalThreadCount = (int)m_ThreadCountPC.NextValue(),
                        WorkingSet = (long)m_WorkingSetPC.NextValue()
                    };

                    break;
                }
                catch (InvalidOperationException e)
                {
                    //Only re-get performance counter one time
                    if (retry)
                        throw e;

                    //Only re-get performance counter for .NET/Windows
                    if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX || Platform.IsMono)
                        throw e;

                    //If a same name process exited, this process's performance counters instance name could be changed,
                    //so if the old performance counter cannot be access, get the performance counter's name again
                    var newInstanceName = GetPerformanceCounterInstanceName(Process.GetCurrentProcess());
                    SetupPerformanceCounters(newInstanceName);
                    retry = true;
                }
            }

            var perfBuilder = new StringBuilder();

            perfBuilder.AppendLine("---------------------------------------------------");
            perfBuilder.AppendLine(string.Format("CPU Usage: {0}%, Physical Memory Usage: {1:N}, Total Thread Count: {2}", globalPerfData.CpuUsage.ToString("0.00"), globalPerfData.WorkingSet, globalPerfData.TotalThreadCount));
            perfBuilder.AppendLine(string.Format("AvailableWorkingThreads: {0}, AvailableCompletionPortThreads: {1}", globalPerfData.AvailableWorkingThreads, globalPerfData.AvailableCompletionPortThreads));
            perfBuilder.AppendLine(string.Format("MaxWorkingThreads: {0}, MaxCompletionPortThreads: {1}", globalPerfData.MaxWorkingThreads, globalPerfData.MaxCompletionPortThreads));

            for (var i = 0; i < m_AppServers.Length; i++)
            {
                var s = m_AppServers[i];

                var serverState = s.CollectServerSummary(globalPerfData);
                var stateTypeMetadata = GetSummaryTypeMetatdata(serverState.GetType());

                perfBuilder.AppendLine(string.Format("{0} ----------------------------------", s.Name));

                for (var j = 0; j < stateTypeMetadata.Count; j++)
                {
                    var property = stateTypeMetadata[j];
                    if (!string.IsNullOrEmpty(property.Value.Format))
                        perfBuilder.AppendLine(string.Format("{0}: {1}", property.Value.Name, string.Format(property.Value.Format, property.Key.GetValue(serverState, m_ParaArray))));
                    else
                        perfBuilder.AppendLine(string.Format("{0}: {1}", property.Value.Name, property.Key.GetValue(serverState, m_ParaArray)));
                }
            }

            m_PerfLog.Info(perfBuilder.ToString());
        }
예제 #5
0
 ServerSummary IWorkItem.CollectServerSummary(NodeSummary nodeSummary)
 {
     return m_AppServer.CollectServerSummary(nodeSummary);   
 }