public override void Observe(long value, LabelSet labelset)
        {
            // TODO cleanup of handle/aggregator.   Issue #530
            var boundInstrument =
                this.observerHandles.GetOrAdd(labelset, new Int64ObserverMetricHandleSdk());

            boundInstrument.Observe(value);
        }
Esempio n. 2
0
        internal BoundCounterMetric <T> Bind(LabelSet labelset, bool isShortLived)
        {
            BoundCounterMetricSdkBase <T> boundInstrument;

            lock (this.bindUnbindLock)
            {
                var recStatus = isShortLived ? RecordStatus.UpdatePending : RecordStatus.Bound;
                boundInstrument = this.counterBoundInstruments.GetOrAdd(labelset, this.CreateMetric(recStatus));
            }

            switch (boundInstrument.Status)
            {
            case RecordStatus.NoPendingUpdate:
                boundInstrument.Status = RecordStatus.UpdatePending;
                break;

            case RecordStatus.CandidateForRemoval:
            {
                // if boundInstrument is marked for removal, then take the
                // lock to sync with Unbind() and re-add. As Collect() might have called Unbind().

                /*
                 * If Unbind gets the lock first, then it'd have removed the record.
                 * But it gets added again by Bind() so no record is lost.
                 * If Bind method gets this lock first, it'd promote record to UpdatePending, so that
                 * Unbind will leave this record untouched.
                 *
                 * Additional notes:
                 * This lock is never taken for bound instruments, and they offer the fastest performance.
                 * This lock is only taken for those labelsets which are marked CandidateForRemoval.
                 * It means the the 1st time a labelset is re-encountered after two Collect() has occurred,
                 * this lock must be taken. Subsequent usage of this labelset before the next two Collect()
                 * will already have status promoted, and no lock is taken.
                 * In effect, the lock is only taken for those labelsets
                 * which was used once, then not used for two collect(), and then used within the subsequent
                 * Collect().
                 *
                 * Its important to note that, for a brand new LabelSet being encountered for the 1st time, lock is not
                 * taken. Lock is taken only during the 1st re-appearance of a LabelSet after a Collect period.
                 *
                 */

                lock (this.bindUnbindLock)
                {
                    boundInstrument.Status = RecordStatus.UpdatePending;

                    this.counterBoundInstruments.GetOrAdd(labelset, boundInstrument);
                }

                break;
            }
            }

            return(boundInstrument);
        }
Esempio n. 3
0
        public override GaugeHandle <T> GetHandle(LabelSet labelset)
        {
            if (!this.gaugeHandles.TryGetValue(labelset, out var handle))
            {
                handle = new GaugeHandleSdk <T>();

                this.gaugeHandles.Add(labelset, handle);
            }

            return(handle);
        }
        public override ObserverMetricHandle <T> GetHandle(LabelSet labelset)
        {
            if (!this.observerHandles.TryGetValue(labelset, out var handle))
            {
                handle = new ObserverMetricHandleSdk <T>();

                this.observerHandles.Add(labelset, handle);
            }

            return(handle);
        }
Esempio n. 5
0
        public override BoundCounterMetric <T> Bind(LabelSet labelset)
        {
            if (!this.counterBoundInstruments.TryGetValue(labelset, out var boundInstrument))
            {
                boundInstrument = new BoundCounterMetricSdk <T>();

                this.counterBoundInstruments.Add(labelset, boundInstrument);
            }

            return(boundInstrument);
        }
        public override void Observe(long value, LabelSet labelset)
        {
            if (!this.observerHandles.TryGetValue(labelset, out var boundInstrument))
            {
                boundInstrument = new Int64ObserverMetricHandleSdk();
                // TODO cleanup of handle/aggregator.   Issue #530
                this.observerHandles.Add(labelset, boundInstrument);
            }

            boundInstrument.Observe(value);
        }
