예제 #1
0
파일: PerfMon.cs 프로젝트: Amitkapadi/WISP
        /// <summary>
        /// Add a custom performance counter.  Counter won't be installed until InstallCounters() is called.
        /// </summary>
        public static void TrackCustomCounter(string name, string helpText, PerformanceCounterType type, TimeSpan sampleInterval, int maxSamplesToCache, string divisor)
        {
            if (m_Sampling)
            {
                return;
            }

            CounterCreationData ccd = new CounterCreationData();

            ccd.CounterName = name;
            ccd.CounterHelp = helpText;
            ccd.CounterType = type;
            PerfHistory h = GetHistory(name, "Wisp", "");

            try
            {
                h.Divisor = float.Parse(divisor);
            }
            catch (FormatException exc)
            {
                Log1.Logger("Performance").Error("Custom Counter " + h.Key + " has an invalid [Divisor] - must be in float format!");
                h.Divisor = 1;
            }

            h.SampleInterval          = sampleInterval;
            h.HelpText                = helpText;
            h.MaxHistorySamplesToKeep = maxSamplesToCache;
            h.IsCustom                = true;
            _Counters.Add(ccd);
            Log1.Logger("Performance").Debug("Tracking custom performance counter [" + name + "|Wisp|" + "]");
        }
예제 #2
0
파일: PerfMon.cs 프로젝트: Amitkapadi/WISP
        protected static void OnTimerElapsed(object state)
        {
            DateTime now = DateTime.UtcNow;

            lock (m_SyncRoot)
            {
                bool anyActiveCounters = false;
                Dictionary <string, PerfHistory> .Enumerator enu = History.GetEnumerator();
                while (enu.MoveNext())
                {
                    PerfHistory h = enu.Current.Value;
                    if (!h.IsEnabled)
                    {
                        continue;
                    }
                    anyActiveCounters = true;
                    if (now - h.LastSample >= h.SampleInterval)
                    {
                        h.AddSample((float)Math.Round(h.Counter.NextValue() / h.Divisor, 2));
                        //Log1.Logger("Performance").Debug("Sampled performance counter [" + h.Category + "|" + h.CounterName + "|" + h.InstanceName + "] with a value of [" + h.History[h.History.Count - 1].Value + "].");
                    }
                }

                if (!anyActiveCounters)
                {
                    Log1.Logger("Performance").Error("Unable to start sampling performance counters: No performance counters are currently active.");
                    StopSamplingCounters();
                }
            }

            StartSamplingCounters();
        }
예제 #3
0
파일: PerfMon.cs 프로젝트: Amitkapadi/WISP
        public static void UntrackSystemCounter(string counterName, string groupName, string instanceName)
        {
            if (m_Sampling)
            {
                return;
            }
            PerformanceCounter pc  = null;
            string             key = counterName + "|" + groupName + "|" + instanceName;

            lock (m_SyncRoot)
            {
                PerfHistory h = null;
                if (!History.TryGetValue(key, out h))
                {
                    return;
                }
                pc = h.Counter;
                History.Remove(key);
            }

            if (pc != null)
            {
                pc.Dispose();
            }
        }
예제 #4
0
 public PerfHistory(PerfHistory h) : base()
 {
     IsEnabled      = h.IsEnabled;
     Category       = h.Category;
     CounterName    = h.CounterName;
     InstanceName   = h.InstanceName;
     HelpText       = h.HelpText;
     SampleInterval = h.SampleInterval;
 }
