Skip to content
Permalink
Browse files
Implements metrics and metricdefinitions API
  • Loading branch information
danielestevez authored and nacx committed Jun 28, 2017
1 parent 3b8f5c6 commit 47c4e72ac2cb4e3d4da283d4ca234cde23f8e145
Showing 14 changed files with 842 additions and 0 deletions.
@@ -27,6 +27,8 @@
import org.jclouds.azurecompute.arm.features.JobApi;
import org.jclouds.azurecompute.arm.features.LoadBalancerApi;
import org.jclouds.azurecompute.arm.features.LocationApi;
import org.jclouds.azurecompute.arm.features.MetricDefinitionsApi;
import org.jclouds.azurecompute.arm.features.MetricsApi;
import org.jclouds.azurecompute.arm.features.NetworkInterfaceCardApi;
import org.jclouds.azurecompute.arm.features.NetworkSecurityGroupApi;
import org.jclouds.azurecompute.arm.features.NetworkSecurityRuleApi;
@@ -208,4 +210,22 @@ NetworkSecurityRuleApi getNetworkSecurityRuleApi(@PathParam("resourcegroup") Str
*/
@Delegate
ImageApi getVirtualMachineImageApi(@PathParam("resourcegroup") String resourcegroup);

/**
* The metrics API includes operations to get insights into entities within your
* subscription.
*
* @see <a href="https://docs.microsoft.com/en-us/rest/api/monitor/metrics">docs</a>
*/
@Delegate
MetricsApi getMetricsApi(@PathParam("resourceid") String resourceid);

/**
* The metric definitions API includes operations to get insights available for entities within your
* subscription.
*
* @see <a href="https://docs.microsoft.com/en-us/rest/api/monitor/metricdefinitions">docs</a>
*/
@Delegate
MetricDefinitionsApi getMetricsDefinitionsApi(@PathParam("resourceid") String resourceid);
}
@@ -44,6 +44,8 @@
import org.jclouds.azurecompute.arm.features.LoadBalancerApi;
import org.jclouds.azurecompute.arm.features.LocationApi;
import org.jclouds.azurecompute.arm.features.DiskApi;
import org.jclouds.azurecompute.arm.features.MetricDefinitionsApi;
import org.jclouds.azurecompute.arm.features.MetricsApi;
import org.jclouds.azurecompute.arm.features.NetworkInterfaceCardApi;
import org.jclouds.azurecompute.arm.features.NetworkSecurityGroupApi;
import org.jclouds.azurecompute.arm.features.NetworkSecurityRuleApi;
@@ -115,6 +117,8 @@ public static Properties defaultProperties() {
properties.put(API_VERSION_PREFIX + AvailabilitySetApi.class.getSimpleName(), "2016-04-30-preview");
properties.put(API_VERSION_PREFIX + DiskApi.class.getSimpleName(), "2017-03-30");
properties.put(API_VERSION_PREFIX + ImageApi.class.getSimpleName(), "2016-04-30-preview");
properties.put(API_VERSION_PREFIX + MetricDefinitionsApi.class.getSimpleName(), "2017-05-01-preview");
properties.put(API_VERSION_PREFIX + MetricsApi.class.getSimpleName(), "2016-09-01");

return properties;
}
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.azurecompute.arm.domain;

import java.util.List;

import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;

/**
* A Metric with its values for a resource
*/
@AutoValue
public abstract class Metric {

public abstract List<MetricData> data();

public abstract String id();

@Nullable
public abstract MetricName name();

public abstract String type();

public abstract String unit();

@SerializedNames({ "data", "id", "name", "type", "unit" })
public static Metric create(final List<MetricData> data, final String id, final MetricName name, final String type,
final String unit) {
return new AutoValue_Metric(data == null ? ImmutableList.<MetricData> of() : ImmutableList.copyOf(data), id, name,
type, unit);
}

}
@@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.azurecompute.arm.domain;

import java.util.Date;

import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import com.google.auto.value.AutoValue;

