Beispiel #1
0
        private List <MetricValue> readMetricValuesIntoEntity(MOBILEEntityBase entity, JobTarget jobTarget, string metricName, AppDRESTMetric appDRESTMetric, int timerangeDuration)
        {
            List <MetricValue> metricValues = new List <MetricValue>(appDRESTMetric.metricValues.Count);

            foreach (AppDRESTMetricValue appDRESTMetricValue in appDRESTMetric.metricValues)
            {
                // Populate metrics into the list for output into CSV
                MetricValue metricValue = new MetricValue();

                metricValue.Controller      = jobTarget.Controller;
                metricValue.ApplicationID   = jobTarget.ApplicationID;
                metricValue.ApplicationName = jobTarget.Application;

                if (entity != null)
                {
                    if (entity is MOBILEApplication)
                    {
                        MOBILEApplication mobileApplication = (MOBILEApplication)entity;

                        metricValue.EntityID   = mobileApplication.ApplicationID;
                        metricValue.EntityName = mobileApplication.ApplicationName;
                        metricValue.EntityType = MOBILEApplication.ENTITY_TYPE;
                    }
                    else if (entity is MOBILENetworkRequest)
                    {
                        MOBILENetworkRequest networkRequest = (MOBILENetworkRequest)entity;

                        metricValue.EntityID   = networkRequest.RequestID;
                        metricValue.EntityName = networkRequest.RequestName;
                        metricValue.EntityType = MOBILENetworkRequest.ENTITY_TYPE;
                    }
                }

                metricValue.EventTimeStampUtc = UnixTimeHelper.ConvertFromUnixTimestamp(appDRESTMetricValue.startTimeInMillis);
                metricValue.EventTimeStamp    = metricValue.EventTimeStampUtc.ToLocalTime();
                metricValue.EventTime         = metricValue.EventTimeStamp;

                metricValue.MetricName = metricName;
                metricValue.MetricID   = appDRESTMetric.metricId;
                switch (appDRESTMetric.frequency)
                {
                case "SIXTY_MIN":
                {
                    metricValue.MetricResolution = 60;
                    break;
                }

                case "TEN_MIN":
                {
                    metricValue.MetricResolution = 10;
                    break;
                }

                case "ONE_MIN":
                {
                    metricValue.MetricResolution = 1;
                    break;
                }

                default:
                {
                    metricValue.MetricResolution = 1;
                    break;
                }
                }

                metricValue.Count       = appDRESTMetricValue.count;
                metricValue.Min         = appDRESTMetricValue.min;
                metricValue.Max         = appDRESTMetricValue.max;
                metricValue.Occurrences = appDRESTMetricValue.occurrences;
                metricValue.Sum         = appDRESTMetricValue.sum;
                metricValue.Value       = appDRESTMetricValue.value;

                metricValues.Add(metricValue);
            }

            return(metricValues);
        }
Beispiel #2
0
        private List <MetricValue> readMetricsIntoEntities(
            List <AppDRESTMetric> metricData,
            Dictionary <string, MOBILEEntityBase> entitiesDictionaryByName,
            JobTarget jobTarget,
            JobTimeRange jobTimeRange)
        {
            MOBILEEntityBase entity = null;

            int timerangeDuration = (int)(jobTimeRange.To - jobTimeRange.From).Duration().TotalMinutes;

            List <MetricValue> metricValues = new List <MetricValue>(metricData.Count * timerangeDuration);

            foreach (AppDRESTMetric appDRESTMetric in metricData)
            {
                if (appDRESTMetric.metricValues.Count == 0)
                {
                    // No metrics in this chunk
                    continue;
                }

                #region Get metric path components and metric name

                // Analyze metric path returned by the call to controller
                string[] metricPathComponents = appDRESTMetric.metricPath.Split('|');

                if (metricPathComponents.Length == 0)
                {
                    // Metric name was no good
                    logger.Warn("Metric path='{0}' could not be parsed into individual components", appDRESTMetric.metricPath);
                    continue;
                }

                string[] metricNameComponents = appDRESTMetric.metricName.Split('|');

                if (metricNameComponents.Length == 0)
                {
                    // Metric name was no good
                    logger.Warn("Metric name='{0}' could not be parsed into individual components", appDRESTMetric.metricName);
                    continue;
                }

                // Name of the metric is always the last one in the metric path
                string metricName = metricPathComponents[metricPathComponents.Length - 1];

                #endregion

                #region Determine metric entity type, scope and name from metric path

                if (metricPathComponents.Length == 3)
                {
                    #region Application level

                    // MetricPath = Mobile|iOS|App Crashes
                    // MetricName = MOBILE|Global|iOS|App Crashes

                    entity = entitiesDictionaryByName.FirstOrDefault().Value;

                    #endregion
                }
                else if (String.Compare(metricPathComponents[4], "Requests", true) == 0)
                {
                    #region Network Request

                    // MetricPath = Mobile|iOS|Apps|AD-DevOps-iOS|Requests|devops-payments-web:8080/devops-payments-web/checkout|Application Server Time (ms)
                    // MetricName = BTM|Application Diagnostic Data|MOBILE_REQUEST:17808|Application Server Time (ms)

                    entitiesDictionaryByName.TryGetValue(metricPathComponents[5], out entity);

                    #endregion
                }
                else
                {
                    // Unsupported type of metric
                    logger.Warn("Metric path='{0}' is not of supported type of metric for processing", appDRESTMetric.metricPath);
                }

                #endregion

                List <MetricValue> metricValuesConverted = readMetricValuesIntoEntity(entity, jobTarget, metricName, appDRESTMetric, timerangeDuration);
                metricValues.AddRange(metricValuesConverted);
            }

            return(metricValues);
        }