예제 #1
0
        public static void QueueMetric(Metric metric)
        {
            _metricsEverUsed = true;

            try
            {
                //set a sanity cap
                if (MetricQueue.Count < 100000)
                {
                    MetricQueue.Enqueue(metric);

                    // RT-561: Incremented Metrics Broken
                    if (metric.IsIncrement)
                    {
                        var nameKey = metric.CalcNameKey();

                        if (LastAggregates.ContainsKey(metric.CalcNameKey()))
                        {
                            LastAggregates[nameKey].OccurredUtc = metric.Occurred;
                            LastAggregates[nameKey].Value      += metric.Value;
                        }
                        else
                        {
                            var agg = new MetricAggregate(metric);
                            agg.OccurredUtc = metric.Occurred;
                            agg.Value       = metric.Value;

                            LastAggregates.TryAdd(nameKey, agg);
                        }
                    }
                }
                else
                {
                    StackifyAPILogger.Log("No longer queuing new metrics because more than 100000 are queued", true);
                }
            }
            catch (Exception ex)
            {
                StackifyAPILogger.Log(ex.ToString());
            }
        }