示例#1
0
 public PerfmonPlugin(Options options, Counterlist counter)
 {
     Initialize(options);
     AddCounter(counter, 0);
     if (counter.querytype.Equals(WMIEvent))
     {
         PollingInterval = 0;
     }
 }
示例#2
0
        public void AddCounter(Counterlist aCounter, int whichCounter)
        {
            if (!String.IsNullOrEmpty(aCounter.query))
            {
                if (aCounter.counters != null)
                {
                    foreach (var testCounter in aCounter.counters)
                    {
                        if (String.IsNullOrEmpty(testCounter.counter))
                        {
                            Console.Error.WriteLine("plugin.json contains malformed counter: counterlist[{0}] missing 'counter' in 'counters'. Please review and compare to template.", whichCounter);
                            return;
                        }
                    }
                    PerfmonQueries.Add(new PerfmonQuery(aCounter.query, aCounter.eventname, aCounter.querytype, aCounter.querynamespace, aCounter.counters));
                }
                else
                {
                    PerfmonQueries.Add(new PerfmonQuery(aCounter.query, aCounter.eventname, aCounter.querytype, aCounter.querynamespace, null));
                }
                return;
            }

            if (String.IsNullOrEmpty(aCounter.provider) || String.IsNullOrEmpty(aCounter.category))
            {
                Console.Error.WriteLine("plugin.json contains malformed counter: counterlist[{0}] missing 'provider' or 'category'. Please review and compare to template.", whichCounter);
                return;
            }

            string instanceName = string.Empty;

            if (!String.IsNullOrEmpty(aCounter.instance) && !String.Equals(aCounter.instance, "*"))
            {
                instanceName = aCounter.instance.ToString();
            }

            if (aCounter.counters != null)
            {
                int    whichSubCounter = -1;
                string countersStr     = "";
                foreach (var aSubCounter in aCounter.counters)
                {
                    whichSubCounter++;
                    if (String.IsNullOrEmpty(aSubCounter.counter))
                    {
                        Console.Error.WriteLine("plugin.json contains malformed counter: 'counters' in counterlist[{0}] missing 'counter' in element {1}. Please review and compare to template.", whichCounter, whichSubCounter);
                        continue;
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(countersStr))
                        {
                            countersStr = aSubCounter.counter;
                        }
                        else
                        {
                            countersStr += (", " + aSubCounter.counter);
                        }
                    }
                }
                if (!String.IsNullOrEmpty(countersStr))
                {
                    PerfmonQueries.Add(new PerfmonQuery(aCounter.provider, aCounter.category, countersStr, instanceName));
                }
            }
            else
            {
                Console.Error.WriteLine("plugin.json contains malformed counter: counterlist[{0}] missing 'counters'. Please review and compare to template.", whichCounter);
            }
        }
示例#3
0
        public void AddCounter(Counterlist aCounter, int whichCounter)
        {
            if (!String.IsNullOrEmpty(aCounter.query))
            {
                if (aCounter.counters != null)
                {
                    int whichOfTheseCounters = -1;
                    foreach (var testCounter in aCounter.counters)
                    {
                        whichOfTheseCounters++;
                        if (String.IsNullOrEmpty(testCounter.counter))
                        {
                            Log.WriteLog(String.Format("{0} contains malformed counter: 'counters' in counterlist[{1}] missing 'counter' in element {2}. Please review and compare to template.",
                                                       fileName, whichCounter, whichOfTheseCounters),
                                         Log.LogLevel.ERROR);
                            continue;
                        }
                    }
                }
                WMIQueries.Add(new WMIQuery(aCounter.query, aCounter.eventname, aCounter.querytype, aCounter.querynamespace, aCounter.counters));
            }
            else
            {
                if (String.IsNullOrEmpty(aCounter.provider) || String.IsNullOrEmpty(aCounter.category))
                {
                    Log.WriteLog(String.Format("{0} contains malformed counter: counterlist[{1}] missing 'provider' or 'category'. Please review and compare to template.",
                                               fileName, whichCounter), Log.LogLevel.ERROR);
                }
                if (aCounter.counters == null)
                {
                    Log.WriteLog(String.Format("{0} contains malformed counter: counterlist[{1}] missing 'counters'. Please review and compare to template.",
                                               fileName, whichCounter), Log.LogLevel.ERROR);
                }

                string instanceName = string.Empty;
                if (!String.IsNullOrEmpty(aCounter.instance) && !String.Equals(aCounter.instance, "*"))
                {
                    instanceName = aCounter.instance.ToString();
                }

                int whichOfTheseCounters = -1;
                foreach (var testCounter in aCounter.counters)
                {
                    whichOfTheseCounters++;
                    if (String.IsNullOrEmpty(testCounter.counter))
                    {
                        Log.WriteLog(String.Format("{0} contains malformed counter: 'counters' in counterlist[{1}] missing 'counter' in element {2}. Please review and compare to template.",
                                                   fileName, whichCounter, whichOfTheseCounters), Log.LogLevel.ERROR);
                        continue;
                    }
                }

                if (String.Equals(aCounter.provider, PerfCounterType))
                {
                    List <string> pcounters = new List <string>();
                    foreach (var pCounter in aCounter.counters)
                    {
                        pcounters.Add(pCounter.counter);
                    }
                    PerfCounter AddPC = RUser.RunAsRemoteUser <PerfCounter>(() => new PerfCounter(aCounter.category, pcounters, instanceName, MachineName));
                    PerfCounters.Add(AddPC);
                }
                else
                {
                    string countersStr = "";
                    foreach (var wCounter in aCounter.counters)
                    {
                        if (String.IsNullOrEmpty(countersStr))
                        {
                            countersStr = wCounter.counter;
                        }
                        else
                        {
                            countersStr += (", " + wCounter.counter);
                        }
                    }
                    if (!String.IsNullOrEmpty(countersStr))
                    {
                        WMIQueries.Add(new WMIQuery(aCounter.provider, aCounter.category, countersStr, instanceName));
                    }
                }
            }
        }