Example #1
0
        public override IList <Object> GetSummary()
        {
            List <Object> objects = new List <Object>();
            ISession      session = null;

            try
            {
                string        configPath = string.Format("{0}SummaryConfig.{1}.xml", _nhSettings["AppDataPath"], _nhSettings["Scope"]);
                SummaryConfig config     = utility.Utility.Read <SummaryConfig>(configPath);

                session = NHibernateSessionManager.Instance.GetSession(
                    _nhSettings["AppDataPath"], _nhSettings["Scope"]);

                if (session != null)
                {
                    foreach (SummaryItem summaryItem in config)
                    {
                        List <string>  headers   = summaryItem.Headers;
                        IQuery         query     = session.CreateSQLQuery(summaryItem.Query);
                        IList <object> resultSet = query.List <object>();

                        foreach (object result in resultSet)
                        {
                            IDictionary <String, String> nameValuePairs = new Dictionary <String, String>();

                            if (result.GetType().IsArray)
                            {
                                object[] values = (object[])result;

                                for (int i = 0; i < values.Length; i++)
                                {
                                    nameValuePairs[headers[i]] = values[i].ToString();
                                }
                            }
                            else
                            {
                                nameValuePairs[headers[0]] = result.ToString();
                            }

                            objects.Add(nameValuePairs);
                        }
                    }
                }
            }
            finally
            {
                if (session != null)
                {
                    session.Close();
                }
            }

            return(objects);
        }
        public ThrottlingMetrics(
            [NotNull] IThrottlingProvider provider,
            [NotNull] IMetricContext metricContext,
            [NotNull] ThrottlingMetricsOptions options)
        {
            eventSubscription  = provider.Subscribe(this as IObserver <IThrottlingEvent>);
            resultSubscription = provider.Subscribe(this as IObserver <IThrottlingResult>);

            var integerGaugeConfig = new IntegerGaugeConfig {
                InitialValue = 0, ResetOnScrape = true
            };
            var propertiesGaugeConfig = new IntegerGaugeConfig {
                InitialValue = 0, ResetOnScrape = true, SendZeroValues = false
            };
            var floatingGaugeConfig = new FloatingGaugeConfig {
                InitialValue = 0, ResetOnScrape = true
            };
            var summaryConfig = new SummaryConfig();
            var counterConfig = new CounterConfig();

            if (options.ScrapePeriod != null)
            {
                integerGaugeConfig.ScrapePeriod     = options.ScrapePeriod;
                floatingGaugeConfig.ScrapePeriod    = options.ScrapePeriod;
                summaryConfig.ScrapePeriod          = options.ScrapePeriod;
                counterConfig.ScrapePeriod          = options.ScrapePeriod;
                counterConfig.AggregationParameters = new Dictionary <string, string>().SetAggregationPeriod(options.ScrapePeriod.Value);
            }

            waitTimeSummary  = metricContext.CreateSummary("queueWaitTime", summaryConfig);
            rejectionCounter = metricContext.CreateCounter("rejectionsCount", "status", counterConfig);

            maxCapacityLimit       = metricContext.CreateIntegerGauge("maxCapacityLimit", integerGaugeConfig);
            maxCapacityConsumed    = metricContext.CreateIntegerGauge("maxCapacityConsumed", integerGaugeConfig);
            maxCapacityUtilization = metricContext.CreateFloatingGauge("maxCapacityUtilization", floatingGaugeConfig);

            maxQueueLimit       = metricContext.CreateIntegerGauge("maxQueueLimit", integerGaugeConfig);
            maxQueueSize        = metricContext.CreateIntegerGauge("maxQueueSize", integerGaugeConfig);
            maxQueueUtilization = metricContext.CreateFloatingGauge("maxQueueUtilization", floatingGaugeConfig);

            maxConsumptionPerProperty = options.PropertiesWithConsumptionTracking
                                        .ToDictionary(
                property => property,
                property => metricContext
                .WithTag("scope", "property")
                .WithTag("propertyName", property)
                .CreateIntegerGauge("maxConsumption", "propertyValue", propertiesGaugeConfig));
            propertyConsumptionTrackingThreshold = options.PropertyConsumptionTrackingThreshold;
        }
Example #3
0
        public void Write(IEnumerable<ITimeSeries> timeSeriesGroup, string summaryFile, SummaryConfig excelConfig)
        {
            if (timeSeriesGroup == null) throw new ArgumentNullException(nameof(timeSeriesGroup));
            if (timeSeriesGroup.Any(x => x == null)) throw new ArgumentException("IEnumerable contains null values.", nameof(timeSeriesGroup));

            if (excelConfig.Sheet == null) throw new ArgumentNullException(nameof(excelConfig.Sheet));
            if (excelConfig.Row <= 0) throw new ArgumentOutOfRangeException(nameof(excelConfig.Row), "Value must be higher than 0.");

            if (!(timeSeriesGroup is TimeSeriesGroup timeSeriesGroupInstance))
            {
                timeSeriesGroupInstance = new TimeSeriesGroup();
                timeSeriesGroupInstance.AddRange(timeSeriesGroup);
            }

            using (var excelPack = new ExcelPackage(new FileInfo(summaryFile)))
            {
                var worksheet = excelPack.Workbook.Worksheets[excelConfig.Sheet];
                if (worksheet == null)
                {
                    throw new InvalidDataException($"Table '{excelConfig.Sheet}' not found.");
                }

                var edrWorksheet = new EppWorksheet(worksheet);
                FillDataIntoTable(edrWorksheet, timeSeriesGroupInstance, excelConfig.Row);

                excelPack.Save();
            }
        }