/// <summary> /// The create. /// </summary> /// <param name="dataSamples"> /// The data samples. /// </param> /// <returns> /// an array of counter samples /// </returns> public static IEnumerable <CounterAggregation> Create(ICollection <CounterSampleMessage> dataSamples) { if (dataSamples.Count == 0) { return(new CounterAggregation[0]); } var result = new Dictionary <string, CounterAggregation>(); // add other values foreach (CounterSampleMessage sample in dataSamples) { CounterAggregation aggregation; if (result.TryGetValue(sample.CounterName, out aggregation) == false) { aggregation = new CounterAggregation { CounterName = sample.CounterName, Timestamps = new List <long>(), Values = new List <float>() }; result.Add(aggregation.CounterName, aggregation); } aggregation.Timestamps.Add(sample.CounterSample.Timestamp.ToBinary()); aggregation.Values.Add(sample.CounterSample.Value); } return(result.Values.ToArray()); }
/// <summary> /// The publish counter data. /// </summary> /// <param name="peer"> /// The client peer. /// </param> /// <param name="counterSamples"> /// The counter samples. /// </param> private static void PublishCounterData(PeerBase peer, ICollection <CounterSampleMessage> counterSamples) { IEnumerable <CounterAggregation> aggregations = CounterAggregation.Create(counterSamples); foreach (CounterAggregation aggregation in aggregations) { var @event = new CounterDataEvent { Name = aggregation.CounterName, TimeStamps = aggregation.Timestamps.ToArray(), Values = aggregation.Values.ToArray() }; var eventData = new EventData((byte)EventCode.CounterData, @event); // already in right fiber, we would use peer.SendEvent otherwise peer.SendEvent(eventData, new SendParameters { ChannelId = Settings.DiagnosticsEventChannel }); } }
public static IEnumerable<CounterAggregation> Create(ICollection<CounterSampleMessage> dataSamples) { if (dataSamples.Count == 0) { return new CounterAggregation[0]; } var result = new Dictionary<string, CounterAggregation>(); // add other values foreach (CounterSampleMessage sample in dataSamples) { CounterAggregation aggregation; if (result.TryGetValue(sample.CounterName, out aggregation) == false) { aggregation = new CounterAggregation { CounterName = sample.CounterName, Timestamps = new List<long>(), Values = new List<float>() }; result.Add(aggregation.CounterName, aggregation); } aggregation.Timestamps.Add(sample.CounterSample.Timestamp.ToBinary()); aggregation.Values.Add(sample.CounterSample.Value); } return result.Values.ToArray(); }