Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
 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));
 }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
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(); });
        }
Ejemplo n.º 7
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(); });
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 public AggregateSum(JsonMetric metric, string name)
     : base(metric, name)
 {
 }
Ejemplo n.º 10
0
 public AggregateAverage(JsonMetric metric, string name)
     : base(metric, name)
 {
 }
Ejemplo n.º 11
0
 public AggregateAverage(JsonMetric metric, string name)
     : base(metric, name)
 {
 }
Ejemplo n.º 12
0
 public AggregateCount(JsonMetric metric, string name)
     : base(metric, name)
 {
 }