private static Dictionary<string, PerformanceCounter> CreatePerfCounters(string perfCounterCategoryName, string[] perfCounterNames, bool overWriteCounters)
    {
        CounterCreationDataCollection counters = new CounterCreationDataCollection();

        foreach (string perfCounterName in perfCounterNames)
        {
            counters.Add(new CounterCreationData(perfCounterName, "", PerformanceCounterType.NumberOfItems64));
        }

        if (overWriteCounters)
        {
            if (PerformanceCounterCategory.Exists(perfCounterCategoryName))
            {
                PerformanceCounterCategory.Delete(perfCounterCategoryName);
            }
            PerformanceCounterCategory.Create(perfCounterCategoryName, "", PerformanceCounterCategoryType.SingleInstance, counters);
        }
        else
        {
            if (!PerformanceCounterCategory.Exists(perfCounterCategoryName))
            {
                PerformanceCounterCategory.Create(perfCounterCategoryName, "", PerformanceCounterCategoryType.SingleInstance, counters);
            }
        }

        Dictionary<string, PerformanceCounter> perfCounterLookup = new Dictionary<string, PerformanceCounter>();

        foreach (string perfCounterName in perfCounterNames)
        {
            perfCounterLookup.Add(perfCounterName, new PerformanceCounter(perfCounterCategoryName, perfCounterName, false));
        }

        return perfCounterLookup;
    }
コード例 #2
0
ファイル: App.cs プロジェクト: EdiCarlos/MyPractices
    //public static void Main()
    //{
    //    ArrayList samplesList = new ArrayList();

    //    SetupCategory();
    //    CreateCounters();
    //    CollectSamples(samplesList);
    //}


    private static bool SetupCategory()
    {
        if (!PerformanceCounterCategory.Exists("ElapsedTimeSampleCategory"))
        {

            CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData ETimeData = new CounterCreationData();
            ETimeData.CounterType = PerformanceCounterType.ElapsedTime;
            ETimeData.CounterName = "ElapsedTimeSample";
            CCDC.Add(ETimeData);

            // Create the category.
            PerformanceCounterCategory.Create("ElapsedTimeSampleCategory",
                "Demonstrates usage of the ElapsedTime performance counter type.",
                CCDC);

            return (true);
        }
        else
        {
            Console.WriteLine("Category exists - ElapsedTimeSampleCategory");
            return (false);
        }
    }
    public static void Main()
    {
        string categoryName = "Sample Perf Counters";
        string[] counterNames = {"Counter 1", "Counter 2"};

        CounterCreationDataCollection counters = new CounterCreationDataCollection();

        foreach (string counterName in counterNames)
        {
            counters.Add(new CounterCreationData(counterName, "", PerformanceCounterType.NumberOfItems64));
        }

        // example of recreating the counters

        if (PerformanceCounterCategory.Exists(categoryName))
        {
            PerformanceCounterCategory.Delete(categoryName);
        }
        PerformanceCounterCategory.Create(categoryName, "", PerformanceCounterCategoryType.SingleInstance, counters);

        // example of conditionally creating the counters

        if (!PerformanceCounterCategory.Exists(categoryName))
        {
            PerformanceCounterCategory.Create(categoryName, "", PerformanceCounterCategoryType.SingleInstance, counters);
        }

        // update the counters (don't create a new instance each time you update)

        List<PerformanceCounter> perfCounters = new List<PerformanceCounter>();

        foreach (string counterName in counterNames)
        {
            perfCounters.Add(new PerformanceCounter(categoryName, counterName, false));
        }

        Random rand = new Random();

        while (true)
        {
            foreach (PerformanceCounter perfCounter in perfCounters)
            {
                perfCounter.RawValue = rand.Next(101);
            }

            Thread.Sleep(2000);
        }
    }