Esempio n. 7
0
        public override MeasureHandle <T> GetHandle(LabelSet labelset)
        {
            if (!this.measureHandles.TryGetValue(labelset, out var handle))
            {
                handle = new MeasureHandleSDK <T>();

                this.measureHandles.Add(labelset, handle);
            }

            return(handle);
        }
        public override BoundMeasureMetric <T> Bind(LabelSet labelset)
        {
            if (!this.measureBoundInstruments.TryGetValue(labelset, out var boundInstrument))
            {
                boundInstrument = this.CreateMetric();

                this.measureBoundInstruments.Add(labelset, boundInstrument);
            }

            return(boundInstrument);
        }
 internal void UnBind(LabelSet labelSet)
 {
     lock (this.bindUnbindLock)
     {
         if (this.counterBoundInstruments.TryGetValue(labelSet, out var boundInstrument))
         {
             // Check status again, inside lock as an instrument update
             // might have occurred which promoted this record.
             if (boundInstrument.Status == RecordStatus.CandidateForRemoval)
             {
                 this.counterBoundInstruments.Remove(labelSet);
             }
         }
     }
 }
 /// <inheritdoc/>
 public override CounterHandle <T> GetHandle(LabelSet labelset)
 {
     return(NoOpCounterHandle <T> .Instance);
 }
 /// <summary>
 /// Gets the bound measure metric with given labelset.
 /// </summary>
 /// <param name="labelset">The labelset from which bound instrument should be constructed.</param>
 /// <returns>The bound measure metric.</returns>
 public abstract BoundMeasureMetric <T> Bind(LabelSet labelset);
 /// <inheritdoc/>
 public override void Observe(double value, LabelSet labelset)
 {
 }
 /// <summary>
 /// Observes a value.
 /// </summary>
 /// <param name="value">value to observe.</param>
 /// <param name="labelset">The labelset associated with this value.</param>
 public abstract void Observe(double value, LabelSet labelset);
Esempio n. 14
0
 /// <inheritdoc/>
 public override GaugeHandle <T> GetHandle(LabelSet labelset)
 {
     return(NoOpGaugeHandle <T> .Instance);
 }
Esempio n. 15
0
 public CounterHandleSDK(string metricName, LabelSet labelset, MetricProcessor <T> metricProcessor) : this()
 {
     this.metricProcessor = metricProcessor;
     this.labelset        = labelset;
 }
 public override BoundCounterMetric <T> Bind(LabelSet labelset)
 {
     // user making Bind call means record is not shortlived.
     return(this.Bind(labelset, isShortLived: false));
 }
Esempio n. 17
0
 /// <inheritdoc/>
 public override BoundMeasureMetric <T> Bind(LabelSet labelset)
 {
     return(NoOpBoundMeasureMetric <T> .Instance);
 }
 /// <inheritdoc/>
 public override ObserverMetricHandle <T> GetHandle(LabelSet labelset)
 {
     return(NoOpObserverMetricHandle <T> .Instance);
 }
Esempio n. 19
0
 public override CounterHandle <T> GetHandle(LabelSet labelset)
 {
     return(new CounterHandleSDK <T>(this.metricName, labelset, this.metricProcessor));
 }
 /// <summary>
 /// Gets the handle with given labelset.
 /// </summary>
 /// <param name="labelset">The labelset from which handle should be constructed.</param>
 /// <returns>The handle.</returns>
 public abstract ObserverMetricHandle <T> GetHandle(LabelSet labelset);
Esempio n. 21
0
 /// <summary>
 /// Gets the handle with given labelset.
 /// </summary>
 /// <param name="labelset">The labelset from which handle should be constructed.</param>
 /// <returns>The handle.</returns>
 public abstract GaugeHandle <T> GetHandle(LabelSet labelset);
 public override BoundMeasureMetric <T> Bind(LabelSet labelset)
 {
     return(this.measureBoundInstruments.GetOrAdd(labelset, this.CreateMetric()));
 }
Esempio n. 23
0
 /// <summary>
 /// Gets the handle with given labelset.
 /// </summary>
 /// <param name="labelset">The labelset from which handle should be constructed.</param>
 /// <returns>The handle.</returns>
 public abstract CounterHandle <T> GetHandle(LabelSet labelset);
Esempio n. 24
0
 /// <summary>
 /// Gets the bound counter metric with given labelset.
 /// </summary>
 /// <param name="labelset">The labelset from which bound instrument should be constructed.</param>
 /// <returns>The bound counter metric.</returns>
 public abstract BoundCounterMetric <T> Bind(LabelSet labelset);
Esempio n. 25
0
 /// <summary>
 /// Observes a value.
 /// </summary>
 /// <param name="value">value to observe.</param>
 /// <param name="labelset">The labelset associated with this value.</param>
 public abstract void Observe(long value, LabelSet labelset);
 /// <inheritdoc/>
 public override MeasureHandle <T> GetHandle(LabelSet labelset)
 {
     return(NoOpMeasureHandle <T> .Instance);
 }
Esempio n. 27
0
 /// <inheritdoc/>
 public override void Observe(long value, LabelSet labelset)
 {
 }
Esempio n. 28
0
 /// <summary>
 /// Gets the handle with given labelset.
 /// </summary>
 /// <param name="labelset">The labelset from which handle should be constructed.</param>
 /// <returns>The handle.</returns>
 public abstract MeasureHandle <T> GetHandle(LabelSet labelset);