Beispiel #1
0
        public MetricProcessor(string name, JsonMetric jsonMetric)
            : base(name)
        {
            Name   = name;
            Metric = jsonMetric;

            CurrentState = LoadState();

            _updateCallbacks = new ConcurrentDictionary <string, Action <MetricProcessor> >();
            _errorCallbacks  = new ConcurrentDictionary <string, Action <string> >();

            Task.Run(() => { EventLoop(); });
        }
Beispiel #2
0
        static MetricState Deserialize(byte[] stream)
        {
            if (stream == null)
            {
                return(null);
            }

            BinaryFormatter binaryFormatter = new BinaryFormatter();

            using (MemoryStream memoryStream = new MemoryStream(stream)) {
                MetricState result = (MetricState)binaryFormatter.Deserialize(memoryStream);
                return(result);
            }
        }
Beispiel #3
0
        static byte[] Serialize(MetricState o)
        {
            if (o == null)
            {
                return(null);
            }

            BinaryFormatter binaryFormatter = new BinaryFormatter();

            using (MemoryStream memoryStream = new MemoryStream()) {
                binaryFormatter.Serialize(memoryStream, o);
                byte[] objectDataAsStream = memoryStream.ToArray();
                return(objectDataAsStream);
            }
        }
Beispiel #4
0
        public MetricState(string name, JsonMetric jsonMetric)
        {
            Metric = jsonMetric;
            if (string.IsNullOrEmpty(Metric.Group))
            {
                Dimensions = new string[] { };
            }
            else
            {
                Dimensions = Metric.Group.Split(',');
            }
            Aggregates = new Dictionary <string, Aggregate>();

            Total = AggregateFactory.Default.Get(Metric);
            AsOf  = MetricState.PeriodTime(Metric.Period);
        }
Beispiel #5
0
        public MetricState LoadState()
        {
            while (RedisClient.Current.Database == null)
            {
                Thread.Sleep(10);
            }

            var state = GetState(MetricState.PeriodTime(Metric.Period));

            if (state != null)
            {
                return(state);
            }
            else
            {
                return(new MetricState(Name, Metric));
            }
        }
Beispiel #6
0
 public string StateKey()
 {
     return(string.Format("{0}|{1}", MetricSortedListKey, MetricState.PeriodTime(Metric.Period)));
 }