コード例 #4
0
    static void Main(string[] args)
    {
        if (args.Length <= 1)
            {
                System.Console.WriteLine("Please enter CounterGroup and Counters");
                System.Console.WriteLine("Usage: executable <CounterGroup> <Counter1> <CounterN>");
                return;
            }

            if (args.Length == 2) {
                if (args[0].Equals("delete")) {
                    if (PerformanceCounterCategory.Exists(args[1]))
                    {
                        PerformanceCounterCategory.Delete(args[1]);
                        Console.Out.WriteLine("Deleting perfGroup: " + args[1]);
                    }
                    return;
                }
            }

            CounterCreationDataCollection col = new CounterCreationDataCollection();

            String metrics_name = args[0];

            for (int i = 1; i < args.Length; i++) {

                Console.Out.WriteLine("Adding counters: " + args[i]);
                CounterCreationData counter = new CounterCreationData();
                counter.CounterName = args[i];
                counter.CounterHelp = args[i];
                counter.CounterType = PerformanceCounterType.NumberOfItems32;
                col.Add(counter);
            }

            if (PerformanceCounterCategory.Exists(metrics_name))
            {
                PerformanceCounterCategory.Delete(metrics_name);
                Console.Out.WriteLine("Deleting perfGroup:" + metrics_name);
            }

            PerformanceCounterCategory category = PerformanceCounterCategory.Create(metrics_name,
            "Perf Category Description ", col);
            Console.Out.WriteLine("Creating perfGroup:" + metrics_name);
    }
	public void AddRange(CounterCreationDataCollection value) {}
コード例 #6
0
        private void SetupCategory()
        {
            if (!PerformanceCounterCategory.Exists(_stpCategoryName))
            {
                CounterCreationDataCollection counters = new CounterCreationDataCollection();

                for (int i = 0; i < _stpPerformanceCounters.Length; i++)
                {
                    _stpPerformanceCounters[i].AddCounterToCollection(counters);
                }

                PerformanceCounterCategory.Create(
                    _stpCategoryName,
                    _stpCategoryHelp,
                    PerformanceCounterCategoryType.MultiInstance,
                    counters);

            }
        }
コード例 #7
0
        public void AddCounterToCollection(CounterCreationDataCollection counterData)
        {
            CounterCreationData counterCreationData = new CounterCreationData(
                _counterName,
                _counterHelp,
                _pcType);

            counterData.Add(counterCreationData);
        }
コード例 #8
0
        public static void AttachPerformanceCountersToProperties <T>
        (
            string performanceCounterInstanceName
            , string category
            , T target                             //= default(T)
        )
        {
            var type           = typeof(T);
            var propertiesList = type.GetProperties().ToList();

            propertiesList = propertiesList
                             .Where
                             (
                (pi) =>
            {
                var parameters = pi.GetIndexParameters();
                return
                (
                    pi.PropertyType == typeof(PerformanceCounter) &&
                    (parameters == null ? 0 : parameters.Length) <= 0
                );
            }
                             ).ToList();
            if (PerformanceCounterCategory.Exists(category))
            {
                propertiesList
                .ForEach
                (
                    (pi) =>
                {
                    if (PerformanceCounterCategory.CounterExists(pi.Name, category))
                    {
                        if (PerformanceCounterCategory.InstanceExists(performanceCounterInstanceName, category))
                        {
                            //var pc = new PerformanceCounter(category, pi.Name, instanceName, false);
                            //pc.InstanceName = instanceName;
                            //pc.RemoveInstance();
                        }
                    }
                }
                );
                //PerformanceCounterCategory.Delete(category);
            }
            if (!PerformanceCounterCategory.Exists(category))
            {
                var ccdc = new CounterCreationDataCollection();
                propertiesList
                .ForEach
                (
                    (pi) =>
                {
                    var propertyName           = pi.Name;
                    var performanceCounterType = PerformanceCounterType.NumberOfItems64;
                    var performanceCounterName = propertyName;
                    var attribute
                        = pi
                          .GetCustomAttributes(false)
                          .FirstOrDefault
                          (
                              (x) =>
                    {
                        return
                        (x as PerformanceCounterDefinitionAttribute
                         != null);
                    }
                          ) as PerformanceCounterDefinitionAttribute;
                    if (attribute != null)
                    {
                        var counterName = attribute.CounterName;
                        if (!string.IsNullOrEmpty(counterName))
                        {
                            performanceCounterName = counterName;
                        }
                        var counterType = attribute.CounterType;
                        //if (counterType != null)
                        {
                            performanceCounterType = counterType;
                        }
                    }
                    var ccd = PerformanceCountersHelper
                              .GetCounterCreationData
                              (
                        performanceCounterName
                        , performanceCounterType
                              );
                    ccdc.Add(ccd);
                }
                );
                PerformanceCounterCategory
                .Create
                (
                    category
                    , string.Format("{0} Category Help.", category)
                    , PerformanceCounterCategoryType.MultiInstance
                    , ccdc
                );
            }
            propertiesList.ForEach
            (
                (pi) =>
            {
                var propertyName           = pi.Name;
                var performanceCounterType = PerformanceCounterType.NumberOfItems64;
                var performanceCounterName = propertyName;
                var attribute
                    = pi
                      .GetCustomAttributes(false)
                      .FirstOrDefault
                      (
                          (x) =>
                {
                    return
                    (x as PerformanceCounterDefinitionAttribute
                     != null);
                }
                      ) as PerformanceCounterDefinitionAttribute;
                if (attribute != null)
                {
                    var counterName = attribute.CounterName;
                    if (!string.IsNullOrEmpty(counterName))
                    {
                        performanceCounterName = counterName;
                    }
                    var counterType = attribute.CounterType;
                    //if (counterType != null)
                    {
                        performanceCounterType = counterType;
                    }
                }
                var pc = new PerformanceCounter()
                {
                    CategoryName = category
                    ,
                    CounterName = performanceCounterName
                    ,
                    InstanceLifetime = PerformanceCounterInstanceLifetime.Process
                    ,
                    InstanceName = performanceCounterInstanceName
                    ,
                    ReadOnly = false
                    ,
                    RawValue = 0
                };
                if (pi.GetGetMethod().IsStatic)
                {
                    var setter = DynamicPropertyAccessor
                                 .CreateSetStaticPropertyValueAction <PerformanceCounter>
                                 (
                        type
                        , propertyName
                                 );
                    setter(pc);
                }
                else
                {
                    if (target != null)
                    {
                        var setter = DynamicPropertyAccessor
                                     .CreateSetPropertyValueAction <PerformanceCounter>
                                     (
                            type
                            , propertyName
                                     );
                        setter(target, pc);
                    }
                }
            }
            );
        }
	public static PerformanceCounterCategory Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) {}
