/// <summary> /// Gets the monitors for the given <paramref name="metricIdentifier"/>. /// </summary> /// <param name="metricIdentifier">The metric identifier.</param> /// <returns>The monitors for the given <paramref name="metricIdentifier"/>.</returns> public async Task <IReadOnlyList <MonitorIdentifier> > GetMonitorsAsync(MetricIdentifier metricIdentifier) { metricIdentifier.Validate(); string url = string.Format( "{0}{1}/monitoringAccount/{2}/metricNamespace/{3}/metric/{4}/monitorIDs", this.connectionInfo.GetEndpoint(metricIdentifier.MonitoringAccount), this.ConfigRelativeUrlV2, metricIdentifier.MonitoringAccount, SpecialCharsHelper.EscapeTwice(metricIdentifier.MetricNamespace), SpecialCharsHelper.EscapeTwice(metricIdentifier.MetricName)); var response = await this.GetResponseAsStringDelegate( new Uri(url), HttpMethod.Get, this.httpClient, metricIdentifier.MonitoringAccount, this.ConfigRelativeUrlV2, null, string.Empty, null, null, MetricQueryResponseDeserializer.CurrentVersion, NumAttempts).ConfigureAwait(false); return(JsonConvert.DeserializeObject <MonitorIdentifier[]>(response.Item1)); }
/// <summary> /// Deletes the metric configuration. /// </summary> /// <param name="metricIdentifier">The metric identifier.</param> /// <returns>A task representing the deletion of the configuration.</returns> /// <remarks> /// It deletes only the metric configuration, not the metric data. /// </remarks> public async Task Delete(MetricIdentifier metricIdentifier) { string url = string.Format( "{0}{1}/monitoringAccount/{2}/metricNamespace/{3}/metric/{4}", this.connectionInfo.GetEndpoint(metricIdentifier.MonitoringAccount), this.ConfigRelativeUrl, metricIdentifier.MonitoringAccount, SpecialCharsHelper.EscapeTwice(metricIdentifier.MetricNamespace), SpecialCharsHelper.EscapeTwice(metricIdentifier.MetricName)); await HttpClientHelper.GetResponse( new Uri(url), HttpMethod.Delete, this.httpClient, metricIdentifier.MonitoringAccount, this.ConfigRelativeUrl).ConfigureAwait(false); }
/// <summary> /// Gets the metric configuration. /// </summary> /// <param name="metricIdentifier">The metric identifier.</param> /// <returns>The metric configuration.</returns> public async Task <MetricConfigurationV2> Get(MetricIdentifier metricIdentifier) { string url = string.Format( "{0}{1}/monitoringAccount/{2}/metricNamespace/{3}/metric/{4}", this.connectionInfo.GetEndpoint(metricIdentifier.MonitoringAccount), this.ConfigRelativeUrl, metricIdentifier.MonitoringAccount, SpecialCharsHelper.EscapeTwice(metricIdentifier.MetricNamespace), SpecialCharsHelper.EscapeTwice(metricIdentifier.MetricName)); var response = await HttpClientHelper.GetResponse( new Uri(url), HttpMethod.Get, this.httpClient, metricIdentifier.MonitoringAccount, this.ConfigRelativeUrl).ConfigureAwait(false); return(JsonConvert.DeserializeObject <MetricConfigurationV2>(response.Item1)); }
/// <summary> /// Gets the monitor IDs for the given monitoring account, optionally with the metric namespace. /// </summary> /// <param name="monitoringAccount">The monitoring account.</param> /// <param name="metricNamespace">The metric namespace.</param> /// <returns> /// The monitor IDs for the given monitoring account, optionally with the metric namespace. /// </returns> public async Task <IReadOnlyList <MonitorIdentifier> > GetMonitorsAsync(string monitoringAccount, string metricNamespace = null) { if (string.IsNullOrWhiteSpace(monitoringAccount)) { throw new ArgumentException("monitoringAccount is null or empty.", monitoringAccount); } string namespaceSegments = string.Empty; if (!string.IsNullOrWhiteSpace(metricNamespace)) { namespaceSegments = string.Format("metricNamespace/{0}", SpecialCharsHelper.EscapeTwice(metricNamespace)); } string url = string.Format( "{0}{1}/monitoringAccount/{2}/{3}/monitorIDs", this.connectionInfo.GetEndpoint(monitoringAccount), this.ConfigRelativeUrlV2, monitoringAccount, namespaceSegments); var response = await this.GetResponseAsStringDelegate( new Uri(url), HttpMethod.Get, this.httpClient, monitoringAccount, this.ConfigRelativeUrlV2, null, string.Empty, null, null, MetricQueryResponseDeserializer.CurrentVersion, NumAttempts).ConfigureAwait(false); return(JsonConvert.DeserializeObject <MonitorIdentifier[]>(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)); }
/// <summary> /// Batched API to get the current monitor health statuses. /// </summary> /// <param name="monitorInstanceDefinitions">The monitor instance definitions.</param> /// <returns> /// The current monitor health statuses. /// </returns> public async Task <IReadOnlyList <KeyValuePair <TimeSeriesDefinition <MonitorIdentifier>, IMonitorHealthStatus> > > GetMultipleCurrentHeathStatusesAsync( IEnumerable <TimeSeriesDefinition <MonitorIdentifier> > monitorInstanceDefinitions) { if (monitorInstanceDefinitions == null) { throw new ArgumentNullException("monitorInstanceDefinitions"); } var definitionList = monitorInstanceDefinitions.ToList(); if (definitionList.Count == 0) { throw new ArgumentException("The count of 'monitorInstanceDefinitions' is 0."); } if (definitionList.Any(d => d == null)) { throw new ArgumentException("At least one of monitorInstanceDefinitions are null."); } var monitorIdentifier = definitionList[0].Id; var dimensionCombinationList = new List <Dictionary <string, string> >(definitionList.Count); foreach (var definition in definitionList) { if (!definition.Id.Equals(monitorIdentifier)) { throw new MetricsClientException("All the time series definitions must have the same monitor identifier."); } var dict = new Dictionary <string, string>(); if (definition.DimensionCombination != null) { foreach (var kvp in definition.DimensionCombination) { dict[kvp.Key] = kvp.Value; } } dimensionCombinationList.Add(dict); } string operation = $"{this.HealthRelativeUrl}/batchedRead"; string url = string.Format( "{0}{1}/monitoringAccount/{2}/metricNamespace/{3}/metric/{4}/monitorId/{5}", this.connectionInfo.GetEndpoint(monitorIdentifier.MetricIdentifier.MonitoringAccount), operation, monitorIdentifier.MetricIdentifier.MonitoringAccount, SpecialCharsHelper.EscapeTwice(monitorIdentifier.MetricIdentifier.MetricNamespace), SpecialCharsHelper.EscapeTwice(monitorIdentifier.MetricIdentifier.MetricName), SpecialCharsHelper.EscapeTwice(monitorIdentifier.MonitorId)); var response = await this.GetResponseAsStringDelegate( new Uri(url), HttpMethod.Post, this.httpClient, monitorIdentifier.MetricIdentifier.MonitoringAccount, operation, dimensionCombinationList, string.Empty, null, null, MetricQueryResponseDeserializer.CurrentVersion, NumAttempts).ConfigureAwait(false); var deserializeObject = JsonConvert.DeserializeObject <List <MonitorHealthStatus> >(response.Item1); var results = new KeyValuePair <TimeSeriesDefinition <MonitorIdentifier>, IMonitorHealthStatus> [deserializeObject.Count]; for (int i = 0; i < deserializeObject.Count; ++i) { var status = new KeyValuePair <TimeSeriesDefinition <MonitorIdentifier>, IMonitorHealthStatus>(definitionList[i], deserializeObject[i]); results[i] = status; } return(results); }