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(); }); }
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); } }
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); } }
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); }
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)); } }
public string StateKey() { return(string.Format("{0}|{1}", MetricSortedListKey, MetricState.PeriodTime(Metric.Period))); }