/// <summary> /// Gets the dimension values for dimensionName satifying the dimensionFilters and /// </summary> /// <param name="metricId">Metric id.</param> /// <param name="filters">The dimension filters representing the pre-aggregate dimensions. Create an emtpy include filter for dimension with no filter values. Requested dimension should also be part of this and should be empty.</param> /// <param name="dimensionName">Name of the dimension for which values are requested.</param> /// <param name="startTimeUtc">Start time for evaluating dimension values.</param> /// <param name="endTimeUtc">End time for evaluating dimension values.</param> /// <returns>Dimension values for dimensionName.</returns> public async Task <IEnumerable <string> > GetDimensionValuesAsync(MetricIdentifier metricId, List <Tuple <string, IEnumerable <string> > > filters, string dimensionName, DateTime startTimeUtc, DateTime endTimeUtc) { filters.Sort((item1, item2) => string.Compare(item1.Item1, item2.Item1, StringComparison.OrdinalIgnoreCase)); var baseUrl = string.Format( "{0}/api/v2/hint/tenant/{1}/component/{2}/event/{3}/startTimeUtcMillis/{4}/endTimeUtcMillis/{5}", Endpoint, EscapeTwice(metricId.MonitoringAccount), EscapeTwice(metricId.MetricNamespace), EscapeTwice(metricId.MetricName), UnixEpochHelper.GetMillis(startTimeUtc), UnixEpochHelper.GetMillis(endTimeUtc)); var urlBuilder = new StringBuilder(baseUrl); foreach (var filter in filters) { if (filter.Item1.Equals(dimensionName, StringComparison.OrdinalIgnoreCase) && filter.Item2.Count() > 0) { throw new ArgumentException("Dimension filters cannot contain requested dimension with filter values"); } if (filter.Item2.Count() > 0) { foreach (var val in filter.Item2) { urlBuilder.Append("/").Append(EscapeTwice(filter.Item1)).Append("/").Append(EscapeTwice(val)); } } else { // Put Empty value. urlBuilder.Append("/").Append(EscapeTwice(filter.Item1)).Append("/").Append(EscapeTwice("{{*}}")); } } urlBuilder.Append("/").Append(EscapeTwice(dimensionName)).Append("/value"); var response = await GetResponse( new Uri(urlBuilder.ToString()), HttpMethod.Get, HttpClient, null, ClientId).ConfigureAwait(false); return(JsonConvert.DeserializeObject <List <string> >(response.Item1)); }
public async Task <TimeSeries <MonitorIdentifier, bool?> > GetMonitorHistoryAsync( DateTime startTimeUtc, DateTime endTimeUtc, TimeSeriesDefinition <MonitorIdentifier> monitorInstanceDefinition) { if (monitorInstanceDefinition == null) { throw new ArgumentNullException("monitorInstanceDefinition"); } if (startTimeUtc > endTimeUtc) { throw new ArgumentException(string.Format("startTimeUtc [{0}] must be <= endTimeUtc [{1}]", startTimeUtc, endTimeUtc)); } startTimeUtc = new DateTime(startTimeUtc.Ticks / TimeSpan.TicksPerMinute * TimeSpan.TicksPerMinute); endTimeUtc = new DateTime(endTimeUtc.Ticks / TimeSpan.TicksPerMinute * TimeSpan.TicksPerMinute); string dimensionsFlattened = null; if (monitorInstanceDefinition.DimensionCombination != null) { dimensionsFlattened = string.Join( "/", monitorInstanceDefinition.DimensionCombination.Select( d => string.Join("/", SpecialCharsHelper.EscapeTwice(d.Key), SpecialCharsHelper.EscapeTwice(d.Value)))); } string operation = $"{this.HealthRelativeUrl}/history"; string url = string.Format( "{0}{1}/monitoringAccount/{2}/metricNamespace/{3}/metric/{4}/monitorId/{5}/from/{6}/to/{7}{8}", this.connectionInfo.GetEndpoint(monitorInstanceDefinition.Id.MetricIdentifier.MonitoringAccount), operation, monitorInstanceDefinition.Id.MetricIdentifier.MonitoringAccount, SpecialCharsHelper.EscapeTwice(monitorInstanceDefinition.Id.MetricIdentifier.MetricNamespace), SpecialCharsHelper.EscapeTwice(monitorInstanceDefinition.Id.MetricIdentifier.MetricName), SpecialCharsHelper.EscapeTwice(monitorInstanceDefinition.Id.MonitorId), UnixEpochHelper.GetMillis(startTimeUtc), UnixEpochHelper.GetMillis(endTimeUtc), dimensionsFlattened != null ? "/" + dimensionsFlattened : string.Empty); var response = await this.GetResponseAsStringDelegate( new Uri(url), HttpMethod.Get, this.httpClient, monitorInstanceDefinition.Id.MetricIdentifier.MonitoringAccount, operation, null, string.Empty, null, null, MetricQueryResponseDeserializer.CurrentVersion, NumAttempts).ConfigureAwait(false); var values = JsonConvert.DeserializeObject <List <bool?> >(response.Item1); return(new TimeSeries <MonitorIdentifier, bool?>(startTimeUtc, endTimeUtc, SerializationConstants.DefaultSeriesResolutionInMinutes, monitorInstanceDefinition, new List <List <bool?> > { values }, TimeSeriesErrorCode.Success)); }