示例#1
0
        public async Task <IDictionary <string, double> > GetDimensionMetricsCountCoreAsync(string metricsName, TimeSpan backTime, string dimension)
        {
            IDictionary <string, double> result = new Dictionary <string, double>();
            var connectionInfo   = new ConnectionInfo(_certificate, _mdmEnvironment);
            var metricReader     = new MetricReader(connectionInfo);
            var metricId         = GenMetricId(metricsName);
            var dimensionFilters = new List <DimensionFilter>
            {
                DimensionFilter.CreateIncludeFilter(dimension)
            };

            try
            {
                var now     = DateTime.UtcNow;
                var results = await metricReader.GetTimeSeriesAsync(
                    metricId,
                    dimensionFilters,
                    now - backTime,
                    now,
                    new[] { SamplingType.Count },
                    new SelectionClauseV3(new PropertyDefinition(PropertyAggregationType.Sum, SamplingType.Count), 100_000, OrderBy.Descending),
                    outputDimensionNames : new List <string> {
                    dimension
                }
                    );

                return(results.Results.ToDictionary(r => r.DimensionList.First().Value, r => r.EvaluatedResult));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to get metrics data from Geneva", ex);
                return(null);
            }
        }
示例#2
0
        public static string QueryMetrics(string podName, PlatformType platformType, SystemLoadType systemLoadType, DateTime startTime, DateTime endTime, string filePath)
        {
            if (platformType == PlatformType.Dogfood)
            {
                var testCertificateThumbprint = "C35CBFF9FA6C51E51E1DE97B6D1E246F27661301";
                var httpsUrl       = "https://shoebox2.metrics.nsatc.net/public/monitoringAccount/SignalRShoeboxTest/homeStamp";
                var connectionInfo = new ConnectionInfo(new Uri(httpsUrl), testCertificateThumbprint, StoreLocation.LocalMachine);
                var id             = new MetricIdentifier("SignalRShoeboxTest", "systemLoad", systemLoadType == SystemLoadType.CPU ? "PodCpuUsage" : "PodMemory");
                var reader         = new MetricReader(connectionInfo);

                // The short link for this series is http://jarvis-int.dc.ad.msft.net/D10A9E2E.
                var definition = new TimeSeriesDefinition <MetricIdentifier>(
                    id,
                    new Dictionary <string, string> {
                    { "podName", podName }
                });

                TimeSeries <MetricIdentifier, double?> result =
                    reader.GetTimeSeriesAsync(startTime, endTime, SamplingType.Max, definition).Result;
                var strOutput = JsonConvert.SerializeObject(result);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath, false))
                {
                    file.Write(strOutput);
                }
                return(strOutput);
            }
            return(null);
        }
示例#3
0
        /// <summary>
        /// Gets the known dimension combinations that match the query criteria.  In this example, we are checking for available memory
        /// on all our roles and datacenters.
        /// </summary>
        public static void GetFilteredDimensionValues()
        {
            // Replace 31280E2F2D2220808315C212DF8062A295B28325 with your cert thumbprint,
            // install it to the "Personal\Certificates" folder in the "Local Computer" certificate store,
            // and grant the permission of reading the private key to the service/application using the MDM consumption APIs.
            string testCertificateThumbprint = "31280E2F2D2220808315C212DF8062A295B28325";

            var connectionInfo = new ConnectionInfo(testCertificateThumbprint, StoreLocation.LocalMachine, MdmEnvironment.Int);

            var reader = new MetricReader(connectionInfo);

            var id = new MetricIdentifier("MetricTeamInternalMetrics", "PlatformMetrics", "\\Memory\\Available MBytes");

            var dimensionFilters = new DimensionFilter[] { "__Role", "Datacenter" };

            IEnumerable <IQueryResult> results = reader.GetFilteredDimensionValuesAsync(
                id,
                dimensionFilters,
                DateTime.UtcNow.AddMinutes(-60),
                DateTime.UtcNow,
                SamplingType.Sum,
                Reducer.Average,
                new QueryFilter(Operator.GreaterThan, 5000),
                false,
                new SelectionClause(SelectionType.TopValues, 10, OrderBy.Descending)
                ).Result;

            foreach (var series in results)
            {
                IEnumerable <string> dimensions = series.DimensionList.Select(x => string.Format("[{0}, {1}]", x.Key, x.Value));
                Console.WriteLine("Dimensions: {0}, Evaluated Result: {1:N0}", string.Join(", ", dimensions), series.EvaluatedResult);
            }

            Console.WriteLine("############################ END OF GetFilteredDimensionValues ##############################");
        }