コード例 #10
0
        public static void InstallCounters()
        {
            if (!PerformanceCounterCategory.Exists("DialogueMaster Babel"))
            {
                CounterCreationDataCollection ccdJanusTables = new CounterCreationDataCollection();

                // tables
                CounterCreationData cd = new CounterCreationData();
                cd.CounterType = PerformanceCounterType.NumberOfItems64;
                cd.CounterName = "Tables created";
                cd.CounterHelp = "Total number of NGram-Tables created";
                ccdJanusTables.Add(cd);

                cd             = new CounterCreationData();
                cd.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
                cd.CounterName = "Tables created / sec";
                cd.CounterHelp = "Number of NGram-Tables created per second";
                ccdJanusTables.Add(cd);


                cd             = new CounterCreationData();
                cd.CounterType = PerformanceCounterType.RawFraction;
                cd.CounterName = "Avg. table creation time";
                cd.CounterHelp = "Average time it takes to create a table";
                ccdJanusTables.Add(cd);

                cd             = new CounterCreationData();
                cd.CounterType = PerformanceCounterType.RawBase;
                cd.CounterName = "base for avg. table creation time";
                cd.CounterHelp = "base for Average time it takes to create a table";
                ccdJanusTables.Add(cd);


                // Comparison
                cd             = new CounterCreationData();
                cd.CounterType = PerformanceCounterType.NumberOfItems64;
                cd.CounterName = "Comparisons";
                cd.CounterHelp = "Total number of comparisons";
                ccdJanusTables.Add(cd);

                cd             = new CounterCreationData();
                cd.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
                cd.CounterName = "Comparisons / sec";
                cd.CounterHelp = "Number of comparisons created per second";
                ccdJanusTables.Add(cd);

                cd             = new CounterCreationData();
                cd.CounterType = PerformanceCounterType.RawFraction;
                cd.CounterName = "Avg. comparison time";
                cd.CounterHelp = "Average time it takes to compare two tables";
                ccdJanusTables.Add(cd);

                cd             = new CounterCreationData();
                cd.CounterType = PerformanceCounterType.RawBase;
                cd.CounterName = "base for Avg. comparison time";
                cd.CounterHelp = "base for Average time it takes to compare two tables";
                ccdJanusTables.Add(cd);

                // Classifications
                cd             = new CounterCreationData();
                cd.CounterType = PerformanceCounterType.NumberOfItems64;
                cd.CounterName = "Classifications";
                cd.CounterHelp = "Total number of classifications";
                ccdJanusTables.Add(cd);

                cd             = new CounterCreationData();
                cd.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
                cd.CounterName = "Classifications / sec";
                cd.CounterHelp = "Number of classifications created per second";
                ccdJanusTables.Add(cd);

                cd             = new CounterCreationData();
                cd.CounterType = PerformanceCounterType.RawFraction;
                cd.CounterName = "Avg. classification time";
                cd.CounterHelp = "Average time it takes to classify a text";
                ccdJanusTables.Add(cd);

                cd             = new CounterCreationData();
                cd.CounterType = PerformanceCounterType.RawBase;
                cd.CounterName = "base for Avg. classification time";
                cd.CounterHelp = "base for Average time it takes to classify a text";
                ccdJanusTables.Add(cd);

                PerformanceCounterCategory.Create("DialogueMaster Babel", "DialogueMaster Janus language detection engine", PerformanceCounterCategoryType.SingleInstance, ccdJanusTables);
            }
        }