/**
*
*/
@AutoValue
public abstract class MetricData
{

/**
* The timestamp for the metric value in ISO 8601 format.
*/
public abstract Date timeStamp();

/**
* The average value in the time range
*/
@Nullable
public abstract Double total();

/**
* The sum of all of the values in the time range.
*/
@Nullable
public abstract Double average();

/**
* The least value in the time range.
*/
@Nullable
public abstract Double minimum();

/**
* The greatest value in the time range.
*/
@Nullable
public abstract Double maximum();

/**
* The number of samples in the time range.
*/
@Nullable
public abstract Long count();

@SerializedNames({"timeStamp", "total", "average", "minimum", "maximum", "count"})
public static MetricData create(final Date timeStamp, final Double total, final Double average,
final Double minimum, final Double maximum, final Long count)
{
return new AutoValue_MetricData(timeStamp, total, average, minimum, maximum, count);
}
}
@@ -0,0 +1,97 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.azurecompute.arm.domain;

import java.util.List;

import org.jclouds.azurecompute.arm.util.GetEnumValue;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;

/**
* A Metric definition for a resource
*/
@AutoValue
public abstract class MetricDefinition {

public enum AggregationType {
None("None"), Average("Average"), Count("Count"), Total("Total"), Minimum("Minimum"), Maximum(
"Maximum"), UNRECOGNIZED("Unrecognized");

private final String label;

AggregationType(String label) {
this.label = label;
}

public static AggregationType fromValue(final String text) {
return (AggregationType) GetEnumValue.fromValueOrDefault(text, AggregationType.UNRECOGNIZED);
}

@Override
public String toString() {
return label;
}
}

@Nullable
public abstract String resourceId();

public abstract MetricName name();

@Nullable
public abstract Boolean isDimensionRequired();

public abstract String unit();

public abstract AggregationType primaryAggregationType();

public abstract List<MetricDefinition.MetricAvailability> metricAvailabilities();

public abstract String id();

@SerializedNames({ "resourceId", "name", "isDimensionRequired", "unit", "primaryAggregationType",
"metricAvailabilities", "id" })
public static MetricDefinition create(final String resourceId, final MetricName name,
final Boolean isDimensionRequired, final String unit, final AggregationType primaryAggregationType,
List<MetricAvailability> metricAvailabilities, final String id) {
return new AutoValue_MetricDefinition(resourceId, name, isDimensionRequired, unit, primaryAggregationType,
metricAvailabilities == null ?
ImmutableList.<MetricAvailability> of() :
ImmutableList.copyOf(metricAvailabilities), id);
}

@AutoValue
public abstract static class MetricAvailability {

public abstract String timeGrain();

public abstract String retention();

MetricAvailability() {

}

@SerializedNames({ "timeGrain", "retention" })
public static MetricDefinition.MetricAvailability create(String timeGrain, String retention) {
return new AutoValue_MetricDefinition_MetricAvailability(timeGrain, retention);
}
}
}
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.azurecompute.arm.domain;

import org.jclouds.json.SerializedNames;

import com.google.auto.value.AutoValue;

/**
* A Metric with its values for a resource
*/
@AutoValue
public abstract class MetricName {

public abstract String value();

public abstract String localizedValue();

@SerializedNames({ "value", "localizedValue" })
public static MetricName create(String value, String localizedValue) {
return new AutoValue_MetricName(value, localizedValue);
}

}
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.azurecompute.arm.features;

import java.util.List;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
import org.jclouds.azurecompute.arm.domain.MetricDefinition;
import org.jclouds.azurecompute.arm.filters.ApiVersionFilter;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.filters.OAuthFilter;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;

/**
* This Azure Resource Manager API provides all the metric definitions available for a given resource
* <p/>
*
* @see <a href="https://docs.microsoft.com/en-us/rest/api/monitor/metricdefinitions">docs</a>
*/
@Path("/{resourceid}")
@RequestFilters({ OAuthFilter.class, ApiVersionFilter.class })
@Consumes(MediaType.APPLICATION_JSON)
public interface MetricDefinitionsApi {
@Named("metrics:list")
@Path("/providers/microsoft.insights/metricdefinitions")
@GET
@SelectJson("value")
@Fallback(EmptyListOnNotFoundOr404.class)
List<MetricDefinition> list(@Nullable @QueryParam("$filter") String filter);
}

0 comments on commit 47c4e72

Please sign in to comment.