コード例 #1
0
        /// <summary>
        /// Create a new metric object with the provided instance name and add it to the collection
        /// </summary>
        /// <param name="instanceName">The instance name to use, or blank or null for the default metric.</param>
        /// <returns>The new metric object that was added to the collection</returns>
        public CustomSampledMetric Add(string instanceName)
        {
            //Create a new metric object with the provided instance name (it will get added to us automatically)
            CustomSampledMetric newMetric = new CustomSampledMetric(Definition, instanceName);

            //finally, return the newly created metric object to our caller
            return(newMetric);
        }
コード例 #2
0
        /// <summary>
        /// Write a metric sample to the specified metric instance with the provided data immediately, creating the metric if it doesn't exist.
        /// </summary>
        /// <remarks>The sample is immediately written to the log. If you are sampling multiple metrics at the same time,
        /// it is faster to create each of the samples and write them with one call to Log.Write instead of writing them out
        /// individually.  To do this, you can use CreateMetricSample</remarks>
        /// <param name="instanceName">The instance name to use, or blank or null for the default metric.</param>
        /// <param name="rawValue">The raw data value</param>
        /// <param name="rawTimeStamp">The exact date and time the raw value was determined</param>
        /// <param name="baseValue">The reference value to compare against for come counter types</param>
        public void WriteSample(string instanceName, double rawValue, double baseValue, DateTimeOffset rawTimeStamp)
        {
            //Find the right metric sample instance, creating it if we have to.
            CustomSampledMetric ourMetric = EnsureMetricExists(instanceName);

            //now that we have the right metric object, its time to go ahead and create the sample.
            ourMetric.WriteSample(rawValue, baseValue, rawTimeStamp);
        }
コード例 #3
0
        /// <summary>
        /// Retrieve an item from the collection by its key if present.  If not present, the default value of the object is returned.
        /// </summary>
        /// <param name="key">The metric name to locate in the collection</param>
        /// <param name="value">When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param>
        /// <returns>true if the collection contains an element with the specified key; otherwise false.</returns>
        public bool TryGetValue(string key, out CustomSampledMetric value)
        {
            //We are playing a few games to get native typing here.  Because it's an OUt value, we
            //have to swap types around ourselves so we can cast.
            IMetric innerValue;

            //gateway to our inner dictionary try get value
            bool result = base.TryGetValue(key, out innerValue);

            value = (CustomSampledMetric)innerValue;

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Retrieves the specified metric instance, or creates it if it doesn't exist
        /// </summary>
        /// <param name="instanceName"></param>
        /// <returns>The custom sampled metric object.</returns>
        private CustomSampledMetric EnsureMetricExists(string instanceName)
        {
            //Find the right metric sample instance, creating it if we have to.
            string  metricKey = MetricDefinition.GetKey(this, instanceName);
            IMetric ourMetric;

            //This must be protected in a multi-threaded environment
            lock (Metrics.Lock)
            {
                if (Metrics.TryGetValue(metricKey, out ourMetric) == false)
                {
                    //it doesn't exist - go ahead and add it
                    ourMetric = new CustomSampledMetric(this, instanceName);
                }
            }

            //and return the metric
            return((CustomSampledMetric)ourMetric);
        }
コード例 #5
0
        private double? m_BaseValue; //We calculate this on first reference, then cache the result because it can take time.

        /// <summary>
        /// Create a new sample object for the provided metric and raw sample packet.
        /// </summary>
        /// <remarks>The metric sample is automatically added to the samples collection of the provided metric object.</remarks>
        /// <param name="metric">The metric object this sample applies to.</param>
        /// <param name="metricSamplePacket">The raw sample data packet.</param>
        internal CustomSampledMetricSample(CustomSampledMetric metric, CustomSampledMetricSamplePacket metricSamplePacket)
            : base(metric, metricSamplePacket, (metric.Definition).RequiresMultipleSamples)
        {

        }
コード例 #6
0
 /// <summary>
 /// Create a new sample collection for the specified metric object
 /// </summary>
 /// <param name="metric"></param>
 internal CustomSampledMetricSampleCollection(CustomSampledMetric metric)
     : base(metric)
 {
     m_CustomSampledMetric = metric;
 }
コード例 #7
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);
            }
        }