Beispiel #1
0
        private static void Test13()
        {
            ConcurrentDictionary <AggregationKey, List <string> > dic = new ConcurrentDictionary <AggregationKey, List <string> >();
            DateTime d1 = DateTime.Now.RoundTo(TimeSpan.FromSeconds(1));
            DateTime d2 = d1;
            DateTime d3 = d2.AddSeconds(5);

            Dictionary <string, string> dic1 = new Dictionary <string, string>();

            dic1["e1"] = "v1";
            dic1["e2"] = "v2";
            dic1["e3"] = "v3";
            dic1["e4"] = "v4";
            Dictionary <string, string> dic2 = new Dictionary <string, string>();

            dic2["e1"] = "v1";
            dic2["e2"] = "v2";
            dic2["e3"] = "v3";
            dic2["e4"] = "v5";
            Dictionary <string, string> dic3 = new Dictionary <string, string>();

            dic3["e1"] = "v1";
            dic3["e2"] = "v2";
            dic3["e3"] = "v3";
            dic3["e4"] = "v4";
            AggregationKey ak1 = new AggregationKey(d1, dic1);
            AggregationKey ak2 = new AggregationKey(d2, dic2);
            AggregationKey ak3 = new AggregationKey(d3, dic3);

            dic.GetOrAdd(ak1, new List <string>()).Add("f1");
            dic.GetOrAdd(ak2, new List <string>()).Add("f2");
            dic.GetOrAdd(ak3, new List <string>()).Add("f3");
            Console.ReadLine();
        }
        private static void Test13()
        {
            ConcurrentDictionary<AggregationKey, List<string>> dic = new ConcurrentDictionary<AggregationKey, List<string>>();
            DateTime d1 = DateTime.Now.RoundTo(TimeSpan.FromSeconds(1));
            DateTime d2 = d1;
            DateTime d3 = d2.AddSeconds(5);

            Dictionary<string, string> dic1 = new Dictionary<string, string>();
            dic1["e1"] = "v1";
            dic1["e2"] = "v2";
            dic1["e3"] = "v3";
            dic1["e4"] = "v4";
            Dictionary<string, string> dic2 = new Dictionary<string, string>();
            dic2["e1"] = "v1";
            dic2["e2"] = "v2";
            dic2["e3"] = "v3";
            dic2["e4"] = "v5";
            Dictionary<string, string> dic3 = new Dictionary<string, string>();
            dic3["e1"] = "v1";
            dic3["e2"] = "v2";
            dic3["e3"] = "v3";
            dic3["e4"] = "v4";
            AggregationKey ak1 = new AggregationKey(d1,dic1);
            AggregationKey ak2 = new AggregationKey(d2,dic2);
            AggregationKey ak3 = new AggregationKey(d3,dic3);
            dic.GetOrAdd(ak1,new List<string>()).Add("f1");
            dic.GetOrAdd(ak2,new List<string>()).Add("f2");
            dic.GetOrAdd(ak3,new List<string>()).Add("f3");
            Console.ReadLine();
        }
Beispiel #3
0
        private static AggregatedValue ParseAggregatedValue(StoredCounter entry)
        {
            DateTime date = entry.Date;
            Dictionary <string, string> properties = entry.Props;
            AggregationKey  ak  = new AggregationKey(date, properties);
            AggregatedValue val = new AggregatedValue(ak);

            if (entry.Data.Sum != null)
            {
                val.AddResult(new AggregationOperationResult(AggregationType.Sum, entry.Data.Sum.Value));
            }
            if (entry.Data.Count != null)
            {
                val.AddResult(new AggregationOperationResult(AggregationType.Count, entry.Data.Count.Value));
            }
            if (entry.Data.Min != null)
            {
                val.AddResult(new AggregationOperationResult(AggregationType.Min, entry.Data.Min.Min()));
            }
            if (entry.Data.Max != null)
            {
                val.AddResult(new AggregationOperationResult(AggregationType.Max, entry.Data.Max.Max()));
            }
            if (entry.Data.Avg != null)
            {
                val.AddResult(new AggregationOperationResult(AggregationType.Avg, entry.Data.Avg.Average()));
            }
            if (entry.Data.RawValues != null)
            {
                val.AddRawValues(entry.Data.RawValues);
            }
            return(val);
        }
