/// <summary>
 /// Create a new custom sampled metric object from the provided raw data packet
 /// </summary>
 /// <remarks>The new metric will automatically be added to the metric definition's metrics collection.</remarks>
 /// <param name="definition">The metric definition for the metric instance</param>
 /// <param name="packet">The raw data packet</param>
 internal CustomSampledMetric(CustomSampledMetricDefinition definition, CustomSampledMetricPacket packet)
     : base(definition, packet)
 {
     // We created a CustomSampledMetricSampleCollection when base constructor called our OnSampleCollectionCreate().
     m_Samples          = (CustomSampledMetricSampleCollection)base.Samples;
     m_MetricDefinition = definition;
     m_Packet           = packet;
 }
        /// <summary>Creates a new metric instance from the provided definition information, or returns any existing instance if found.</summary>
        /// <remarks>If the metric definition doesn't exist, it will be created.  If the metric doesn't exist, it will be created.
        /// If the metric definition does exist, but is not a Custom Sampled Metric (or a derived class) an exception will be thrown.</remarks>
        /// <param name="definitions">The definitions dictionary this definition is a part of</param>
        /// <param name="metricTypeName">The unique metric type</param>
        /// <param name="categoryName">The name of the category with which this definition is associated.</param>
        /// <param name="counterName">The name of the definition within the category.</param>
        /// <param name="metricSampleType">The type of data captured for each metric under this definition.</param>
        /// <param name="instanceName">The unique name of this instance within the metric's collection.</param>
        public static CustomSampledMetric AddOrGet(MetricDefinitionCollection definitions, string metricTypeName, string categoryName, string counterName, MetricSampleType metricSampleType, string instanceName)
        {
            //we must have a definitions collection, or we have a problem
            if (definitions == null)
            {
                throw new ArgumentNullException(nameof(definitions));
            }

            //we need to find the definition, adding it if necessary
            string            definitionKey = MetricDefinition.GetKey(metricTypeName, categoryName, counterName);
            IMetricDefinition definition;

            //Establish a lock on the definitions collection so our lookup & create are atomic.
            lock (definitions.Lock)
            {
                if (definitions.TryGetValue(definitionKey, out definition))
                {
                    //if the metric definition exists, but is of the wrong type we have a problem.
                    if ((definition is CustomSampledMetricDefinition) == false)
                    {
                        throw new ArgumentException("A metric already exists with the provided type, category, and counter name but it is not compatible with being a custom sampled metric.  Please use a different counter name.", nameof(counterName));
                    }
                }
                else
                {
                    //we didn't find one, make a new one
                    definition =
                        new CustomSampledMetricDefinition(definitions, metricTypeName, categoryName, counterName,
                                                          metricSampleType);
                }
            }

            //now we have our definition, proceed to create a new metric if it doesn't exist
            string  metricKey = MetricDefinition.GetKey(metricTypeName, categoryName, counterName, instanceName);
            IMetric metric;

            //see if we can get the metric already.  If not, we'll create it
            lock (((MetricCollection)definition.Metrics).Lock)
            {
                if (definition.Metrics.TryGetValue(metricKey, out metric) == false)
                {
                    metric = new CustomSampledMetric((CustomSampledMetricDefinition)definition, instanceName);
                }
            }

            return((CustomSampledMetric)metric);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new custom sampled metric dictionary for the provided definition.
 /// </summary>
 /// <remarks>This dictionary is created automatically by the Custom Sampled Metric Definition during its initialization.</remarks>
 /// <param name="metricDefinition">The definition of the custom sampled metric to create a metric dictionary for</param>
 internal CustomSampledMetricDictionary(CustomSampledMetricDefinition metricDefinition)
     : base(metricDefinition)
 {
 }
Exemplo n.º 4
0
        /// <summary>
        /// Register all of the individual metrics we use
        /// </summary>
        private void Register()
        {
            lock (m_Lock)
            {
                //register our process-wide metrics
                CustomSampledMetricDefinition curSampledMetricDefinition;

                curSampledMetricDefinition             = new CustomSampledMetricDefinition(Log.Metrics, ProcessMetricType, "Process.Processor", CounterTotalProcessorTime, MetricSampleType.TotalFraction);
                curSampledMetricDefinition.Description = "The percentage of processor capacity used by the process.";
                curSampledMetricDefinition.UnitCaption = "%";
                m_ProcessPercentProcessorTime          = curSampledMetricDefinition.Metrics.Add(null);

                curSampledMetricDefinition             = new CustomSampledMetricDefinition(Log.Metrics, ProcessMetricType, "Process.Processor", CounterUserProcessorTime, MetricSampleType.TotalFraction);
                curSampledMetricDefinition.Description = "The percentage of processor capacity used by the process for non-privileged tasks.";
                curSampledMetricDefinition.UnitCaption = "%";
                m_ProcessPercentUserProcessorTime      = curSampledMetricDefinition.Metrics.Add(null);

                curSampledMetricDefinition              = new CustomSampledMetricDefinition(Log.Metrics, ProcessMetricType, "Process.Processor", CounterPrivilegedProcessorTime, MetricSampleType.TotalFraction);
                curSampledMetricDefinition.Description  = "The percentage of processor capacity used by the process for privileged tasks.";
                curSampledMetricDefinition.UnitCaption  = "%";
                m_ProcessPercentPrivilegedProcessorTime = curSampledMetricDefinition.Metrics.Add(null);

                curSampledMetricDefinition             = new CustomSampledMetricDefinition(Log.Metrics, ProcessMetricType, "Process.Memory", CounterNonpagedSystemMemorySize, MetricSampleType.RawCount);
                curSampledMetricDefinition.Description = "The amount of nonpaged system memory allocated for the process.";
                curSampledMetricDefinition.UnitCaption = "Bytes";
                m_ProcessNonpagedSystemMemorySize      = curSampledMetricDefinition.Metrics.Add(null);

                curSampledMetricDefinition             = new CustomSampledMetricDefinition(Log.Metrics, ProcessMetricType, "Process.Memory", CounterPagedMemorySize, MetricSampleType.RawCount);
                curSampledMetricDefinition.Description = "The amount of paged memory allocated for the process.";
                curSampledMetricDefinition.UnitCaption = "Bytes";
                m_ProcessPagedMemorySize = curSampledMetricDefinition.Metrics.Add(null);

                curSampledMetricDefinition             = new CustomSampledMetricDefinition(Log.Metrics, ProcessMetricType, "Process.Memory", CounterPagedSystemMemorySize, MetricSampleType.RawCount);
                curSampledMetricDefinition.Description = "The amount of pageable system memory allocated for the process.";
                curSampledMetricDefinition.UnitCaption = "Bytes";
                m_ProcessPagedSystemMemorySize         = curSampledMetricDefinition.Metrics.Add(null);

                curSampledMetricDefinition             = new CustomSampledMetricDefinition(Log.Metrics, ProcessMetricType, "Process.Memory", CounterPeakPagedMemorySize, MetricSampleType.RawCount);
                curSampledMetricDefinition.Description = "The maximum amount of memory in the virtual memory paging file for the process.";
                curSampledMetricDefinition.UnitCaption = "Bytes";
                m_ProcessPeakPagedMemorySize           = curSampledMetricDefinition.Metrics.Add(null);

                curSampledMetricDefinition             = new CustomSampledMetricDefinition(Log.Metrics, ProcessMetricType, "Process.Memory", CounterPeakVirtualMemorySize, MetricSampleType.RawCount);
                curSampledMetricDefinition.Description = "The maximum amount of virtual memory used for the process.";
                curSampledMetricDefinition.UnitCaption = "Bytes";
                m_ProcessPeakVirtualMemorySize         = curSampledMetricDefinition.Metrics.Add(null);

                curSampledMetricDefinition             = new CustomSampledMetricDefinition(Log.Metrics, ProcessMetricType, "Process.Memory", CounterPeakWorkingSet, MetricSampleType.RawCount);
                curSampledMetricDefinition.Description = "The maximum amount of physical memory used for the process.";
                curSampledMetricDefinition.UnitCaption = "Bytes";
                m_ProcessPeakWorkingSet = curSampledMetricDefinition.Metrics.Add(null);

                curSampledMetricDefinition             = new CustomSampledMetricDefinition(Log.Metrics, ProcessMetricType, "Process.Memory", CounterPrivateMemorySize, MetricSampleType.RawCount);
                curSampledMetricDefinition.Description = "The amount of private memory allocated for the process.";
                curSampledMetricDefinition.UnitCaption = "Bytes";
                m_ProcessPrivateMemorySize             = curSampledMetricDefinition.Metrics.Add(null);

                curSampledMetricDefinition             = new CustomSampledMetricDefinition(Log.Metrics, ProcessMetricType, "Process.Memory", CounterVirtualMemorySize, MetricSampleType.RawCount);
                curSampledMetricDefinition.Description = "The amount of virtual memory allocated for the process.";
                curSampledMetricDefinition.UnitCaption = "Bytes";
                m_ProcessVirtualMemorySize             = curSampledMetricDefinition.Metrics.Add(null);

                curSampledMetricDefinition             = new CustomSampledMetricDefinition(Log.Metrics, ProcessMetricType, "Process.Memory", CounterWorkingSet, MetricSampleType.RawCount);
                curSampledMetricDefinition.Description = "The amount of physical memory allocated for the process.";
                curSampledMetricDefinition.UnitCaption = "Bytes";
                m_ProcessWorkingSet = curSampledMetricDefinition.Metrics.Add(null);
            }
        }
 /// <summary>
 /// Create a new custom sampled metric object from the provided metric definition
 /// </summary>
 /// <remarks>The new metric will automatically be added to the metric definition's metrics collection.</remarks>
 /// <param name="definition">The metric definition for the metric instance</param>
 /// <param name="instanceName">The unique name of this instance within the metric's collection.</param>
 public CustomSampledMetric(CustomSampledMetricDefinition definition, string instanceName)
     : this(definition, new CustomSampledMetricPacket(definition.Packet, instanceName))
 {
 }