enh(plugin) add metricnamespace option to Azure Monitor get-metric mode (#2675)
* Added metricnamespace as parameter to the Azure Metrics script * Adjusted azcli.pm + added count as aggregation
This commit is contained in:
parent
7e675441c3
commit
1a1c380968
|
@ -279,6 +279,7 @@ sub azure_get_metrics_set_url {
|
||||||
"&metricnames=" . $encoded_metrics . "&aggregation=" . $encoded_aggregations .
|
"&metricnames=" . $encoded_metrics . "&aggregation=" . $encoded_aggregations .
|
||||||
"×pan=" . $encoded_timespan . "&interval=" . $options{interval};
|
"×pan=" . $encoded_timespan . "&interval=" . $options{interval};
|
||||||
$url .= "&\$filter=" . $options{dimension} if defined($options{dimension});
|
$url .= "&\$filter=" . $options{dimension} if defined($options{dimension});
|
||||||
|
$url .= "&metricnamespace=" . $uri->encode($options{metric_namespace}) if defined($options{metric_namespace});
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
@ -318,6 +319,9 @@ sub azure_get_metrics {
|
||||||
$results->{$metric_name}->{total} += $point->{total};
|
$results->{$metric_name}->{total} += $point->{total};
|
||||||
$results->{$metric_name}->{points}++;
|
$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>
|
=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>
|
=item B<--zeroed>
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ sub check_options {
|
||||||
|
|
||||||
if (defined($self->{option_results}->{aggregation})) {
|
if (defined($self->{option_results}->{aggregation})) {
|
||||||
foreach my $aggregation (@{$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}->add_option_msg(short_msg => "Aggregation '" . $aggregation . "' is not handled");
|
||||||
$self->{output}->option_exit();
|
$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 '');
|
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}' " .
|
"--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}'";
|
"--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 '');
|
$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}->{total} += $point->{total};
|
||||||
$results->{$metric_name}->{points}++;
|
$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 '');
|
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||||
|
|
||||||
my $cmd_options = "resource list --only-show-errors --output json";
|
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 .= " --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 .= " --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 '');
|
$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>
|
=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>
|
=item B<--zeroed>
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,8 @@ sub new {
|
||||||
"resource-type:s" => { name => 'resource_type' },
|
"resource-type:s" => { name => 'resource_type' },
|
||||||
"resource-namespace:s" => { name => 'resource_namespace' },
|
"resource-namespace:s" => { name => 'resource_namespace' },
|
||||||
"metric:s@" => { name => 'metric' },
|
"metric:s@" => { name => 'metric' },
|
||||||
"filter-dimension:s" => { name => 'filter_dimension'}
|
"filter-dimension:s" => { name => 'filter_dimension' },
|
||||||
|
"metric-namespace:s" => { name => 'metric_namespace' }
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
|
@ -151,6 +152,9 @@ sub check_options {
|
||||||
if (defined($self->{option_results}->{filter_dimension}) && $self->{option_results}->{filter_dimension} ne '') {
|
if (defined($self->{option_results}->{filter_dimension}) && $self->{option_results}->{filter_dimension} ne '') {
|
||||||
$self->{az_metrics_dimension} = $self->{option_results}->{filter_dimension};
|
$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 {
|
sub manage_selection {
|
||||||
|
@ -163,6 +167,7 @@ sub manage_selection {
|
||||||
resource_namespace => $self->{az_resource_namespace},
|
resource_namespace => $self->{az_resource_namespace},
|
||||||
metrics => $self->{az_metrics},
|
metrics => $self->{az_metrics},
|
||||||
aggregations => $self->{az_aggregation},
|
aggregations => $self->{az_aggregation},
|
||||||
|
metric_namespace => $self->{az_metric_namespace},
|
||||||
timeframe => $self->{az_timeframe},
|
timeframe => $self->{az_timeframe},
|
||||||
interval => $self->{az_interval},
|
interval => $self->{az_interval},
|
||||||
dimension => $self->{az_metrics_dimension}
|
dimension => $self->{az_metrics_dimension}
|
||||||
|
@ -170,7 +175,7 @@ sub manage_selection {
|
||||||
|
|
||||||
$self->{metrics} = {};
|
$self->{metrics} = {};
|
||||||
foreach my $label (keys %{$results}) {
|
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}));
|
next if (!defined($results->{$label}->{$aggregation}));
|
||||||
|
|
||||||
$self->{metrics}->{$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).
|
Set monitor metrics (Required) (Can be multiple).
|
||||||
|
|
||||||
|
=item B<--metric-namespace>
|
||||||
|
|
||||||
|
Set monitor metric namespace.
|
||||||
|
|
||||||
=item B<--filter-dimension>
|
=item B<--filter-dimension>
|
||||||
|
|
||||||
Specify the metric dimension (required for some specific metrics)
|
Specify the metric dimension (required for some specific metrics)
|
||||||
|
|
Loading…
Reference in New Issue