diff --git a/cloud/azure/custom/api.pm b/cloud/azure/custom/api.pm index 7f782b5f2..516ec9a72 100644 --- a/cloud/azure/custom/api.pm +++ b/cloud/azure/custom/api.pm @@ -279,6 +279,7 @@ sub azure_get_metrics_set_url { "&metricnames=" . $encoded_metrics . "&aggregation=" . $encoded_aggregations . "×pan=" . $encoded_timespan . "&interval=" . $options{interval}; $url .= "&\$filter=" . $options{dimension} if defined($options{dimension}); + $url .= "&metricnamespace=" . $uri->encode($options{metric_namespace}) if defined($options{metric_namespace}); return $url; } @@ -318,6 +319,9 @@ sub azure_get_metrics { $results->{$metric_name}->{total} += $point->{total}; $results->{$metric_name}->{points}++; } + if (defined($point->{count})) { + $results->{$metric_name}->{count} = $point->{count}; + } } } @@ -719,7 +723,7 @@ Set interval of the metric query (Can be : PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, =item B<--aggregation> -Set monitor aggregation (Can be multiple, Can be: 'minimum', 'maximum', 'average', 'total'). +Set monitor aggregation (Can be multiple, Can be: 'minimum', 'maximum', 'average', 'total', 'count'). =item B<--zeroed> diff --git a/cloud/azure/custom/azcli.pm b/cloud/azure/custom/azcli.pm index 253137fe5..1a179b916 100644 --- a/cloud/azure/custom/azcli.pm +++ b/cloud/azure/custom/azcli.pm @@ -82,7 +82,7 @@ sub check_options { if (defined($self->{option_results}->{aggregation})) { foreach my $aggregation (@{$self->{option_results}->{aggregation}}) { - if ($aggregation !~ /average|maximum|minimum|total/i) { + if ($aggregation !~ /average|maximum|minimum|total|count/i) { $self->{output}->add_option_msg(short_msg => "Aggregation '" . $aggregation . "' is not handled"); $self->{output}->option_exit(); } @@ -154,7 +154,7 @@ sub azure_get_metrics_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "monitor metrics list --metrics '" . join('\' \'', @{$options{metrics}}) . "' --start-time $options{start_time} --end-time $options{end_time} " . + my $cmd_options = "monitor metrics list --metrics '" . join('\' \'', @{$options{metrics}}) . "' --namespace $options{metric_namespace} --start-time $options{start_time} --end-time $options{end_time} " . "--interval $options{interval} --aggregation '" . join('\' \'', @{$options{aggregations}}) . "' --only-show-errors --output json --resource '$options{resource}' " . "--resource-group '$options{resource_group}' --resource-type '$options{resource_type}' --resource-namespace '$options{resource_namespace}'"; $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); @@ -198,6 +198,9 @@ sub azure_get_metrics { $results->{$metric_name}->{total} += $point->{total}; $results->{$metric_name}->{points}++; } + if (defined($point->{count})) { + $results->{$metric_name}->{count} = $point->{count}; + } } } @@ -237,7 +240,7 @@ sub azure_list_resources_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); my $cmd_options = "resource list --only-show-errors --output json"; - $cmd_options .= " --namespace '$options{namespace}'" if (defined($options{namespace}) && $options{namespace} ne ''); + $cmd_options .= " --namespace '$options{resource_namespace}'" if (defined($options{resource_namespace}) && $options{resource_namespace} ne ''); $cmd_options .= " --resource-type '$options{resource_type}'" if (defined($options{resource_type}) && $options{resource_type} ne ''); $cmd_options .= " --location '$options{location}'" if (defined($options{location}) && $options{location} ne ''); $cmd_options .= " --resource-group '$options{resource_group}'" if (defined($options{resource_group}) && $options{resource_group} ne ''); @@ -601,7 +604,7 @@ Set interval of the metric query (Can be : PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, =item B<--aggregation> -Set monitor aggregation (Can be multiple, Can be: 'minimum', 'maximum', 'average', 'total'). +Set monitor aggregation (Can be multiple, Can be: 'minimum', 'maximum', 'average', 'total', 'count'). =item B<--zeroed> diff --git a/cloud/azure/management/monitor/mode/getmetrics.pm b/cloud/azure/management/monitor/mode/getmetrics.pm index 3092f514f..abc080ae7 100644 --- a/cloud/azure/management/monitor/mode/getmetrics.pm +++ b/cloud/azure/management/monitor/mode/getmetrics.pm @@ -99,7 +99,8 @@ sub new { "resource-type:s" => { name => 'resource_type' }, "resource-namespace:s" => { name => 'resource_namespace' }, "metric:s@" => { name => 'metric' }, - "filter-dimension:s" => { name => 'filter_dimension'} + "filter-dimension:s" => { name => 'filter_dimension' }, + "metric-namespace:s" => { name => 'metric_namespace' } }); return $self; @@ -151,6 +152,9 @@ sub check_options { if (defined($self->{option_results}->{filter_dimension}) && $self->{option_results}->{filter_dimension} ne '') { $self->{az_metrics_dimension} = $self->{option_results}->{filter_dimension}; } + if (defined($self->{option_results}->{metric_namespace}) && $self->{option_results}->{metric_namespace} ne '') { + $self->{az_metric_namespace} = $self->{option_results}->{metric_namespace}; + } } sub manage_selection { @@ -163,6 +167,7 @@ sub manage_selection { resource_namespace => $self->{az_resource_namespace}, metrics => $self->{az_metrics}, aggregations => $self->{az_aggregation}, + metric_namespace => $self->{az_metric_namespace}, timeframe => $self->{az_timeframe}, interval => $self->{az_interval}, dimension => $self->{az_metrics_dimension} @@ -170,7 +175,7 @@ sub manage_selection { $self->{metrics} = {}; foreach my $label (keys %{$results}) { - foreach my $aggregation (('minimum', 'maximum', 'average', 'total')) { + foreach my $aggregation (('minimum', 'maximum', 'average', 'total', 'count')) { next if (!defined($results->{$label}->{$aggregation})); $self->{metrics}->{$label . '_' . $aggregation} = { @@ -230,6 +235,10 @@ Set resource type (Required if resource's name is used). Set monitor metrics (Required) (Can be multiple). +=item B<--metric-namespace> + +Set monitor metric namespace. + =item B<--filter-dimension> Specify the metric dimension (required for some specific metrics)