示例#4
0
        /// <summary>
        /// Gets the known dimension combinations that match the query criteria and the associated time series.
        /// In this example, we are checking the sum and count for available memory on all our roles and datacenters.
        /// </summary>
        public static void GetFilteredDimensionValuesV3()
        {
            var connectionInfo = new ConnectionInfo(MdmEnvironment.Int);

            var reader = new MetricReader(connectionInfo);

            var id = new MetricIdentifier("MetricTeamInternalMetrics", "PlatformMetrics", "\\Memory\\Available MBytes");

            var dimensionFilters = new DimensionFilter[] { "__Role", "Datacenter" };

            IQueryResultListV3 results = reader.GetFilteredDimensionValuesAsyncV3(
                id,
                dimensionFilters,
                DateTime.UtcNow.AddMinutes(-10),
                DateTime.UtcNow,
                new[] { SamplingType.Sum, SamplingType.Count },
                new SelectionClauseV3(new PropertyDefinition(PropertyAggregationType.Average, SamplingType.Sum), 10, OrderBy.Descending)).Result;

            foreach (var series in results.Results)
            {
                IEnumerable <string> dimensions = series.DimensionList.Select(x => string.Format("[{0}, {1}]", x.Key, x.Value));
                var sumSeries   = $"[{string.Join(",", series.GetTimeSeriesValues(SamplingType.Sum))}]";
                var countSeries = $"[{string.Join(",", series.GetTimeSeriesValues(SamplingType.Count))}]";
                Console.WriteLine("Dimensions: {0}, \n\tSum: {1}, \n\tCount: {2}.", string.Join(", ", dimensions), sumSeries, countSeries);
            }

            Console.WriteLine("############################ END OF GetFilteredDimensionValues ##############################");
        }
示例#5
0
        /// <summary>
        /// Gets the multiple time series with resolution reduction.
        /// </summary>
        public static void GetMultipleTimeSeriesWithResolutionReduction()
        {
            // Replace 31280E2F2D2220808315C212DF8062A295B28325 with your cert thumbprint,
            // install it to the "Personal\Certificates" folder in the "Local Computer" certificate store,
            // and grant the permission of reading the private key to the service/application using the MDM consumption APIs.
            string testCertificateThumbprint = "31280E2F2D2220808315C212DF8062A295B28325";

            var connectionInfo = new ConnectionInfo(testCertificateThumbprint, StoreLocation.LocalMachine, MdmEnvironment.Int);
            var reader         = new MetricReader(connectionInfo);

            var id1 = new MetricIdentifier("MetricTeamInternalMetrics", "PlatformMetrics", "\\Memory\\Available MBytes");
            var id2 = new MetricIdentifier("MetricTeamInternalMetrics", "PlatformMetrics", "\\Processor(_Total)\\% Processor Time");

            var dimensionCombination = new Dictionary <string, string> {
                { "Datacenter", "westus" }, { "__Role", "metrics.server" }
            };
            var definitions = new List <TimeSeriesDefinition <MetricIdentifier> >();

            definitions.Add(new TimeSeriesDefinition <MetricIdentifier>(id1, dimensionCombination));
            definitions.Add(new TimeSeriesDefinition <MetricIdentifier>(id2, dimensionCombination));

            const int seriesResolutionInMinutes = 5;
            var       endTimeUtc = DateTime.UtcNow;
            var       result     = reader.GetMultipleTimeSeriesAsync(endTimeUtc.AddMinutes(-9), endTimeUtc, SamplingType.Average, seriesResolutionInMinutes, definitions).Result;

            foreach (var series in result)
            {
                foreach (var dataPoint in series.Datapoints)
                {
                    Console.WriteLine(
                        "Metric: {0}, Time: {1}, Value: {2}",
                        series.Definition.Id.MetricName,
                        dataPoint.TimestampUtc,
                        dataPoint.Value);
                }
            }

            result =
                reader.GetMultipleTimeSeriesAsync(
                    endTimeUtc.AddMinutes(-9),
                    endTimeUtc,
                    new[] { SamplingType.Average },
                    definitions,
                    seriesResolutionInMinutes,
                    AggregationType.None).Result;

            foreach (var series in result)
            {
                foreach (var dataPoint in series.Datapoints)
                {
                    Console.WriteLine(
                        "Metric: {0}, Time: {1}, Value: {2}",
                        series.Definition.Id.MetricName,
                        dataPoint.TimestampUtc,
                        dataPoint.Value);
                }
            }

            Console.WriteLine("############################ END OF GetMultipleTimeSeriesWithResolutionReduction ##############################");
        }