コード例 #11
0
        public static void Initialize()
        {
            //Console.ForegroundColor = ConsoleColor.Yellow;
            //Console.Write("Initializing Performance Counter: ");

            //System.Diagnostics.PerformanceCounterCategory.Delete(CountersConstants.COECategory);

            if (!System.Diagnostics.PerformanceCounterCategory.Exists(CountersConstants.FixSvcCategory))
            {
                CounterCreationDataCollection CounterData = new CounterCreationDataCollection()
                {
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.ClientsCancelOrderReqs, CounterHelp = CountersConstants.ClientsCancelOrderReqsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.ClientsNewOrderReqs, CounterHelp = CountersConstants.ClientsNewOrderReqsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.ClientsReplaceOrderReqs, CounterHelp = CountersConstants.ClientsReplaceOrderReqsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },

                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.RcvExecRspMsgs, CounterHelp = CountersConstants.RcvExecRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.NewExecRspMsgs, CounterHelp = CountersConstants.NewExecRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.SuspendedExecRspMsgs, CounterHelp = CountersConstants.SuspendedExecRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.FilledExecRspMsgs, CounterHelp = CountersConstants.FilledExecRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.PartialFilledExecRspMsgs, CounterHelp = CountersConstants.PartialFilledExecRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.ReplacedExecRspMsgs, CounterHelp = CountersConstants.ReplacedExecRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.RejectedExecRspMsgs, CounterHelp = CountersConstants.RejectedExecRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.CanceledExecRspMsgs, CounterHelp = CountersConstants.CanceledExecRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.PendingCancelExecRspMsgs, CounterHelp = CountersConstants.PendingCancelExecRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.PendingReplaceExecRspMsgs, CounterHelp = CountersConstants.PendingReplaceExecRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.ExpiredExecRspMsgs, CounterHelp = CountersConstants.ExpiredExecRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.UnhandledExecRspMsgs, CounterHelp = CountersConstants.UnhandledExecRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },

                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.BusinessRejectRspMsgs, CounterHelp = CountersConstants.BusinessRejectRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.OrderCancelRejectRspMsgs, CounterHelp = CountersConstants.OrderCancelRejectRspMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.RejectionMsgs, CounterHelp = CountersConstants.RejectionMsgsHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },

                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.NotApplicableMessages, CounterHelp = CountersConstants.NotApplicableMessagesHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.SMSSentMessages, CounterHelp = CountersConstants.SMSSentMessagesHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.EmailSentMessages, CounterHelp = CountersConstants.EmailSentMessagesHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.ExceptionMessages, CounterHelp = CountersConstants.ExceptionMessagesHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.SubmittedOrders, CounterHelp = CountersConstants.SubmittedOrdersHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    },
                    new CounterCreationData()
                    {
                        CounterName = CountersConstants.DuplicatedOrders, CounterHelp = CountersConstants.DuplicatedOrdersHelp, CounterType = PerformanceCounterType.NumberOfItems64
                    }
                };
                System.Diagnostics.PerformanceCounterCategory.Create(CountersConstants.FixSvcCategory, CountersConstants.FixSvcCategoryHelp, PerformanceCounterCategoryType.MultiInstance, CounterData);
                //Console.ForegroundColor = ConsoleColor.Green;
                //Console.WriteLine("Done, Performance Counters have been creat3ed successfully !");
                //Console.WriteLine();
            }
            //else
            //{
            //Console.ForegroundColor = ConsoleColor.Green;
            //Console.WriteLine("Done, Performance Counters Already Existed !");
            //Console.WriteLine();
            //}

            m_sigleton = new Dictionary <string, PerformanceCounter>();



            PerformanceCounter clientCancelOrders = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.ClientsCancelOrderReqs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.ClientsCancelOrderReqs, clientCancelOrders);
            PerformanceCounter clientNewOrder = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.ClientsNewOrderReqs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.ClientsNewOrderReqs, clientNewOrder);
            PerformanceCounter clientReplaceOrders = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.ClientsReplaceOrderReqs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.ClientsReplaceOrderReqs, clientReplaceOrders);


            PerformanceCounter newRsp = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.NewExecRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.NewExecRspMsgs, newRsp);
            PerformanceCounter replaceRsp = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.ReplacedExecRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.ReplacedExecRspMsgs, replaceRsp);
            PerformanceCounter suspendedRsp = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.SuspendedExecRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.SuspendedExecRspMsgs, suspendedRsp);
            PerformanceCounter filled = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.FilledExecRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.FilledExecRspMsgs, filled);
            PerformanceCounter partialliFilled = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.PartialFilledExecRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.PartialFilledExecRspMsgs, partialliFilled);
            PerformanceCounter exec = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.RcvExecRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.RcvExecRspMsgs, exec);
            PerformanceCounter rejectedRsp = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.RejectedExecRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.RejectedExecRspMsgs, rejectedRsp);
            PerformanceCounter canceledRsp = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.CanceledExecRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.CanceledExecRspMsgs, canceledRsp);
            PerformanceCounter pendingCancelRsp = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.PendingCancelExecRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.PendingCancelExecRspMsgs, pendingCancelRsp);
            PerformanceCounter pendingReplaceRsp = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.PendingReplaceExecRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.PendingReplaceExecRspMsgs, pendingReplaceRsp);
            PerformanceCounter expiredRsp = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.ExpiredExecRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.ExpiredExecRspMsgs, expiredRsp);
            PerformanceCounter unhandeledExecRsp = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.UnhandledExecRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.UnhandledExecRspMsgs, unhandeledExecRsp);

            PerformanceCounter businessRejectRsp = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.BusinessRejectRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.BusinessRejectRspMsgs, businessRejectRsp);
            PerformanceCounter orderCancelRejectRsp = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.OrderCancelRejectRspMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.OrderCancelRejectRspMsgs, orderCancelRejectRsp);
            PerformanceCounter rejectionMsg = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.RejectionMsgs, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.RejectionMsgs, rejectionMsg);



            PerformanceCounter NotApplicableMessages = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.NotApplicableMessages, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.NotApplicableMessages, NotApplicableMessages);
            PerformanceCounter ExceptionMessages = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.ExceptionMessages, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.ExceptionMessages, ExceptionMessages);
            PerformanceCounter SMSSentMessages = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.SMSSentMessages, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.SMSSentMessages, SMSSentMessages);
            PerformanceCounter EmailSentMessages = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.EmailSentMessages, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.EmailSentMessages, EmailSentMessages);
            PerformanceCounter SubmittedOrders = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.SubmittedOrders, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.SubmittedOrders, SubmittedOrders);
            PerformanceCounter DuplicatedOrders = new PerformanceCounter(CountersConstants.FixSvcCategory, CountersConstants.DuplicatedOrders, CountersConstants.FixSvcCategoryInstance, false);

            m_sigleton.Add(CountersConstants.DuplicatedOrders, DuplicatedOrders);

            foreach (PerformanceCounter counter in m_sigleton.Values)
            {
                counter.ReadOnly = false;
            }
        }