예제 #5
0
        private void OnPerfMonStartRequest(INetworkConnection con, Packet r)
        {
            Log1.Logger("Zeus").Debug("Performance Monitor Start request from " + ServerUser.AccountName + ".");

            if (!ServerUser.Profile.IsUserInRole("Administrator"))
            {
                Log1.Logger("Zeus").Warn("[" + ServerUser.AccountName + "] has insufficient permissions to start performance monitor.");
                r.ReplyPacket = CreateStandardReply(r, ReplyType.Failure, "Insufficient permissions. Only Administrators can start the performance monitor.");
                return;
            }

            PacketGenericMessage msg = r as PacketGenericMessage;

            r.ReplyPacket = CreateStandardReply(r, ReplyType.OK, "");
            string[] counters = msg.Parms.GetStringArrayProperty(2);

            if (counters.Length == 0)
            {
                r.ReplyPacket.ReplyCode    = ReplyType.Failure;
                r.ReplyPacket.ReplyMessage = "Must specify at least one counter to start.";
                return;
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < counters.Length; i++)
            {
                string      key = counters[i];
                PerfHistory h   = null;
                if (PerfMon.History.TryGetValue(key, out h))
                {
                    h.IsEnabled = true;
                    if (sb.Length == 0)
                    {
                        sb.Append("Enabled performance counter ");
                    }
                    sb.Append(key.Replace("|", " -> ") + ", ");
                }
            }

            if (sb.Length >= 2)
            {
                sb.Remove(sb.Length - 2, 1);
                PerfMon.InstallCounters();
                PerfMon.StartSamplingCounters();
            }
            else if (sb.Length == 0)
            {
                r.ReplyPacket.ReplyCode = ReplyType.Failure;
                sb.Append("No performance counters were activated.");
            }

            r.ReplyPacket.ReplyMessage = sb.ToString();
        }
예제 #6
0
        private void OnPerfMonCounterOverviewRequest(INetworkConnection con, Packet r)
        {
            Log1.Logger("Zeus").Debug("Performance Monitor Counter overview request from " + ServerUser.AccountName + ".");

            PacketGenericMessage msg = r as PacketGenericMessage;

            r.ReplyPacket = CreateStandardReply(r, ReplyType.OK, "");
            PerfHistory[] history = new PerfHistory[PerfMon.History.Count];
            PerfMon.History.Values.CopyTo(history, 0);
            msg.ReplyPacket.Parms.SetProperty(2, history);
            msg.ReplyPacket.Parms.SetProperty(3, PerfMon.IsSampling);
        }
