private MeterValue GetValueWithSetItems(bool resetMetric) { double elapsed = _clock.Nanoseconds - _startTime; var value = GetValue(elapsed); Debug.Assert(_setMeters != null, "set meters not 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); }
public static MeterValueSource FromSerializableMetric(this MeterMetric source) { var rateUnit = source.RateUnit.FromUnit(); var items = source.Items.Select( i => { var value = new MeterValue( i.Count, i.MeanRate, i.OneMinuteRate, i.FiveMinuteRate, i.FifteenMinuteRate, rateUnit); return(new MeterValue.SetItem( i.Item, i.Percent, value)); }). ToArray(); var meterValue = new MeterValue( source.Count, source.MeanRate, source.OneMinuteRate, source.FiveMinuteRate, source.FifteenMinuteRate, rateUnit, items); return(new MeterValueSource( source.Name, source.Group, ConstantValue.Provider(meterValue), source.Unit, rateUnit, source.Tags.FromDictionary())); }
public SetItem(string item, double percent, MeterValue value) { Item = item; Percent = percent; Value = value; }