コード例 #12
0
 /// <summary>
 /// Create a new <see cref="PerformanceCounterCategoryFactory"/>.
 /// </summary>
 public PerformanceCounterCategoryFactory()
 {
     counterCreationDataCollection = new CounterCreationDataCollection();
 }
コード例 #13
0
 private static bool IsCounterAlreadyIncluded(ref CounterCreationDataCollection colCounterCreationData, string counterName)
 {
     return(colCounterCreationData.Cast <CounterCreationData>().Any(objCreateCounter => objCreateCounter.CounterName == counterName));
 }
コード例 #14
0
 /// <summary>
 /// Registers the counter category.
 /// </summary>
 /// <param name="categoryName">Name of the category.</param>
 /// <param name="description">The description.</param>
 /// <param name="counterCreationDataCollection">The counter creation data collection.</param>
 private void RegisterCounterCategory(string categoryName, string description, CounterCreationDataCollection counterCreationDataCollection)
 {
     if (counterCreationDataCollection.Count > 0)
     {
         if (false == PerformanceCounterCategory.Exists(categoryName))
         {
             PerformanceCounterCategory.Create(categoryName, description, PerformanceCounterCategoryType.MultiInstance, counterCreationDataCollection);
         }
     }
 }
コード例 #15
0
        private void Client_ProcessLog(RCClient sender, RCClient.ProcessLogEventArgs args)
        {
            this.SendMessageToControlServer <LogProcessMessage>(new LogProcessMessage(args.Process.Name, args.Message));
            if (args.Process.PerformanceString.Length > 0 && RCProcess.IsStandardOutputLog(args.Message) && RCProcess.GetOriginalLog(args.Message).StartsWith(args.Process.PerformanceString))
            {
                string categoryName = "RCClient." + args.Process.Name;
                RCProcess.PerformanceDescriptionParser[] fromRawString = RCProcess.PerformanceDescriptionParser.GetFromRawString(args.Process.PerformanceDescription);
                string[] array = RCProcess.GetOriginalLog(args.Message).Substring(args.Process.PerformanceString.Length).Trim().Split(new char[]
                {
                    ' '
                });
                int    num    = Math.Min(array.Length, fromRawString.Length);
                long[] array2 = new long[num];
                for (int i = 0; i < num; i++)
                {
                    try
                    {
                        array2[i] = long.Parse(array[i]);
                    }
                    catch (Exception)
                    {
                        array2[i] = 0L;
                    }
                }
                bool flag = false;
                do
                {
                    try
                    {
                        for (int j = 0; j < num; j++)
                        {
                            new PerformanceCounter(categoryName, fromRawString[j].Name, false).RawValue = array2[j];
                        }
                        flag = false;
                    }
                    catch (Exception ex)
                    {
                        Log <RCClientService> .Logger.ErrorFormat("ExceptionRcClient: {0}", ex.ToString());

                        if (flag)
                        {
                            if (ex is Win32Exception)
                            {
                                Log <RCClientService> .Logger.ErrorFormat("Performance monitor unexcepted exception : {0}\n{1}", ((Win32Exception)ex).NativeErrorCode, ex.Message);
                            }
                            else
                            {
                                Log <RCClientService> .Logger.Error("Performance monitor unexcepted exception :", ex);
                            }
                            break;
                        }
                        flag = true;
                        if (PerformanceCounterCategory.Exists(categoryName))
                        {
                            PerformanceCounterCategory.Delete(categoryName);
                        }
                        CounterCreationDataCollection counterCreationDataCollection = new CounterCreationDataCollection();
                        foreach (RCProcess.PerformanceDescriptionParser performanceDescriptionParser in fromRawString)
                        {
                            counterCreationDataCollection.Add(new CounterCreationData(performanceDescriptionParser.Name, performanceDescriptionParser.HelpMessage, PerformanceCounterType.NumberOfItems64));
                        }
                        PerformanceCounterCategory.Create(categoryName, "", PerformanceCounterCategoryType.SingleInstance, counterCreationDataCollection);
                    }
                }while (flag);
            }
        }
	public CounterCreationDataCollection(CounterCreationDataCollection value) {}
