Exemplo n.º 1
0
 private void MakeStat(string pName, string pUnitName, Action<Stat> act)
 {
     Stat tempStat = new Stat(pName, pName, pName, pUnitName, "scene", m_scene.RegionInfo.RegionName, StatType.Pull, act, StatVerbosity.Info);
     StatsManager.RegisterStat(tempStat);
     registeredStats.Add(tempStat);
 }
Exemplo n.º 2
0
        public virtual void AddRegion(Scene scene)
        {
            if (!m_Enabled)
                return;

            Scene = scene;

            m_interRegionTeleportAttempts = 
                new Stat(
                    "InterRegionTeleportAttempts",
                    "Number of inter-region teleports attempted.",
                    "This does not count attempts which failed due to pre-conditions (e.g. target simulator refused access).\n"
                        + "You can get successfully teleports by subtracting aborts, cancels and teleport failures from this figure.",
                    "",
                    "entitytransfer",
                    Scene.Name,
                    StatType.Push,
                    null,
                    StatVerbosity.Debug);

            m_interRegionTeleportAborts = 
                new Stat(
                    "InterRegionTeleportAborts",
                    "Number of inter-region teleports aborted due to client actions.",
                    "The chief action is simultaneous logout whilst teleporting.",
                    "",
                    "entitytransfer",
                    Scene.Name,
                    StatType.Push,
                    null,
                    StatVerbosity.Debug);

            m_interRegionTeleportCancels = 
                new Stat(
                    "InterRegionTeleportCancels",
                    "Number of inter-region teleports cancelled by the client.",
                    null,
                    "",
                    "entitytransfer",
                    Scene.Name,
                    StatType.Push,
                    null,
                    StatVerbosity.Debug);

            m_interRegionTeleportFailures = 
                new Stat(
                    "InterRegionTeleportFailures",
                    "Number of inter-region teleports that failed due to server/client/network issues.",
                    "This number may not be very helpful in open-grid/hg situations as the network connectivity/quality of destinations is uncontrollable.",
                    "",
                    "entitytransfer",
                    Scene.Name,
                    StatType.Push,
                    null,
                    StatVerbosity.Debug);

            StatsManager.RegisterStat(m_interRegionTeleportAttempts);
            StatsManager.RegisterStat(m_interRegionTeleportAborts);
            StatsManager.RegisterStat(m_interRegionTeleportCancels);
            StatsManager.RegisterStat(m_interRegionTeleportFailures);

            scene.RegisterModuleInterface<IEntityTransferModule>(this);
            scene.EventManager.OnNewClient += OnNewClient;
        }
Exemplo n.º 3
0
        /// <summary>
        /// This is a seperate method so that it can be called once we have an m_scene to distinguish different scene
        /// stats.
        /// </summary>
        private void EnablePoolStats()
        {
            m_poolCountStat
                = new Stat(
                    "UDPPacketBufferPoolCount",
                    "Objects within the UDPPacketBuffer pool",
                    "The number of objects currently stored within the UDPPacketBuffer pool",
                    "",
                    "clientstack",
                    m_scene.Name,
                    StatType.Pull,
                    stat => stat.Value = Pool.Count,
                    StatVerbosity.Debug);

            StatsManager.RegisterStat(m_poolCountStat);

            m_incomingPacketPoolStat
                = new Stat(
                    "IncomingPacketPoolCount",
                    "Objects within incoming packet pool",
                    "The number of objects currently stored within the incoming packet pool",
                    "",
                    "clientstack",
                    m_scene.Name,
                    StatType.Pull,
                    stat => stat.Value = m_incomingPacketPool.Count,
                    StatVerbosity.Debug);

            StatsManager.RegisterStat(m_incomingPacketPoolStat);
        }