示例#6
0
        /// <summary>
        /// Gets the known time series definitions and query.
        /// </summary>
        public static void GetKnownTimeSeriesDefinitionsAndQuery()
        {
            // Replace 31280E2F2D2220808315C212DF8062A295B28325 with your cert thumbprint,
            // install it to the "Personal\Certificates" folder in the "Local Computer" certificate store,
            // and grant the permission of reading the private key to the service/application using the MDM consumption APIs.
            string testCertificateThumbprint = "31280E2F2D2220808315C212DF8062A295B28325";

            var connectionInfo = new ConnectionInfo(testCertificateThumbprint, StoreLocation.LocalMachine, MdmEnvironment.Int);

            var reader = new MetricReader(connectionInfo);

            var id = new MetricIdentifier("MetricTeamInternalMetrics", "PlatformMetrics", "\\Memory\\Available MBytes");

            // Use implicit conversion from string for simple case.
            IReadOnlyList <TimeSeriesDefinition <MetricIdentifier> > knownDimensions =
                reader.GetKnownTimeSeriesDefinitionsAsync(id, "__Role", "Datacenter").Result;

            TimeSeries <MetricIdentifier, double?> result =
                reader.GetTimeSeriesAsync(DateTime.UtcNow.AddMinutes(-10), DateTime.UtcNow, SamplingType.Sum, knownDimensions.First()).Result;

            foreach (var dataPoint in result.Datapoints)
            {
                Console.WriteLine("Time: {0}, Value: {1}", dataPoint.TimestampUtc, dataPoint.Value);
            }

            Console.WriteLine("############################ END OF GetKnownTimeSeriesDefinitionsAndQuery ##############################");
        }
示例#7
0
        public static void GetDogfoodCPUSeries()
        {
            var testCertificateThumbprint = "C35CBFF9FA6C51E51E1DE97B6D1E246F27661301";
            var httpsUrl       = "https://shoebox2.metrics.nsatc.net/public/monitoringAccount/SignalRShoeboxTest/homeStamp";
            var connectionInfo = new ConnectionInfo(new Uri(httpsUrl), testCertificateThumbprint, StoreLocation.LocalMachine);
            var reader         = new MetricReader(connectionInfo);

            // Single metric
            var id = new MetricIdentifier("SignalRShoeboxTest", "systemLoad", "PodCpuUsage");
            //var id = new MetricIdentifier("SignalRShoeboxTest", "ShoeboxInternal", "MessageCountRaw");
            //var id = new MetricIdentifier("SignalRShoeboxTest", "systemLoad", "PodMemory");

            // The short link for this series is http://jarvis-int.dc.ad.msft.net/D10A9E2E.
            var definition = new TimeSeriesDefinition <MetricIdentifier>(
                id,
                new Dictionary <string, string> { //{ "ResourceId", resourceId}
                { "resourceKubeId", "62a558c2-2895-423d-a7b0-05b03a15b65a" }
            });

            TimeSeries <MetricIdentifier, double?> result =
                reader.GetTimeSeriesAsync(DateTime.UtcNow.AddMinutes(-10), DateTime.UtcNow, SamplingType.Max, definition).Result;

            foreach (var dataPoint in result.Datapoints)
            {
                Console.WriteLine("Time: {0}, Value: {1}", dataPoint.TimestampUtc, dataPoint.Value);
            }
            Console.WriteLine(JsonConvert.SerializeObject(result));
            Console.WriteLine("############################ END OF GetDogfoodSeries ##############################");
        }
示例#8
0
            public bool MoveNext()
            {
                if (this.node != null)
                {
                    this.Current = this.node.Value;
                    this.node    = this.node.Next;
                    return(true);
                }

                return(false);
            }
