/// <summary> /// Bind to an existing metric given by "name" /// </summary> /// <param name="pipeline"></param> /// <param name="name"></param> /// <param name="connection"></param> /// <param name="connectionId"></param> public MetricConnection(EventPipeline pipeline, IConnection connection, string connectionId, string jsonMetric, string clientId) { _connection = connection; _connectionId = connectionId; _clientId = clientId; _jsonMetric = JsonConvert.DeserializeObject<JsonMetric>(jsonMetric); // Try to find the metric, and add a watcher var metric = pipeline.GetProcessor(_jsonMetric.Name) as MetricProcessor; if (metric == null) { // Its new so we need to create a new one... var filePath = Path.Combine(PathManager.BasePath, "user", "metric", _jsonMetric.Name + ".json"); //if (!File.Exists(filePath)) { var formattedJson = JsonConvert.SerializeObject(_jsonMetric, Formatting.Indented); File.WriteAllText(filePath, formattedJson); //} metric = new MetricProcessor(_jsonMetric.Name, _jsonMetric); pipeline.AddProcessor(metric); } metric.Updated(_connectionId, WriteValueUpdate); metric.Error(_connectionId, WriteErrorUpdate); SendUpdates(metric); }
public Aggregate(JsonMetric metric, string name) { Metric = metric; Name = name; if (!metric.Aggregate.StartsWith(Name)) { throw new Exception(string.Format("Aggregate does not match name, name: {0}, Aggregate: {1}", Name, metric.Aggregate)); } Expression = metric.Aggregate.Substring(Name.Length + 1, metric.Aggregate.Length - (Name.Length + 2)); }
public Aggregate Get(JsonMetric metric) { foreach (var k in _aggregates.Keys) { if (metric.Aggregate.StartsWith(k)) { return _aggregates[k](metric); } } throw new Exception(string.Format("Unable to fidn aggregate for expression: {0}", metric.Aggregate)); }
public Aggregate Get(JsonMetric metric) { foreach (var k in _aggregates.Keys) { if (metric.Aggregate.StartsWith(k)) { return(_aggregates[k](metric)); } } throw new Exception(string.Format("Unable to fidn aggregate for expression: {0}", metric.Aggregate)); }
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(); }); }
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(); }); }
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 AggregateSum(JsonMetric metric, string name) : base(metric, name) { }
public AggregateAverage(JsonMetric metric, string name) : base(metric, name) { }
public AggregateCount(JsonMetric metric, string name) : base(metric, name) { }