コード例 #1
0
            public PerformanceCounterTracker(Logging.IBasicLogger logger, PerformanceCounterSpec pcs)
            {
                this.pcs = pcs;
                pcc      = pcs.GetPerformanceCounterCategory();

                useRawPerfCtrValue = pcs.UseRawValue;

                gpInfo = new MDRF.Writer.GroupPointInfo()
                {
                    Name     = pcs.PointName,
                    ValueCST = ContainerStorageType.None,
                };

                try
                {
                    var categorySample = pcc.ReadCategory();
                    Service(logger, categorySample, true);
                }
                catch (System.Exception ex)
                {
                    Logging.IMesgEmitter emitter = (logger == null ? Logging.NullEmitter : logger.Info);

                    emitter.Emit("{0} for '{1}' generated unexpected exception: {2}", CurrentMethodName, gpInfo.Name, ex.ToString(ExceptionFormat.TypeAndMessage));

                    isUsable = false;
                }
            }
コード例 #2
0
 public PerformanceCounterSpec(PerformanceCounterSpec other)
 {
     MachineName  = other.MachineName;
     CategoryName = other.CategoryName;
     CounterName  = other.CounterName;
     InstanceName = other.InstanceName;
     UseRawValue  = other.UseRawValue;
     _pointName   = other._pointName;
 }
コード例 #3
0
        /// <summary>
        /// This method returns true if the given PerformanceCounterSpec <paramref name="pcs"/> refers to a counter instance that exists in the indicated category
        /// </summary>
        public bool IsValid(PerformanceCounterSpec pcs)
        {
            if (pcs == null || pcs.CategoryName.IsNullOrEmpty() || pcs.CounterName.IsNullOrEmpty())
            {
                return(false);
            }

            lock (mutex)
            {
                InitializeIfNeeded();

                try
                {
                    PerformanceCounterCategory pcc = null;

                    if (!pccDictionary.TryGetValue(pcs.CategoryName, out pcc) || pcc == null)
                    {
                        return(false);
                    }

                    PerformanceCounter [] perfCtrArray = null;

                    if (pcs.InstanceName.IsNullOrEmpty())
                    {
                        perfCtrArray = pcc.GetCounters();
                    }
                    else
                    {
                        if (!pcc.InstanceExists(pcs.InstanceName))
                        {
                            return(false);
                        }

                        perfCtrArray = pcc.GetCounters(pcs.InstanceName);
                    }

                    if (perfCtrArray.Any(pc => pc.CounterName == pcs.CounterName))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (System.Exception ex)
                {
                    Logger.Debug.Emit("IsValid on point '{0}' failed: {1}", pcs.PointName, ex.ToString(ExceptionFormat.TypeAndMessage));

                    return(false);
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// This extension method attempts to obtain and return the PerformanceCounterCategory object for a given PerformanceCounterSpec <paramref name="pcs"/>.  Returns null if the given CategoryName could not be found.
 /// </summary>
 public static PerformanceCounterCategory GetPerformanceCounterCategory(this PerformanceCounterSpec pcs)
 {
     return(PerformanceCounterCategoryHelper.GetPerformanceCounterCategory(pcs.CategoryName));
 }
コード例 #5
0
 /// <summary>
 /// This extension method returns true if the given PerformanceCounterSpec <paramref name="pcs"/> refers to a counter instance that exists in the indicated category
 /// </summary>
 public static bool IsValid(this PerformanceCounterSpec pcs)
 {
     return(PerformanceCounterCategoryHelper.IsValid(pcs));
 }