Beispiel #1
0
        private MeterValue GetValueWithSetItems(bool resetMetric)
        {
            double elapsed = _clock.Nanoseconds - _startTime;
            var    value   = base.GetValue(elapsed);

            Debug.Assert(_setMeters != null);

            var items = new MeterValue.SetItem[_setMeters.Count];
            var index = 0;

            foreach (var meter in _setMeters)
            {
                var itemValue = meter.Value.GetValue(elapsed);
                var percent   = value.Count > 0 ? itemValue.Count / (double)value.Count * 100 : 0.0;
                items[index++] = new MeterValue.SetItem(meter.Key, percent, itemValue);
                if (index == items.Length)
                {
                    break;
                }
            }

            Array.Sort(items, MeterValue.SetItemComparer);
            var result = new MeterValue(value.Count, value.MeanRate, value.OneMinuteRate, value.FiveMinuteRate, value.FifteenMinuteRate,
                                        TimeUnit.Seconds, items);

            if (resetMetric)
            {
                Reset();
            }
            return(result);
        }
Beispiel #2
0
 private static void TranslateMeterItem(MeterValue.SetItem item, MetricTelemetry mt, string unit, string dimensionName, string type)
 {
     mt.Properties[dimensionName]               = item.Item;
     mt.Properties[Constants.UnitKey]           = unit;
     mt.Properties[Constants.AppMetricsTypeKey] = type;
     mt.Sum = item.Value.MeanRate;
 }
Beispiel #3
0
        public static void PackMeterSetItems <T>(
            this ILineProtocolPayloadBuilder payloadBuilder,
            Func <string, string, string> metricNameFormatter,
            string context,
            MetricValueSourceBase <T> valueSource,
            MeterValue.SetItem setItem)
        {
            var itemData = new Dictionary <string, object>();

            setItem.Value.AddMeterValues(itemData);
            itemData.Add("percent", setItem.Percent);

            var keys   = itemData.Keys.ToList();
            var values = keys.Select(k => itemData[k]);

            var tags = MetricTags.Concat(valueSource.Tags, setItem.Tags);

            if (valueSource.Group.IsPresent())
            {
                var groupTag = new MetricTags(MetricGroupTagKey, metricNameFormatter(string.Empty, valueSource.Name));
                payloadBuilder.Pack(metricNameFormatter(context, valueSource.Group + MetricSetItemSuffix), keys, values, MetricTags.Concat(groupTag, tags));

                return;
            }

            payloadBuilder.Pack(metricNameFormatter(context, valueSource.Name + MetricSetItemSuffix), keys, values, setItem.Tags);
        }
        public static void PackMeterSetItems <T>(
            this ILineProtocolPayloadBuilder payloadBuilder,
            Func <string, string, string> metricNameFormatter,
            string context,
            MetricValueSourceBase <T> valueSource,
            MeterValue.SetItem setItem)
        {
            var itemData = new Dictionary <string, object>();

            setItem.Value.AddMeterValues(itemData);
            itemData.AddIfNotNanOrInfinity("percent", setItem.Percent);

            var keys   = itemData.Keys.ToList();
            var values = keys.Select(k => itemData[k]);

            var tags = MetricTags.Concat(valueSource.Tags, setItem.Tags);

            if (valueSource.IsMultidimensional)
            {
                payloadBuilder.Pack(
                    metricNameFormatter(context, valueSource.MultidimensionalName + MetricSetItemSuffix),
                    keys,
                    values,
                    tags);

                return;
            }

            payloadBuilder.Pack(metricNameFormatter(context, valueSource.Name + MetricSetItemSuffix), keys, values, setItem.Tags);
        }
 public static void AddMeterSetItemValues(
     this MeterValue.SetItem meterItem,
     out IDictionary <string, object> values,
     IDictionary <MeterValueDataKeys, string> dataKeys)
 {
     AddMeterKeyValues(meterItem.Value, out values, dataKeys);
     values.AddIfNotNanOrInfinity(dataKeys[MeterValueDataKeys.SetItemPercent], meterItem.Percent);
 }
        public void equality_with_not_equals_operator()
        {
            var meterValue = new MeterValue(1, 2, 3, 4, 5, TimeUnit.Seconds);

            var value = new MeterValue.SetItem("item", 0.5, meterValue);
            var other = new MeterValue.SetItem("item", 0.5, meterValue);

            (value != other).Should().Be(false);
        }
        public void equality_with_equals_true_when_same()
        {
            var meterValue = new MeterValue(1, 2, 3, 4, 5, TimeUnit.Seconds);

            var value = new MeterValue.SetItem("item", 0.5, meterValue);
            var other = new MeterValue.SetItem("item", 0.5, meterValue);

            value.Equals(other).Should().Be(true);
        }
        public void equality_with_equals_false_when_not_same_by_percent()
        {
            var meterValue = new MeterValue(1, 2, 3, 4, 5, TimeUnit.Seconds);

            var value = new MeterValue.SetItem("item", 0.5, meterValue);
            var other = new MeterValue.SetItem("item", 0.6, meterValue);

            value.Equals(other).Should().Be(false);
        }
        public static MetricValue ToMackerelMetric(this MeterValue.SetItem item)
        {
            var result = new MetricValue
            {
                name  = item.Item,
                value = item.Value.Count
            };

            return(result);
        }
Beispiel #10
0
        public static Metric ToPrometheusMetric(this MeterValue.SetItem item)
        {
            var result = new Metric
            {
                counter = new Counter
                {
                    value = item.Value.Count
                },
                label = item.Tags.ToLabelPairs()
            };

            return(result);
        }
Beispiel #11
0
        public static void AddMeterSetItemValues(
            this MeterValue.SetItem meterSetItem,
            IDictionary <string, object> values,
            IDictionary <MeterFields, string> fields)
        {
            if (values == null || !fields.ContainsKey(MeterFields.SetItem))
            {
                return;
            }

            AddMeterValues(meterSetItem.Value, values, fields);
            fields.TryAddValuesForKeyIfNotNanOrInfinity(values, MeterFields.SetItemPercent, meterSetItem.Percent);
        }
Beispiel #12
0
        public static Metric ToPrometheusMetric(this MeterValue.SetItem item, Func <string, string> labelNameFormatter)
        {
            var result = new Metric
            {
                counter = new Counter
                {
                    value = item.Value.Count
                },
                label = item.Tags.ToLabelPairs(labelNameFormatter)
            };

            return(result);
        }
Beispiel #13
0
        public static Metric ToPrometheusMetric(
            this MeterValue.SetItem item,
            List <LabelPair> parentTags,
            Func <string, string> labelNameFormatter)
        {
            var tags = item.Tags.ToLabelPairs(labelNameFormatter);

            tags.AddRange(parentTags);
            var result = new Metric
            {
                counter = new Counter
                {
                    value = item.Value.Count
                },
                label = tags
            };

            return(result);
        }
 internal static void CopyTo(this MeterValue.SetItem value, MetricTelemetry mt, string unit)
 {
     mt.Sum = value.Value.MeanRate;
     mt.Properties[UnitKey] = unit;
     value.Tags.CopyTo(mt);
 }