コード例 #17
0
	// Create a performance counter category.
	public static PerformanceCounterCategory Create
				(String categoryName, String categoryHelp,
				 CounterCreationDataCollection counterData)
			{
				// Dummy only: we don't support performance counters.
				return new PerformanceCounterCategory(categoryName);
			}
コード例 #18
0
ファイル: Program.cs プロジェクト: TiE23/somethingjunk
    private static bool SetupCategory()
    {
        if (!PerformanceCounterCategory.Exists("AverageCounter64SampleCategory"))

        {

            CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData averageCount64 = new CounterCreationData();
            averageCount64.CounterType = PerformanceCounterType.AverageCount64;
            averageCount64.CounterName = "AverageCounter64Sample";
            counterDataCollection.Add(averageCount64);

            // Add the base counter.
            CounterCreationData averageCount64Base = new CounterCreationData();
            averageCount64Base.CounterType = PerformanceCounterType.AverageBase;
            averageCount64Base.CounterName = "AverageCounter64SampleBase";
            counterDataCollection.Add(averageCount64Base);

            // Create the category.
            PerformanceCounterCategory.Create("AverageCounter64SampleCategory",
                "Demonstrates usage of the AverageCounter64 performance counter type.",
                PerformanceCounterCategoryType.SingleInstance, counterDataCollection);

            return (true);
        }
        else
        {
            Console.WriteLine("Category exists - AverageCounter64SampleCategory");
            return (false);
        }
    }