Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FabricResourceUsageData{T}"/> class.
        /// </summary>
        /// <param name="property">Metric string.</param>
        /// <param name="id">Instance id.</param>
        /// <param name="dataCapacity">Max element capacity of instance's data container.</param>
        /// <param name="useCircularBuffer">Whether to hold data in a Circular Buffer or not.</param>
        public FabricResourceUsageData(
            string property,
            string id,
            int dataCapacity       = 30,
            bool useCircularBuffer = false)
        {
            if (string.IsNullOrEmpty(property))
            {
                throw new ArgumentException($"Must provide a non-empty {property}.");
            }

            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException($"Must provide a non-empty {id}.");
            }

            // This can be either a straight List<T> or a CircularBufferCollection<T>.
            if (useCircularBuffer)
            {
                if (dataCapacity <= 0)
                {
                    var healthReporter = new ObserverHealthReporter(new Logger("FabricResourceUsageData"));
                    var healthReport   = new HealthReport
                    {
                        AppName       = new Uri("fabric:/FabricObserver"),
                        HealthMessage = $"Incorrect CircularBuffer data capacity specified for FRUD instance: {dataCapacity}. " +
                                        "Using default value 30. Please use a number greater than 0 for ResourceUsageDataCapacity setting in Settings.xml.",
                        State                  = HealthState.Ok,
                        ReportType             = HealthReportType.Application,
                        NodeName               = FabricRuntime.GetNodeContext()?.NodeName,
                        HealthReportTimeToLive = TimeSpan.MaxValue,
                        Observer               = ObserverConstants.FabricObserverName,
                    };

                    healthReporter.ReportHealthToServiceFabric(healthReport);
                }

                Data = new CircularBufferCollection <T>(dataCapacity > 0 ? dataCapacity : 30);
            }
            else
            {
                Data = new List <T>();
            }

            Property = property;
            Id       = id;
            Units    = string.Empty;

            if (property.Contains("MB"))
            {
                Units = "MB";
            }

            if (property.ToLower().Contains("%") ||
                property.ToLower().Contains("cpu") ||
                property.ToLower().Contains("percent"))
            {
                Units = "%";
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FabricResourceUsageData{T}"/> class.
        /// </summary>
        /// <param name="property">Metric string.</param>
        /// <param name="id">Instance id.</param>
        /// <param name="dataCapacity">Max element capacity of instance's data container.</param>
        /// <param name="useCircularBuffer">Whether to hold data in a Circular Buffer or not.</param>
        public FabricResourceUsageData(
            string property,
            string id,
            int dataCapacity       = 30,
            bool useCircularBuffer = false)
        {
            if (string.IsNullOrEmpty(property))
            {
                throw new ArgumentException($"Must provide a non-empty {property}.");
            }

            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException($"Must provide a non-empty {id}.");
            }

            // This can be either a straight List<T> or a CircularBufferCollection<T>.
            if (useCircularBuffer)
            {
                Data = new CircularBufferCollection <T>(dataCapacity > 0 ? dataCapacity : 30);
            }
            else
            {
                Data = new List <T>();
            }

            Property = property;
            Id       = id;
            Units    = string.Empty;

            if (property.Contains("MB"))
            {
                Units = "MB";
            }

            if (property.ToLower().Contains("%") ||
                property.ToLower().Contains("cpu") ||
                property.ToLower().Contains("percent"))
            {
                Units = "%";
            }
        }