public static AndetDataCollection GetAppInsightsPrivateBytesTelemetry(ILogger log)
        {
            var result = new AndetDataCollection
            {
                Granularity = "minutely"
            };

            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Add("x-api-key", AzureAiApiKey);
            HttpResponseMessage response = client.GetAsync(GenerateAppInsightsPrivateBytesQuery()).Result;

            if (!response.IsSuccessStatusCode)
            {
                log.LogError($"Error when getting telemetry data from App Insights: {response.Content.ReadAsStringAsync().Result}");
                return(result);
            }

            var intermediateResult = JsonConvert.DeserializeObject <TablesResult>(response.Content.ReadAsStringAsync().Result);
            var rows = intermediateResult.Tables.First();

            result.Series = rows.Rows.Select(i => new PerfCounterRow()
            {
                Timestamp = DateTime.Parse(i[0]), Value = (long)double.Parse(i[1])
            }).OrderBy(i => i.Timestamp).ToList();

            return(result);
        }
        private static IEnumerable <PerfCounterRow> GetAnomalyPerfCountersRows(AndetDataCollection dataCollection, ILogger log)
        {
            var result = new List <PerfCounterRow>();

            var json = JsonConvert.SerializeObject(dataCollection, Formatting.None, new JsonSerializerSettings
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc,
                DateFormatString     = "s"
            });

            log.LogInformation($"ApplicationInsights. JSON prepared for Anomaly Detection: \n\r {json}");

            //send perf counters to Anomaly Detection
            var anomalyDetectionResult = DetectAnomaliesBatch(json);

            //var anomalyDetectionResult = DetectAnomaliesLatest(json);
            if (anomalyDetectionResult.Contains("ErrorCode:"))
            {
                log.LogError(anomalyDetectionResult);
                return(result);
            }

            var intermediateResult = JsonConvert.DeserializeObject <AndetResponseData>(anomalyDetectionResult);

            // selecting indexes of all anomaly rows
            int[] anomalyRowsIndexes = intermediateResult.IsAnomaly.Select((value, index) => new { value, index })
                                       .Where(t => t.value)
                                       .Select(t => t.index)
                                       .ToArray();

            result = anomalyRowsIndexes.Select(i => new PerfCounterRow()
            {
                Timestamp = dataCollection.Series[i].Timestamp, Value = dataCollection.Series[i].Value
            }).ToList();

            return(result);
        }