예제 #7
0
        private void OnPerfMonCounterDataRequest(INetworkConnection con, Packet r)
        {
            Log1.Logger("Zeus.Inbound.Client").Debug("Performance Monitor Counter data request from " + ServerUser.AccountName + ".");

            PacketGenericMessage msg = r as PacketGenericMessage;

            r.ReplyPacket = CreateStandardReply(r, ReplyType.OK, "");
            string[]   counters  = msg.Parms.GetStringArrayProperty(2);
            DateTime[] lastCheck = msg.Parms.GetDateTimeArrayProperty(3);

            msg.ReplyPacket.Parms.SetProperty(3, DateTime.UtcNow);

            List <PerfHistory> clientHistories = new List <PerfHistory>();

            for (int i = 0; i < counters.Length; i++)
            {
                PerfHistory serverHistory = null;
                if (PerfMon.History.TryGetValue(counters[i], out serverHistory))
                {
                    Log.LogMsg("Got request for perf log " + serverHistory.Key + " since " + lastCheck[i].ToLongTimeString());
                    PerfHistory clientHis = new PerfHistory(serverHistory);
                    List <PerfHistory.HistoryItem> buff = new List <PerfHistory.HistoryItem>();
                    for (int x = serverHistory.History.Count - 1; x > -1; x--)
                    {
                        if (serverHistory.History[x].Timestamp > lastCheck[i])
                        {
                            //Log.LogMsg("Adding perf item " + ph.Key + " with timestamp " + ph.History[x].Timestamp.ToLongTimeString());
                            buff.Add(serverHistory.History[x]);
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (buff.Count > 0)
                    {
                        clientHistories.Add(clientHis);
                        buff.Reverse();
                        clientHis.History.AddRange(buff);
                        clientHis.HelpText += " (" + clientHis.History[clientHis.History.Count - 1].Value + ")";
                        Log.LogMsg("Last timestamp sent for perf " + clientHis.Key + " is " + clientHis.LastSample.ToLongTimeString());
                    }
                }
            }

            msg.ReplyPacket.Parms.SetProperty(2, clientHistories.ToArray());
        }
예제 #8
0
파일: PerfMon.cs 프로젝트: Amitkapadi/WISP
        private static PerfHistory GetHistory(string counterName, string groupName, string instanceName)
        {
            PerfHistory rslt;
            string      counter = PerfHistory.GetKey(counterName, groupName, instanceName);

            if (!History.TryGetValue(counter, out rslt))
            {
                rslt              = new PerfHistory();
                rslt.CounterName  = counterName;
                rslt.Category     = groupName;
                rslt.InstanceName = instanceName;
                History.Add(counter, rslt);
            }

            return(rslt);
        }
예제 #9
0
파일: PerfMon.cs 프로젝트: Amitkapadi/WISP
        public static void SetCustomCounter(string counter, long rawValue)
        {
            if (!m_Sampling)
            {
                return;
            }

            string      key = PerfHistory.GetKey(counter, "Wisp", "");
            PerfHistory ph  = null;

            lock (m_SyncRoot)
            {
                if (!History.TryGetValue(key, out ph))
                {
                    Log1.Logger("Performance").Debug("Tried set raw value for counter [" + counter + "] but that counter doesn't exist.");
                    return;
                }

                ph.Counter.RawValue = rawValue;
            }
        }
예제 #10
0
파일: PerfMon.cs 프로젝트: Amitkapadi/WISP
        public static void IncrementCustomCounter(string counter, long amount)
        {
            if (!m_Sampling)
            {
                return;
            }

            PerfHistory ph = null;

            lock (m_SyncRoot)
            {
                if (!History.TryGetValue(PerfHistory.GetKey(counter, "Wisp", ""), out ph))
                {
                    Log1.Logger("Performance").Debug("Tried incremented counter [" + counter + "] but that counter doesn't exist.");
                    return;
                }
                if (ph.Counter != null)
                {
                    ph.Counter.IncrementBy(amount);
                }
            }
        }
예제 #11
0
파일: PerfMon.cs 프로젝트: Amitkapadi/WISP
        public static PerfHistory TrackSystemCounter(string counterName, string groupName, string instanceName, TimeSpan sampleInterval, string helpText, int maxSamplesToCache, string divisor)
        {
            if (m_Sampling)
            {
                return(null);
            }
            if (instanceName.ToLower() == "processname")
            {
                instanceName = ProcessName;
            }

            string      key = counterName + "|" + groupName + "|" + instanceName;
            PerfHistory h   = null;

            try
            {
                PerformanceCounter pc = null;
                lock (m_SyncRoot)
                {
                    if (History.ContainsKey(key))
                    {
                        return(null);
                    }


                    if (instanceName.Length > 0)
                    {
                        h = GetHistory(counterName, groupName, instanceName);
                    }
                    else
                    {
                        h = GetHistory(counterName, groupName, "");
                    }

                    if (h != null)
                    {
                        try
                        {
                            h.Divisor = float.Parse(divisor);
                        }
                        catch (FormatException exc)
                        {
                            Log1.Logger("Performance").Error("System Counter " + h.Key + " has an invalid [Divisor] - must be in float format!");
                            h.Divisor = 1;
                        }
                        h.Counter                 = pc;
                        h.SampleInterval          = sampleInterval;
                        h.HelpText                = helpText;
                        h.MaxHistorySamplesToKeep = maxSamplesToCache;
                    }
                }

                if (pc != null)
                {
                    pc.NextValue();
                }

                Log1.Logger("Performance").Debug("Tracking system performance counter [" + key + "]");
            }
            catch (Exception e)
            {
                Log1.Logger("Performance").Error("Failed to track System Counter [" + key + "]", e);
            }
            return(h);
        }