Beispiel #1
0
        public float GetValue(PerfCounterCategory category, string counterName, string instanceName)
        {
            var perfCounter = new PerformanceCounter
            {
                CategoryName = category.GetDescription(),
                InstanceName = instanceName,
                CounterName  = counterName
            };

            return(perfCounter.NextValue());
        }
Beispiel #2
0
        protected static string GetWorkerInstanceName(int id, PerfCounterCategory category)
        {
            var counterCategory = new PerformanceCounterCategory(category.GetDescription());

            var pidString = $"[{id}]"; // e.g. [2345]

            var iisProcessIdentifierString = "_lm_w3svc_";

            var instances = counterCategory.GetInstanceNames();

            var instance = counterCategory.GetInstanceNames().SingleOrDefault(i =>
                                                                              i.StartsWith(iisProcessIdentifierString) &&
                                                                              i.EndsWith(pidString));

            return(instance);
        }