示例#9
0
        /// <summary>
        /// Gets the known time series definitions.
        /// </summary>
        public static void GetKnownTimeSeriesDefinitions()
        {
            // Replace 31280E2F2D2220808315C212DF8062A295B28325 with your cert thumbprint,
            // install it to the "Personal\Certificates" folder in the "Local Computer" certificate store,
            // and grant the permission of reading the private key to the service/application using the MDM consumption APIs.
            string testCertificateThumbprint = "31280E2F2D2220808315C212DF8062A295B28325";

            var connectionInfo = new ConnectionInfo(testCertificateThumbprint, StoreLocation.LocalMachine, TimeSpan.FromSeconds(300), MdmEnvironment.Int);

            var reader = new MetricReader(connectionInfo);

            string monitoringAccount          = "MetricTeamInternalMetrics";
            IReadOnlyList <string> namespaces = reader.GetNamespacesAsync(monitoringAccount).Result;

            string metricNamespace             = "PlatformMetrics";
            IReadOnlyList <string> metricNames = reader.GetMetricNamesAsync(monitoringAccount, metricNamespace).Result;

            string metric = "\\Memory\\Available MBytes";
            var    id     = new MetricIdentifier(monitoringAccount, metricNamespace, metric);

            var dimensions = reader.GetDimensionNamesAsync(id).Result;

            Console.WriteLine("Dimensions are: {0}", string.Join(", ", dimensions));

            var preaggregates = reader.GetPreAggregateConfigurationsAsync(id).Result;

            foreach (var preAggregateConfiguration in preaggregates)
            {
                Console.WriteLine("Pre-aggregate: {0}", JsonConvert.SerializeObject(preAggregateConfiguration));
            }

            var knownTimeSeriesDefinitions =
                reader.GetKnownTimeSeriesDefinitionsAsync(id, "__Role", DimensionFilter.CreateExcludeFilter("Datacenter", "eastus2")).Result;

            var roleIndex = knownTimeSeriesDefinitions.GetIndexInDimensionCombination("__Role");

            Console.WriteLine("The index of the '__Role' dimension is {0}.", roleIndex);

            foreach (var value in knownTimeSeriesDefinitions)
            {
                Console.WriteLine("Known time series definition: {0}", JsonConvert.SerializeObject(value.DimensionCombination));
            }

            Console.WriteLine("############################ END OF GetKnownTimeSeriesDefinitions ##############################");
        }
示例#10
0
        /// <summary>
        /// Gets the single time series.
        /// </summary>
        /// <param name="useUserAuth">if set to <c>true</c>, use user authentication; otherwise use certificate authentication.</param>
        public static void GetSingleTimeSeries(bool useUserAuth)
        {
            ConnectionInfo connectionInfo;

            if (useUserAuth)
            {
                connectionInfo = new ConnectionInfo(MdmEnvironment.Int);
            }
            else
            {
                // Replace 31280E2F2D2220808315C212DF8062A295B28325 with your cert thumbprint,
                // install it to the "Personal\Certificates" folder in the "Local Computer" certificate store,
                // and grant the permission of reading the private key to the service/application using the MDM consumption APIs.
                string testCertificateThumbprint = "C35CBFF9FA6C51E51E1DE97B6D1E246F27661301";
                connectionInfo = new ConnectionInfo(new Uri("https://shoebox2.metrics.nsatc.net/public/monitoringAccount/SignalRShoeboxTest/homeStamp"), testCertificateThumbprint, StoreLocation.LocalMachine);
            }

            var reader = new MetricReader(connectionInfo);

            // Single metric
            var id = new MetricIdentifier("SignalRShoeboxTest", "ShoeboxInternal", "ConnectionCountDelta");
            //var id = new MetricIdentifier("SignalRShoeboxTest", "systemLoad", "PodMemory");

            // The short link for this series is http://jarvis-int.dc.ad.msft.net/D10A9E2E.
            var definition = new TimeSeriesDefinition <MetricIdentifier>(
                id,
                new Dictionary <string, string> {
                { "ResourceId", "/subscriptions/5ea15035-434e-46ba-97cd-ea0927a47104/resourceGroups/testsoutheastasia/providers/Microsoft.SignalRService/SignalR/honzhangcenable3" }
            });

            TimeSeries <MetricIdentifier, double?> result =
                reader.GetTimeSeriesAsync(DateTime.UtcNow.AddMinutes(-10), DateTime.UtcNow, SamplingType.Average, definition).Result;

            foreach (var dataPoint in result.Datapoints)
            {
                Console.WriteLine("Time: {0}, Value: {1}", dataPoint.TimestampUtc, dataPoint.Value);
            }

            Console.WriteLine("############################ END OF GetSingleTimeSeries ##############################");
        }
示例#11
0
 public DoublyLinkedListNode(MetricReader value)
 {
     this.Value = value;
 }