Beispiel #1
0
        private static string BuildQueryString(CounterConfig counter)
        {
            var providerName = counter.Provider;
            var categoryName = counter.Category;
            var instance     = counter.Instance;
            var counterName  = counter.Counter;

            if (string.IsNullOrWhiteSpace(providerName) || string.IsNullOrWhiteSpace(categoryName) ||
                string.IsNullOrWhiteSpace(counterName))
            {
                Log.ErrorFormat("Invalid Counter. Provider={0}, Category={1}, Name={2}", providerName, categoryName,
                                counterName);
                return(null);
            }

            var whereClause = string.Empty;

            if (!string.IsNullOrWhiteSpace(counter.Instance))
            {
                whereClause = string.Format(" Where Name Like '{0}'", instance);
            }

            var queryString = string.Format("Select * from Win32_PerfFormattedData_{0}_{1}{2}",
                                            providerName, categoryName, whereClause);

            return(queryString);
        }
Beispiel #2
0
        private List <DataPoint> GetDataPoints(CounterConfig counter)
        {
            if (counter == null)
            {
                return(null);
            }

            var queryString = BuildQueryString(counter);

            if (queryString == null)
            {
                return(null);
            }

            var search     = new ManagementObjectSearcher(Scope, new ObjectQuery(queryString));
            var dataPoints = new List <DataPoint>();

            try
            {
                var queryResults = search.Get();
                var results      = queryResults.Cast <ManagementObject>();

                try
                {
                    // ReSharper disable once PossibleMultipleEnumeration
                    Log.DebugFormat("Retrieved {0} results from '{1}'", results.Count(), queryString);
                }
                catch (ManagementException ex)
                {
                    Log.Warn(string.Format("Unable to read results of '{0}'", queryString), ex);
                    return(null);
                }

                // ReSharper disable once PossibleMultipleEnumeration
                foreach (var result in results)
                {
                    try
                    {
                        dataPoints.Add(AssembleDataPoint(counter, result));
                    }
                    catch (Exception ex)
                    {
                        Log.Error(string.Format("Exception while retrieving metric results. Query: {0}", queryString),
                                  ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("Exception while polling metrics. Query: {0}", queryString), ex);
            }

            return(dataPoints);
        }
        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;
        }
        public MetricsProvider(IMetricContext metricContext, string environment, string clientName)
        {
            var sendZeroValuesCounterConfig = new CounterConfig
            {
                ScrapePeriod   = TimeSpan.FromMinutes(1),
                SendZeroValues = false
            };

            var metricsTags = new MetricTags(
                new MetricTag("project", SingularConstants.ProjectName),
                new MetricTag("environment", environment),
                new MetricTag("application", SingularConstants.ServiceName),
                new MetricTag("cluster", SingularConstants.DefaultCluster),
                new MetricTag("version", Version),
                new MetricTag("clientName", clientName)
                );

            var metricsContext = metricContext.WithTags(metricsTags);

            requestReasonsCounter = metricsContext.CreateCounter("client", "reason", sendZeroValuesCounterConfig);
        }
Beispiel #5
0
        private DataPoint AssembleDataPoint(CounterConfig counter, ManagementObject result)
        {
            var    instance            = counter.Instance;
            var    counterName         = counter.Counter;
            string applicationPoolName = string.Empty;
            var    friendlyName        = counter.Name;
            var    resultName          = GetPropertyString(result, "Name");

            var value = Convert.ToSingle(result[counterName]);

            var processId = GetPropertyInt(result, "IDProcess");

            if (processId.HasValue)
            {
                applicationPoolName = GetAppPoolByProcessId(processId);
            }

            // Prefer in order of ApplicationName, ResultName, Instance or just use empty string.
            var instanceName =
                !string.IsNullOrWhiteSpace(applicationPoolName)
                    ? applicationPoolName
                    : !string.IsNullOrWhiteSpace(resultName)
                        ? resultName
                        : !string.IsNullOrWhiteSpace(instance)
                            ? instance
                            : string.Empty;

            Log.DebugFormat("{0}/{1} ({2}): {3}", friendlyName, instanceName,
                            applicationPoolName, value);

            if (!string.IsNullOrWhiteSpace(instanceName))
            {
                friendlyName = string.Concat(friendlyName, " - ", instanceName);
            }
            return(new DataPoint(friendlyName, value, DateTime.UtcNow, _instanceId));
        }
Beispiel #6
0
 public ConfigDialog(CounterConfig config)
 {
     _config = config;
     InitializeComponent();
 }