Exemplo n.º 4
0
        public SimStatsReporter(Scene scene)
        {
            m_scene = scene;
            m_reportedFpsCorrectionFactor = scene.MinFrameTime * m_nominalReportedFps;
            m_statsUpdateFactor = (float)(m_statsUpdatesEveryMS / 1000);
            ReportingRegion = scene.RegionInfo;

            m_objectCapacity = scene.RegionInfo.ObjectCapacity;
            m_report.AutoReset = true;
            m_report.Interval = m_statsUpdatesEveryMS;
            m_report.Elapsed += TriggerStatsHeartbeat;
            m_report.Enabled = true;

            if (StatsManager.SimExtraStats != null)
                OnSendStatsResult += StatsManager.SimExtraStats.ReceiveClassicSimStatsPacket;

            /// At the moment, we'll only report if a frame is over 120% of target, since commonly frames are a bit
            /// longer than ideal (which in itself is a concern).
            SlowFramesStatReportThreshold = (int)Math.Ceiling(m_scene.MinFrameTime * 1000 * 1.2);

            SlowFramesStat
                = new Stat(
                    "SlowFrames",
                    "Slow Frames",
                    "Number of frames where frame time has been significantly longer than the desired frame time.",
                    " frames",
                    "scene",
                    m_scene.Name,
                    StatType.Push,
                    null,
                    StatVerbosity.Info);

            StatsManager.RegisterStat(SlowFramesStat);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Disables pool stats.
        /// </summary>
        protected internal void DisablePoolStats()
        {
            StatsManager.DeregisterStat(m_poolCountStat);
            m_poolCountStat = null;

            StatsManager.DeregisterStat(m_incomingPacketPoolStat);
            m_incomingPacketPoolStat = null;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Registers a statistic.
        /// </summary>
        /// <param name='stat'></param>
        /// <returns></returns>
        public static bool RegisterStat(Stat stat)
        {
            SortedDictionary<string, SortedDictionary<string, Stat>> category = null, newCategory;
            SortedDictionary<string, Stat> container = null, newContainer;

            lock (RegisteredStats)
            {
                // Stat name is not unique across category/container/shortname key.
                // XXX: For now just return false.  This is to avoid problems in regression tests where all tests
                // in a class are run in the same instance of the VM.
                if (TryGetStat(stat, out category, out container))
                    return false;

                // We take a copy-on-write approach here of replacing dictionaries when keys are added or removed.
                // This means that we don't need to lock or copy them on iteration, which will be a much more
                // common operation after startup.
                if (container != null)
                    newContainer = new SortedDictionary<string, Stat>(container);
                else
                    newContainer = new SortedDictionary<string, Stat>();

                if (category != null)
                    newCategory = new SortedDictionary<string, SortedDictionary<string, Stat>>(category);
                else
                    newCategory = new SortedDictionary<string, SortedDictionary<string, Stat>>();

                newContainer[stat.ShortName] = stat;
                newCategory[stat.Container] = newContainer;
                RegisteredStats[stat.Category] = newCategory;
            }

            return true;
        }
Exemplo n.º 7
0
        public static bool TryGetStat(
            Stat stat,
            out SortedDictionary<string, SortedDictionary<string, Stat>> category,
            out SortedDictionary<string, Stat> container)
        {
            category = null;
            container = null;

            lock (RegisteredStats)
            {
                if (RegisteredStats.TryGetValue(stat.Category, out category))
                {
                    if (category.TryGetValue(stat.Container, out container))
                    {
                        if (container.ContainsKey(stat.ShortName))
                            return true;
                    }
                }
            }

            return false;
        }
Exemplo n.º 8
0
 private void GetNextValue(Stat stat, PerfCounterControl perfControl)
 {
     GetNextValue(stat, perfControl, 1.0);
 }
Exemplo n.º 9
0
 private void GetNextValue(Stat stat, PerfCounterControl perfControl, double factor)
 {
     if (Util.EnvironmentTickCountSubtract(perfControl.lastFetch) > performanceCounterSampleInterval)
     {
         if (perfControl != null && perfControl.perfCounter != null)
         {
             try
             {
                 // Kludge for factor to run double duty. If -1, subtract the value from one
                 if (factor == -1)
                     stat.Value = 1 - perfControl.perfCounter.NextValue();
                 else
                     stat.Value = perfControl.perfCounter.NextValue() / factor;
             }
             catch (Exception e)
             {
                 m_log.ErrorFormat("{0} Exception on NextValue fetching {1}: {2}", LogHeader, stat.Name, e);
             }
             perfControl.lastFetch = Util.EnvironmentTickCount();
         }
     }
 }
Exemplo n.º 10
0
 private void MakeStat(string pName, string pUnit, string pContainer, Action<Stat> act)
 {
     Stat stat = new Stat(pName, pName, "", pUnit, CategoryServer, pContainer, StatType.Pull, act, StatVerbosity.Info);
     StatsManager.RegisterStat(stat);
     RegisteredStats.Add(pName, stat);
 }
Exemplo n.º 11
0
    public void RegisterServerStats()
    {
        lastperformanceCounterSampleTime = Util.EnvironmentTickCount();
        PerformanceCounter tempPC;
        Stat tempStat;
        string tempName;

        try
        {
            tempName = "CPUPercent";
            tempPC = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            processorPercentPerfCounter = new PerfCounterControl(tempPC);
            // A long time bug in mono is that CPU percent is reported as CPU percent idle. Windows reports CPU percent busy.
            tempStat = new Stat(tempName, tempName, "", "percent", CategoryServer, ContainerProcessor,
                            StatType.Pull, (s) => { GetNextValue(s, processorPercentPerfCounter, Util.IsWindows() ? 1 : -1); },
                            StatVerbosity.Info);
            StatsManager.RegisterStat(tempStat);
            RegisteredStats.Add(tempName, tempStat);

            MakeStat("TotalProcessorTime", "sec", ContainerProcessor, 
                                (s) => { s.Value = Process.GetCurrentProcess().TotalProcessorTime.TotalSeconds; });

            MakeStat("UserProcessorTime", "sec", ContainerProcessor,
                                (s) => { s.Value = Process.GetCurrentProcess().UserProcessorTime.TotalSeconds; });

            MakeStat("PrivilegedProcessorTime", "sec", ContainerProcessor,
                                (s) => { s.Value = Process.GetCurrentProcess().PrivilegedProcessorTime.TotalSeconds; });

            MakeStat("Threads", "threads", ContainerProcessor,
                                (s) => { s.Value = Process.GetCurrentProcess().Threads.Count; });
        }
        catch (Exception e)
        {
            m_log.ErrorFormat("{0} Exception creating 'Process': {1}", LogHeader, e);
        }

        try
        {
            List<string> okInterfaceTypes = new List<string>(NetworkInterfaceTypes.Split(','));

            IEnumerable<NetworkInterface> nics = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface nic in nics)
            {
                if (nic.OperationalStatus != OperationalStatus.Up)
                    continue;

                string nicInterfaceType = nic.NetworkInterfaceType.ToString();
                if (!okInterfaceTypes.Contains(nicInterfaceType))
                {
                    m_log.DebugFormat("{0} Not including stats for network interface '{1}' of type '{2}'. To include, add to [Monitoring]NetworkInterfaceTypes='Ethernet,Loopback'",
                                            LogHeader, nic.Name, nicInterfaceType);
                    continue;
                }

                if (nic.Supports(NetworkInterfaceComponent.IPv4))
                {
                    IPv4InterfaceStatistics nicStats = nic.GetIPv4Statistics();
                    if (nicStats != null)
                    {
                        MakeStat("BytesRcvd/" + nic.Name, "KB", ContainerNetwork,
                                        (s) => { LookupNic(s, (ns) => { return ns.BytesReceived; }, 1024.0); });
                        MakeStat("BytesSent/" + nic.Name, "KB", ContainerNetwork,
                                        (s) => { LookupNic(s, (ns) => { return ns.BytesSent; }, 1024.0); });
                        MakeStat("TotalBytes/" + nic.Name, "KB", ContainerNetwork,
                                        (s) => { LookupNic(s, (ns) => { return ns.BytesSent + ns.BytesReceived; }, 1024.0); });
                    }
                }
            }
        }
        catch (Exception e)
        {
            m_log.ErrorFormat("{0} Exception creating 'Network Interface': {1}", LogHeader, e);
        }

        MakeStat("ProcessMemory", "MB", ContainerMemory,
                            (s) => { s.Value = Process.GetCurrentProcess().WorkingSet64 / 1024d / 1024d; });
        MakeStat("ObjectMemory", "MB", ContainerMemory,
                            (s) => { s.Value = GC.GetTotalMemory(false) / 1024d / 1024d; });
        MakeStat("LastMemoryChurn", "MB/sec", ContainerMemory,
                            (s) => { s.Value = Math.Round(MemoryWatchdog.LastMemoryChurn * 1000d / 1024d / 1024d, 3); });
        MakeStat("AverageMemoryChurn", "MB/sec", ContainerMemory,
                            (s) => { s.Value = Math.Round(MemoryWatchdog.AverageMemoryChurn * 1000d / 1024d / 1024d, 3); });
    }
Exemplo n.º 12
0
        protected virtual bool EnablePools()
        {
            if (!UsePools)
            {
                m_pool = new Pool<UDPPacketBuffer>(() => new UDPPacketBuffer(), 500);

                m_poolCountStat
                    = new Stat(
                        "UDPPacketBufferPoolCount",
                        "Objects within the UDPPacketBuffer pool",
                        "The number of objects currently stored within the UDPPacketBuffer pool",
                        "",
                        "clientstack",
                        "packetpool",
                        StatType.Pull,
                        stat => stat.Value = m_pool.Count,
                        StatVerbosity.Debug);

                StatsManager.RegisterStat(m_poolCountStat);

                UsePools = true;

                return true;
            }

            return false;
        }
        public void Start()
        {
            lock (this)
            {
                if (IsRunning)
                    return;

                IsRunning = true;

                m_finishedProcessingAfterStop.Reset();

                m_requestQueue = new BlockingCollection<RefillRequest>(new ConcurrentQueue<RefillRequest>(), 5000);

                m_oqreRequestsWaitingStat = 
                    new Stat(
                        "OQRERequestsWaiting",
                        "Number of outgong queue refill requests waiting for processing.",
                        "",
                        "",
                        "clientstack",
                        m_udpServer.Scene.Name,
                        StatType.Pull,
                        MeasuresOfInterest.None,
                        stat => stat.Value = m_requestQueue.Count,
                        StatVerbosity.Debug);

                StatsManager.RegisterStat(m_oqreRequestsWaitingStat);

                Watchdog.StartThread(
                    ProcessRequests,
                    String.Format("OutgoingQueueRefillEngineThread ({0})", m_udpServer.Scene.Name),
                    ThreadPriority.Normal,
                    false,
                    true,
                    null,
                    int.MaxValue);
            }
        }
        public void Stop()
        {   
            lock (this)
            {
                try
                {
                    if (!IsRunning)
                        return;

                    IsRunning = false;

                    int requestsLeft = m_requestQueue.Count;

                    if (requestsLeft <= 0)
                    {
                        m_cancelSource.Cancel();
                    }
                    else 
                    {
                        m_log.InfoFormat("[OUTGOING QUEUE REFILL ENGINE]: Waiting to write {0} events after stop.", requestsLeft);

                        while (requestsLeft > 0)
                        {
                            if (!m_finishedProcessingAfterStop.WaitOne(RequestProcessTimeoutOnStop))
                            {
                                // After timeout no events have been written
                                if (requestsLeft == m_requestQueue.Count)
                                {
                                    m_log.WarnFormat(
                                        "[OUTGOING QUEUE REFILL ENGINE]: No requests processed after {0} ms wait.  Discarding remaining {1} requests", 
                                        RequestProcessTimeoutOnStop, requestsLeft);

                                    break;
                                }
                            }

                            requestsLeft = m_requestQueue.Count;
                        }
                    }
                }
                finally
                {
                    m_cancelSource.Dispose();
                    StatsManager.DeregisterStat(m_oqreRequestsWaitingStat);
                    m_oqreRequestsWaitingStat = null;
                    m_requestQueue = null;
                }
            }
        }
Exemplo n.º 15
0
 private static void OutputStatToConsole(ICommandConsole con, Stat stat)
 {
     con.Output(stat.ToConsoleString());
 }
        /// <summary>
        /// Deregister a statistic
        /// </summary>>
        /// <param name='stat'></param>
        /// <returns></returns>
        public static bool DeregisterStat(Stat stat)
        {
            SortedDictionary<string, SortedDictionary<string, Stat>> category = null, newCategory;
            SortedDictionary<string, Stat> container = null, newContainer;

            RegisteredStatsRwLock.AcquireWriterLock(-1);
            try
            {
                if (!TryGetStatParents(stat, out category, out container))
                    return false;

                newContainer = new SortedDictionary<string, Stat>(container);
                newContainer.Remove(stat.ShortName);

                newCategory = new SortedDictionary<string, SortedDictionary<string, Stat>>(category);
                newCategory.Remove(stat.Container);

                newCategory[stat.Container] = newContainer;
                RegisteredStats[stat.Category] = newCategory;

                return true;
            }
            finally
            {
                RegisteredStatsRwLock.ReleaseWriterLock();
            }
        }
Exemplo n.º 17
0
        public static bool TryGetStat(string category, string container, string statShortName, out Stat stat)
        {
            stat = null;
            SortedDictionary<string, SortedDictionary<string, Stat>> categoryStats;

            lock (RegisteredStats)
            {
                if (!TryGetStatsForCategory(category, out categoryStats))
                    return false;

                SortedDictionary<string, Stat> containerStats;

                if (!categoryStats.TryGetValue(container, out containerStats))
                    return false;

                return containerStats.TryGetValue(statShortName, out stat);
            }
        }
        public static bool TryGetStat(string category, string container, string statShortName, out Stat stat)
        {
            stat = null;
            SortedDictionary<string, SortedDictionary<string, Stat>> categoryStats;

            RegisteredStatsRwLock.AcquireReaderLock(-1);
            try
            {
                if (!TryGetStatsForCategory(category, out categoryStats))
                    return false;

                SortedDictionary<string, Stat> containerStats;

                if (!categoryStats.TryGetValue(container, out containerStats))
                    return false;

                return containerStats.TryGetValue(statShortName, out stat);
            }
            finally
            {
                RegisteredStatsRwLock.ReleaseReaderLock();
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Deregister a statistic
        /// </summary>>
        /// <param name='stat'></param>
        /// <returns></returns>
        public static bool DeregisterStat(Stat stat)
        {
            SortedDictionary<string, SortedDictionary<string, Stat>> category = null, newCategory;
            SortedDictionary<string, Stat> container = null, newContainer;

            lock (RegisteredStats)
            {
                if (!TryGetStat(stat, out category, out container))
                    return false;

                newContainer = new SortedDictionary<string, Stat>(container);
                newContainer.Remove(stat.ShortName);

                newCategory = new SortedDictionary<string, SortedDictionary<string, Stat>>(category);
                newCategory.Remove(stat.Container);

                newCategory[stat.Container] = newContainer;
                RegisteredStats[stat.Category] = newCategory;

                return true;
            }
        }
        public static bool TryGetStatParents(
            Stat stat,
            out SortedDictionary<string, SortedDictionary<string, Stat>> category,
            out SortedDictionary<string, Stat> container)
        {
            category = null;
            container = null;

            RegisteredStatsRwLock.AcquireReaderLock(-1);
            try
            {
                if (RegisteredStats.TryGetValue(stat.Category, out category))
                {
                    if (category.TryGetValue(stat.Container, out container))
                    {
                        if (container.ContainsKey(stat.ShortName))
                            return true;
                    }
                }
            }
            finally
            {
                RegisteredStatsRwLock.ReleaseReaderLock();
            }

            return false;
        }
Exemplo n.º 21
0
            public ThreadWatchdogInfo(Thread thread, int timeout, string name)
            {
                Thread = thread;
                Timeout = timeout;
                FirstTick = Environment.TickCount & Int32.MaxValue;
                LastTick = FirstTick;

                Stat 
                    = new Stat(
                        name,
                        string.Format("Last update of thread {0}", name),
                        "",
                        "ms",
                        "server",
                        "thread",
                        StatType.Pull,
                        MeasuresOfInterest.None,
                        stat => stat.Value = Environment.TickCount & Int32.MaxValue - LastTick,
                        StatVerbosity.Debug);

                StatsManager.RegisterStat(Stat);
            }
Exemplo n.º 22
0
 private void MakeStat(string pName, string pDesc, string pUnit, string pContainer, Action<Stat> act, MeasuresOfInterest moi)
 {
     string desc = pDesc;
     if (desc == null)
         desc = pName;
     Stat stat = new Stat(pName, pName, desc, pUnit, CategoryServer, pContainer, StatType.Pull, moi, act, StatVerbosity.Debug);
     StatsManager.RegisterStat(stat);
     RegisteredStats.Add(pName, stat);
 }
Exemplo n.º 23
0
        public SimStatsReporter(Scene scene)
        {
            // Initialize the different frame time arrays to the correct sizes
            m_totalFrameTimeMilliseconds = new double[m_numberFramesStored];
            m_simulationFrameTimeMilliseconds = new double[m_numberFramesStored];
            m_physicsFrameTimeMilliseconds = new double[m_numberFramesStored];
            m_networkFrameTimeMilliseconds = new double[m_numberFramesStored];

            // Initialize the current number of users logging into the region
            m_usersLoggingIn = 0;

            m_scene = scene;
            m_reportedFpsCorrectionFactor = scene.MinFrameSeconds * m_nominalReportedFps;
            m_statsUpdateFactor = (float)(m_statsUpdatesEveryMS / 1000);
            ReportingRegion = scene.RegionInfo;

            m_objectCapacity = scene.RegionInfo.ObjectCapacity;
            m_report.AutoReset = true;
            m_report.Interval = m_statsUpdatesEveryMS;
            m_report.Elapsed += TriggerStatsHeartbeat;
            m_report.Enabled = true;

            if (StatsManager.SimExtraStats != null)
                OnSendStatsResult += StatsManager.SimExtraStats.ReceiveClassicSimStatsPacket;

            /// At the moment, we'll only report if a frame is over 120% of target, since commonly frames are a bit
            /// longer than ideal (which in itself is a concern).
            SlowFramesStatReportThreshold = (int)Math.Ceiling(scene.MinFrameTicks * 1.2);

            SlowFramesStat
                = new Stat(
                    "SlowFrames",
                    "Slow Frames",
                    "Number of frames where frame time has been significantly longer than the desired frame time.",
                    " frames",
                    "scene",
                    m_scene.Name,
                    StatType.Push,
                    null,
                    StatVerbosity.Info);

            StatsManager.RegisterStat(SlowFramesStat);
        }
Exemplo n.º 24
0
        public void RegisterServerStats()
        {
//            lastperformanceCounterSampleTime = Util.EnvironmentTickCount();
            PerformanceCounter tempPC;
            Stat tempStat;
            string tempName;

            try
            {
                tempName = "CPUPercent";
                tempPC = new PerformanceCounter("Processor", "% Processor Time", "_Total");
                processorPercentPerfCounter = new PerfCounterControl(tempPC);
                // A long time bug in mono is that CPU percent is reported as CPU percent idle. Windows reports CPU percent busy.
                tempStat = new Stat(tempName, tempName, "", "percent", CategoryServer, ContainerProcessor,
                                StatType.Pull, (s) => { GetNextValue(s, processorPercentPerfCounter); },
                                StatVerbosity.Info);
                StatsManager.RegisterStat(tempStat);
                RegisteredStats.Add(tempName, tempStat);

                MakeStat("TotalProcessorTime", null, "sec", ContainerProcessor,
                                    (s) => { s.Value = Math.Round(Process.GetCurrentProcess().TotalProcessorTime.TotalSeconds, 3); });

                MakeStat("UserProcessorTime", null, "sec", ContainerProcessor,
                                    (s) => { s.Value = Math.Round(Process.GetCurrentProcess().UserProcessorTime.TotalSeconds, 3); });

                MakeStat("PrivilegedProcessorTime", null, "sec", ContainerProcessor,
                                    (s) => { s.Value = Math.Round(Process.GetCurrentProcess().PrivilegedProcessorTime.TotalSeconds, 3); });

                MakeStat("Threads", null, "threads", ContainerProcessor,
                                    (s) => { s.Value = Process.GetCurrentProcess().Threads.Count; });
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("{0} Exception creating 'Process': {1}", LogHeader, e);
            }

            MakeStat("BuiltinThreadpoolWorkerThreadsAvailable", null, "threads", ContainerThreadpool,
                s => 
                { 
                    int workerThreads, iocpThreads; 
                    ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads); 
                    s.Value = workerThreads;
                });

            MakeStat("BuiltinThreadpoolIOCPThreadsAvailable", null, "threads", ContainerThreadpool,
                s => 
                { 
                    int workerThreads, iocpThreads; 
                    ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads); 
                    s.Value = iocpThreads;
                });

            if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool && Util.GetSmartThreadPoolInfo() != null)
            {
                MakeStat("STPMaxThreads", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().MaxThreads);
                MakeStat("STPMinThreads", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().MinThreads);
                MakeStat("STPConcurrency", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().MaxConcurrentWorkItems);
                MakeStat("STPActiveThreads", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().ActiveThreads);
                MakeStat("STPInUseThreads", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().InUseThreads);
                MakeStat("STPWorkItemsWaiting", null, "threads", ContainerThreadpool, s => s.Value = Util.GetSmartThreadPoolInfo().WaitingCallbacks);
            }

            MakeStat(
                "HTTPRequestsMade", 
                "Number of outbound HTTP requests made", 
                "requests", 
                ContainerNetwork, 
                s => s.Value = WebUtil.RequestNumber,
                MeasuresOfInterest.AverageChangeOverTime);

            try
            {
                List<string> okInterfaceTypes = new List<string>(NetworkInterfaceTypes.Split(','));

                IEnumerable<NetworkInterface> nics = NetworkInterface.GetAllNetworkInterfaces();
                foreach (NetworkInterface nic in nics)
                {
                    if (nic.OperationalStatus != OperationalStatus.Up)
                        continue;

                    string nicInterfaceType = nic.NetworkInterfaceType.ToString();
                    if (!okInterfaceTypes.Contains(nicInterfaceType))
                    {
                        m_log.DebugFormat("{0} Not including stats for network interface '{1}' of type '{2}'.",
                                                LogHeader, nic.Name, nicInterfaceType);
                        m_log.DebugFormat("{0}     To include, add to comma separated list in [Monitoring]NetworkInterfaceTypes={1}",
                                                LogHeader, NetworkInterfaceTypes);
                        continue;
                    }

                    if (nic.Supports(NetworkInterfaceComponent.IPv4))
                    {
                        IPv4InterfaceStatistics nicStats = nic.GetIPv4Statistics();
                        if (nicStats != null)
                        {
                            MakeStat("BytesRcvd/" + nic.Name, nic.Name, "KB", ContainerNetwork,
                                            (s) => { LookupNic(s, (ns) => { return ns.BytesReceived; }, 1024.0); });
                            MakeStat("BytesSent/" + nic.Name, nic.Name, "KB", ContainerNetwork,
                                            (s) => { LookupNic(s, (ns) => { return ns.BytesSent; }, 1024.0); });
                            MakeStat("TotalBytes/" + nic.Name, nic.Name, "KB", ContainerNetwork,
                                            (s) => { LookupNic(s, (ns) => { return ns.BytesSent + ns.BytesReceived; }, 1024.0); });
                        }
                    }
                    // TODO: add IPv6 (it may actually happen someday)
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("{0} Exception creating 'Network Interface': {1}", LogHeader, e);
            }

            MakeStat("ProcessMemory", null, "MB", ContainerMemory,
                                (s) => { s.Value = Math.Round(Process.GetCurrentProcess().WorkingSet64 / 1024d / 1024d, 3); });
            MakeStat("HeapMemory", null, "MB", ContainerMemory,
                                (s) => { s.Value = Math.Round(GC.GetTotalMemory(false) / 1024d / 1024d, 3); });
            MakeStat("LastHeapAllocationRate", null, "MB/sec", ContainerMemory,
                                (s) => { s.Value = Math.Round(MemoryWatchdog.LastHeapAllocationRate * 1000d / 1024d / 1024d, 3); });
            MakeStat("AverageHeapAllocationRate", null, "MB/sec", ContainerMemory,
                                (s) => { s.Value = Math.Round(MemoryWatchdog.AverageHeapAllocationRate * 1000d / 1024d / 1024d, 3); });
        }
Exemplo n.º 25
0
        public void RegionLoaded(Scene s)
        {
            if (!m_Enabled)
                return;

            if (s_processedRequestsStat == null)
                s_processedRequestsStat =
                    new Stat(
                        "ProcessedFetchInventoryRequests",
                        "Number of processed fetch inventory requests",
                        "These have not necessarily yet been dispatched back to the requester.",
                        "",
                        "inventory",
                        "httpfetch",
                        StatType.Pull,
                        MeasuresOfInterest.AverageChangeOverTime,
                        stat => { stat.Value = ProcessedRequestsCount; },
                        StatVerbosity.Debug);

            if (s_queuedRequestsStat == null)
                s_queuedRequestsStat =
                    new Stat(
                        "QueuedFetchInventoryRequests",
                        "Number of fetch inventory requests queued for processing",
                        "",
                        "",
                        "inventory",
                        "httpfetch",
                        StatType.Pull,
                        MeasuresOfInterest.AverageChangeOverTime,
                        stat => { stat.Value = m_queue.Count; },
                        StatVerbosity.Debug);

            StatsManager.RegisterStat(s_processedRequestsStat);
            StatsManager.RegisterStat(s_queuedRequestsStat);

            m_InventoryService = Scene.InventoryService;
            m_LibraryService = Scene.LibraryService;

            // We'll reuse the same handler for all requests.
            m_webFetchHandler = new FetchInvDescHandler(m_InventoryService, m_LibraryService, Scene);

            Scene.EventManager.OnRegisterCaps += RegisterCaps;

            int nworkers = 2; // was 2
            if (ProcessQueuedRequestsAsync && m_workerThreads == null)
            {
                m_workerThreads = new Thread[nworkers];

                for (uint i = 0; i < nworkers; i++)
                {
                    m_workerThreads[i] = WorkManager.StartThread(DoInventoryRequests,
                            String.Format("InventoryWorkerThread{0}", i),
                            ThreadPriority.Normal,
                            false,
                            true,
                            null,
                            int.MaxValue);
                }
            }
        }
Exemplo n.º 26
0
        private void GetNextValue(Stat stat, PerfCounterControl perfControl)
        {
            if (Util.EnvironmentTickCountSubtract(perfControl.lastFetch) > performanceCounterSampleInterval)
            {
                if (perfControl != null && perfControl.perfCounter != null)
                {
                    try
                    {
                        stat.Value = Math.Round(perfControl.perfCounter.NextValue(), 3);
                    }
                    catch (Exception e)
                    {
                        m_log.ErrorFormat("{0} Exception on NextValue fetching {1}: {2}", LogHeader, stat.Name, e);
                    }

                    perfControl.lastFetch = Util.EnvironmentTickCount();
                }
            }
        }
Exemplo n.º 27
0
        private void StartHTTP()
        {
            m_log.InfoFormat(
                "[BASE HTTP SERVER]: Starting {0} server on port {1}", UseSSL ? "HTTPS" : "HTTP", Port);

            try
            {
                //m_httpListener = new HttpListener();

                NotSocketErrors = 0;
                if (!m_ssl)
                {
                    //m_httpListener.Prefixes.Add("http://+:" + m_port + "/");
                    //m_httpListener.Prefixes.Add("http://10.1.1.5:" + m_port + "/");
                    m_httpListener2 = CoolHTTPListener.Create(m_listenIPAddress, (int)m_port);
                    m_httpListener2.ExceptionThrown += httpServerException;
                    m_httpListener2.LogWriter = httpserverlog;

                    // Uncomment this line in addition to those in HttpServerLogWriter
                    // if you want more detailed trace information from the HttpServer
                    //m_httpListener2.UseTraceLogs = true;

                    //m_httpListener2.DisconnectHandler = httpServerDisconnectMonitor;
                }
                else
                {
                    //m_httpListener.Prefixes.Add("https://+:" + (m_sslport) + "/");
                    //m_httpListener.Prefixes.Add("http://+:" + m_port + "/");
                    m_httpListener2 = CoolHTTPListener.Create(IPAddress.Any, (int)m_port, m_cert);
                    m_httpListener2.ExceptionThrown += httpServerException;
                    m_httpListener2.LogWriter = httpserverlog;
                }

                m_httpListener2.RequestReceived += OnRequest;
                //m_httpListener.Start();
                m_httpListener2.Start(64);

                // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events
                m_PollServiceManager = new PollServiceRequestManager(this, 3, 25000);
                m_PollServiceManager.Start();
                HTTPDRunning = true;

                //HttpListenerContext context;
                //while (true)
                //{
                //    context = m_httpListener.GetContext();
                //    ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(HandleRequest), context);
               // }
            }
            catch (Exception e)
            {
                m_log.Error("[BASE HTTP SERVER]: Error - " + e.Message);
                m_log.Error("[BASE HTTP SERVER]: Tip: Do you have permission to listen on port " + m_port + ", " + m_sslport + "?");

                // We want this exception to halt the entire server since in current configurations we aren't too
                // useful without inbound HTTP.
                throw e;
            }

            m_requestsProcessedStat 
                = new Stat(
                    "HTTPRequestsServed",
                    "Number of inbound HTTP requests processed",
                    "",
                    "requests",
                    "httpserver",
                    Port.ToString(),
                    StatType.Pull,
                    MeasuresOfInterest.AverageChangeOverTime,
                    stat => stat.Value = RequestNumber,
                    StatVerbosity.Debug);
          
            StatsManager.RegisterStat(m_requestsProcessedStat);
        }
Exemplo n.º 28
0
 private void LookupNic(Stat stat, GetIPv4StatValue getter, double factor)
 {
     // Get the one nic that has the name of this stat
     IEnumerable<NetworkInterface> nics = NetworkInterface.GetAllNetworkInterfaces().Where(
                           (network) => network.Name == stat.Description);
     try
     {
         foreach (NetworkInterface nic in nics)
         {
             IPv4InterfaceStatistics intrStats = nic.GetIPv4Statistics();
             if (intrStats != null)
             {
                 double newVal = Math.Round(getter(intrStats) / factor, 3);
                 stat.Value = newVal;
             }
             break;
         }
     }
     catch
     {
         // There are times interfaces go away so we just won't update the stat for this
         m_log.ErrorFormat("{0} Exception fetching stat on interface '{1}'", LogHeader, stat.Description);
     }
 }
Exemplo n.º 29
0
        /// <summary>
        /// Disables pool stats.
        /// </summary>
        private void DisablePoolStats()
        {
            StatsManager.DeregisterStat(m_poolCountStat);
            m_poolCountStat = null;

            StatsManager.DeregisterStat(m_incomingPacketPoolStat);
            m_incomingPacketPoolStat = null;
        }
Exemplo n.º 30
0
         public SimStatsReporter(Scene scene)
        {
            m_scene = scene;

            ReportingRegion = scene.RegionInfo;

            if(scene.Normalized55FPS)
                m_statisticsFPSfactor = 55.0f * m_scene.FrameTime;
            else
                m_statisticsFPSfactor = 1.0f;

            m_targetFrameTime = 1000.0f * m_scene.FrameTime /  m_statisticsFPSfactor;

            m_objectCapacity = scene.RegionInfo.ObjectCapacity;
            m_report.AutoReset = true;
            m_report.Interval = m_statsUpdatesEveryMS;
            m_report.Elapsed += TriggerStatsHeartbeat;
            m_report.Enabled = true;

            m_lastUpdateTS = Util.GetTimeStampMS();
            m_FrameStatsTS = m_lastUpdateTS;
            m_prevFrameStatsTS = m_lastUpdateTS;

            if (StatsManager.SimExtraStats != null)
                OnSendStatsResult += StatsManager.SimExtraStats.ReceiveClassicSimStatsPacket;

            /// At the moment, we'll only report if a frame is over 120% of target, since commonly frames are a bit
            /// longer than ideal (which in itself is a concern).
            SlowFramesStatReportThreshold = (int)Math.Ceiling(m_scene.FrameTime * 1000 * 1.2);

            SlowFramesStat
                = new Stat(
                    "SlowFrames",
                    "Slow Frames",
                    "Number of frames where frame time has been significantly longer than the desired frame time.",
                    " frames",
                    "scene",
                    m_scene.Name,
                    StatType.Push,
                    null,
                    StatVerbosity.Info);

            StatsManager.RegisterStat(SlowFramesStat);
        }