Пример #1
0
 /// <summary>Retrieves all the records managed by this MetricsContext.</summary>
 /// <remarks>
 /// Retrieves all the records managed by this MetricsContext.
 /// Useful for monitoring systems that are polling-based.
 /// </remarks>
 /// <returns>A non-null collection of all monitoring records.</returns>
 public override IDictionary <string, ICollection <OutputRecord> > GetAllRecords()
 {
     lock (this)
     {
         IDictionary <string, ICollection <OutputRecord> > @out = new SortedDictionary <string
                                                                                        , ICollection <OutputRecord> >();
         foreach (KeyValuePair <string, AbstractMetricsContext.RecordMap> recordEntry in bufferedData)
         {
             AbstractMetricsContext.RecordMap recordMap = recordEntry.Value;
             lock (recordMap)
             {
                 IList <OutputRecord> records = new AList <OutputRecord>();
                 ICollection <KeyValuePair <AbstractMetricsContext.TagMap, AbstractMetricsContext.MetricMap
                                            > > entrySet = recordMap;
                 foreach (KeyValuePair <AbstractMetricsContext.TagMap, AbstractMetricsContext.MetricMap
                                        > entry in entrySet)
                 {
                     OutputRecord outRec = new OutputRecord(entry.Key, entry.Value);
                     records.AddItem(outRec);
                 }
                 @out[recordEntry.Key] = records;
             }
         }
         return(@out);
     }
 }
Пример #2
0
 /// <summary>Creates a new AbstractMetricsRecord instance with the given <code>recordName</code>.
 ///     </summary>
 /// <remarks>
 /// Creates a new AbstractMetricsRecord instance with the given <code>recordName</code>.
 /// Throws an exception if the metrics implementation is configured with a fixed
 /// set of record names and <code>recordName</code> is not in that set.
 /// </remarks>
 /// <param name="recordName">the name of the record</param>
 /// <exception cref="Org.Apache.Hadoop.Metrics.MetricsException">if recordName conflicts with configuration data
 ///     </exception>
 public sealed override MetricsRecord CreateRecord(string recordName)
 {
     lock (this)
     {
         if (bufferedData[recordName] == null)
         {
             bufferedData[recordName] = new AbstractMetricsContext.RecordMap();
         }
         return(NewRecord(recordName));
     }
 }
Пример #3
0
        /// <summary>Called by MetricsRecordImpl.remove().</summary>
        /// <remarks>
        /// Called by MetricsRecordImpl.remove().  Removes all matching rows in
        /// the internal table of metric data.  A row matches if it has the same
        /// tag names and values as record, but it may also have additional
        /// tags.
        /// </remarks>
        protected internal virtual void Remove(MetricsRecordImpl record)
        {
            string recordName = record.GetRecordName();

            AbstractMetricsContext.TagMap    tagTable  = record.GetTagTable();
            AbstractMetricsContext.RecordMap recordMap = GetRecordMap(recordName);
            lock (recordMap)
            {
                IEnumerator <AbstractMetricsContext.TagMap> it = recordMap.Keys.GetEnumerator();
                while (it.HasNext())
                {
                    AbstractMetricsContext.TagMap rowTags = it.Next();
                    if (rowTags.ContainsAll(tagTable))
                    {
                        it.Remove();
                    }
                }
            }
        }
Пример #4
0
 /// <summary>Emits the records.</summary>
 /// <exception cref="System.IO.IOException"/>
 private void EmitRecords()
 {
     lock (this)
     {
         foreach (KeyValuePair <string, AbstractMetricsContext.RecordMap> recordEntry in bufferedData)
         {
             AbstractMetricsContext.RecordMap recordMap = recordEntry.Value;
             lock (recordMap)
             {
                 ICollection <KeyValuePair <AbstractMetricsContext.TagMap, AbstractMetricsContext.MetricMap
                                            > > entrySet = recordMap;
                 foreach (KeyValuePair <AbstractMetricsContext.TagMap, AbstractMetricsContext.MetricMap
                                        > entry in entrySet)
                 {
                     OutputRecord outRec = new OutputRecord(entry.Key, entry.Value);
                     EmitRecord(contextName, recordEntry.Key, outRec);
                 }
             }
         }
         Flush();
     }
 }
Пример #5
0
        /// <summary>Called by MetricsRecordImpl.update().</summary>
        /// <remarks>
        /// Called by MetricsRecordImpl.update().  Creates or updates a row in
        /// the internal table of metric data.
        /// </remarks>
        protected internal virtual void Update(MetricsRecordImpl record)
        {
            string recordName = record.GetRecordName();

            AbstractMetricsContext.TagMap     tagTable      = record.GetTagTable();
            IDictionary <string, MetricValue> metricUpdates = record.GetMetricTable();

            AbstractMetricsContext.RecordMap recordMap = GetRecordMap(recordName);
            lock (recordMap)
            {
                AbstractMetricsContext.MetricMap metricMap = recordMap[tagTable];
                if (metricMap == null)
                {
                    metricMap = new AbstractMetricsContext.MetricMap();
                    AbstractMetricsContext.TagMap tagMap = new AbstractMetricsContext.TagMap(tagTable
                                                                                             );
                    // clone tags
                    recordMap[tagMap] = metricMap;
                }
                ICollection <KeyValuePair <string, MetricValue> > entrySet = metricUpdates;
                foreach (KeyValuePair <string, MetricValue> entry in entrySet)
                {
                    string      metricName    = entry.Key;
                    MetricValue updateValue   = entry.Value;
                    Number      updateNumber  = updateValue.GetNumber();
                    Number      currentNumber = metricMap[metricName];
                    if (currentNumber == null || updateValue.IsAbsolute())
                    {
                        metricMap[metricName] = updateNumber;
                    }
                    else
                    {
                        Number newNumber = Sum(updateNumber, currentNumber);
                        metricMap[metricName] = newNumber;
                    }
                }
            }
        }