Beispiel #4
0
        private static AggregatedValue ParseAggregatedValue(BsonDocument entry)
        {
            DateTime date = entry["date"].AsDateTime;
            Dictionary <string, string> properties = !entry.Contains("props")? new Dictionary <string, string>() :
                                                     entry["props"].AsBsonDocument.Where(kvp => kvp.Name != "pCnt").ToDictionary(kvp => kvp.Name,
                                                                                                                                 kvp => kvp.Value.AsString);
            AggregationKey  ak  = new AggregationKey(date, properties);
            AggregatedValue val = new AggregatedValue(ak);

            foreach (var dataElement in entry["data"].AsBsonDocument)
            {
                AggregationType at;
                if (AggregationTypeParser.TryParse(dataElement.Name, out at))
                {
                    switch (at)
                    {
                    case AggregationType.Sum:
                    case AggregationType.Count:
                        val.AddResult(new AggregationOperationResult(at, dataElement.Value.AsDouble));
                        break;

                    case AggregationType.Min:
                        val.AddResult(new AggregationOperationResult(at,
                                                                     dataElement.Value.AsBsonArray.Select(
                                                                         v => v.AsDouble).Min()));
                        break;

                    case AggregationType.Max:
                        val.AddResult(new AggregationOperationResult(at,
                                                                     dataElement.Value.AsBsonArray.Select(
                                                                         v => v.AsDouble).Max()));
                        break;

                    case AggregationType.Avg:
                        val.AddResult(new AggregationOperationResult(at,
                                                                     dataElement.Value.AsBsonArray.Select(
                                                                         v => v.AsDouble).Average()));
                        break;
                    }
                }
                else
                {
                    if (dataElement.Name == "Raw" && dataElement.Value.AsBsonArray.Count != 0)
                    {
                        val.AddRawValues(dataElement.Value.AsBsonArray.Select(v => v.AsDouble).ToList());
                    }
                }
            }
            return(val);
        }
 private static AggregatedValue ParseAggregatedValue(StoredCounter entry)
 {
     DateTime date = entry.Date;
     Dictionary<string, string> properties = entry.Props;
     AggregationKey ak = new AggregationKey(date, properties);
     AggregatedValue val = new AggregatedValue(ak);
     if (entry.Data.Sum != null) val.AddResult(new AggregationOperationResult(AggregationType.Sum, entry.Data.Sum.Value));
     if (entry.Data.Count != null) val.AddResult(new AggregationOperationResult(AggregationType.Count, entry.Data.Count.Value));
     if (entry.Data.Min != null) val.AddResult(new AggregationOperationResult(AggregationType.Min, entry.Data.Min.Min()));
     if (entry.Data.Max != null) val.AddResult(new AggregationOperationResult(AggregationType.Max, entry.Data.Max.Max()));
     if (entry.Data.Avg != null) val.AddResult(new AggregationOperationResult(AggregationType.Avg, entry.Data.Avg.Average()));
     if (entry.Data.RawValues != null) val.AddRawValues(entry.Data.RawValues);
     return val;
 }
 public AggregatedValue(AggregationKey aggregationKey)
 {
     Date = aggregationKey.Date;
     Props = aggregationKey.Props;
     
 }
        public void Push(LogEvent logEvent)
        {
            var props = new Dictionary<string, string>();
            props["cCat"] = logEvent.Category;
            props["cName"] = logEvent.Counter;
            props["src"] = logEvent.Source;
            if (!String.IsNullOrEmpty(logEvent.Instance)) props["instance"] = logEvent.Instance;
            if (!String.IsNullOrEmpty(logEvent.ExtendedData)) props["ext_data"] = logEvent.ExtendedData;
            var aggregationKey = new AggregationKey(logEvent.DateTime.RoundTo(_aggregationPeriod), props);
            /*_events.AddOrUpdate(aggregationKey,
                                new ConcurrentBag<double>() {SlowPokeParse(logEvent)},
                                (key, bag) =>
                                    {
                                        bag.Add(SlowPokeParse(logEvent));
                                        return bag;
                                    });
            */
            var value = Double.Parse(logEvent.Value);
            //_rwLock.EnterReadLock();
            try
            {
                _bag.Add(new Tuple<AggregationKey, double>(aggregationKey, value));
                //_events.GetOrAdd(aggregationKey, new ConcurrentBag<double>()).Add(value);
            }
            finally
            {
              //  _rwLock.ExitReadLock();
            }

        }
        private AggregatedValue Calculate(AggregationKey key, List<double> valuesList, DateTime d)
        {
            try
            {
                if (key.Date > d)
                {
                    foreach (var value in valuesList)
                    {
                        _bag.Add(new Tuple<AggregationKey, double>(key,value));
                        //_events.GetOrAdd(kvp.Key, new ConcurrentBag<double>()).Add(value);
                    }
                    return null;
                }

                var av = new AggregatedValue(key);
                
                foreach (var aggregationOperation in _aggregationOperations)
                {
                    try
                    {
                        av.AddResult(aggregationOperation.Do(valuesList));
                    }
                    catch (InvalidOperationException)
                    {
                    }

                }
                //TODO dirty hack
                if (
                    _aggregationOperations.Any(
                        op =>
                        op.GetType() == typeof(PercentileAggregationOperation) ||
                        op.GetType() == typeof(DistributionGroupAggregationOperation)))
                    av.AddRawValues(valuesList);
                return av;
                //_onAggregateCompleteAction(av);

                /*ThreadPool.QueueUserWorkItem(state =>
                                                 {
                                                     Thread.Sleep(500);
                                                     int countAfter = kvp.Value.Count;
                                                     int i;
                                                     if (countBefore != countAfter)
                                                         i = 1;
                                                 });
*/

            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
            return null;

        }
 private static AggregatedValue ParseAggregatedValue(BsonDocument entry)
 {
     DateTime date = entry["date"].AsDateTime;
     Dictionary<string, string> properties = !entry.Contains("props")? new Dictionary<string, string>() : 
         entry["props"].AsBsonDocument.Where(kvp => kvp.Name != "pCnt").ToDictionary(kvp => kvp.Name,
                                                                                     kvp => kvp.Value.AsString);
     AggregationKey ak = new AggregationKey(date, properties);
     AggregatedValue val = new AggregatedValue(ak);
     foreach (var dataElement in entry["data"].AsBsonDocument)
     {
         AggregationType at;
         if (AggregationTypeParser.TryParse(dataElement.Name, out at))
         {
             switch (at)
             {
                 case AggregationType.Sum:
                 case AggregationType.Count:
                     val.AddResult(new AggregationOperationResult(at, dataElement.Value.AsDouble));
                     break;
                 case AggregationType.Min:
                     val.AddResult(new AggregationOperationResult(at,
                                                                  dataElement.Value.AsBsonArray.Select(
                                                                      v => v.AsDouble).Min()));
                     break;
                 case AggregationType.Max:
                     val.AddResult(new AggregationOperationResult(at,
                                                                  dataElement.Value.AsBsonArray.Select(
                                                                      v => v.AsDouble).Max()));
                     break;
                 case AggregationType.Avg:
                     val.AddResult(new AggregationOperationResult(at,
                                                                  dataElement.Value.AsBsonArray.Select(
                                                                      v => v.AsDouble).Average()));
                     break;
             }
         }
         else
         {
             if (dataElement.Name == "Raw" && dataElement.Value.AsBsonArray.Count != 0)
                 val.AddRawValues(dataElement.Value.AsBsonArray.Select(v => v.AsDouble).ToList());
         }
     }
     return val;
 }