enh(gcp) add dimension option (#1633)
* enh(gcp) add dimension option * enh(gcp) indent and unecessary condition
This commit is contained in:
parent
b842ec970e
commit
84a8488496
|
@ -96,7 +96,7 @@ sub set_counters {
|
|||
key_values => [ { name => $metric . '_' . $aggregation }, { name => 'display' }, { name => 'stat' } ],
|
||||
closure_custom_calc => $self->can('custom_metric_calc'),
|
||||
closure_custom_calc_extra_options => { metric_perf => $metric_perf,
|
||||
metric_label => $metric_label, metric_name => $metric_name, metric => $metric },
|
||||
metric_label => $metric_label, metric_name => $metric_name, metric => $metric },
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
|
||||
|
@ -174,6 +174,7 @@ sub manage_selection {
|
|||
foreach my $instance (@{$self->{gcp_instance}}) {
|
||||
foreach my $metric (@{$self->{gcp_metrics}}) {
|
||||
($metric_results, undef) = $options{custom}->gcp_get_metrics(
|
||||
dimension => 'metric.labels.instance_name',
|
||||
instance => $instance,
|
||||
metric => $metric,
|
||||
api => $self->{gcp_api},
|
||||
|
|
|
@ -223,6 +223,7 @@ sub manage_selection {
|
|||
foreach my $instance (@{$self->{gcp_instance}}) {
|
||||
foreach my $metric (@{$self->{gcp_metrics}}) {
|
||||
($metric_results, undef) = $options{custom}->gcp_get_metrics(
|
||||
dimension => 'metric.labels.instance_name',
|
||||
instance => $instance,
|
||||
metric => $metric,
|
||||
api => $self->{gcp_api},
|
||||
|
|
|
@ -215,6 +215,7 @@ sub manage_selection {
|
|||
foreach my $instance (@{$self->{gcp_instance}}) {
|
||||
foreach my $metric (@{$self->{gcp_metrics}}) {
|
||||
($metric_results, undef) = $options{custom}->gcp_get_metrics(
|
||||
dimension => 'metric.labels.instance_name',
|
||||
instance => $instance,
|
||||
metric => $metric,
|
||||
api => $self->{gcp_api},
|
||||
|
|
|
@ -106,11 +106,11 @@ sub check_options {
|
|||
$self->{step} = (defined($self->{option_results}->{step})) ? $self->{option_results}->{step} : undef;
|
||||
$self->{key_file} = (defined($self->{option_results}->{key_file})) ? $self->{option_results}->{key_file} : undef;
|
||||
$self->{authorization_endpoint} = (defined($self->{option_results}->{authorization_endpoint})) ?
|
||||
$self->{option_results}->{authorization_endpoint} : 'https://www.googleapis.com/oauth2/v4/token';
|
||||
$self->{option_results}->{authorization_endpoint} : 'https://www.googleapis.com/oauth2/v4/token';
|
||||
$self->{monitoring_endpoint} = (defined($self->{option_results}->{monitoring_endpoint})) ?
|
||||
$self->{option_results}->{monitoring_endpoint} : 'https://monitoring.googleapis.com/v3';
|
||||
$self->{option_results}->{monitoring_endpoint} : 'https://monitoring.googleapis.com/v3';
|
||||
$self->{scope_endpoint} = (defined($self->{option_results}->{scope_endpoint})) ?
|
||||
$self->{option_results}->{scope_endpoint} : 'https://www.googleapis.com/auth/cloud-platform';
|
||||
$self->{option_results}->{scope_endpoint} : 'https://www.googleapis.com/auth/cloud-platform';
|
||||
|
||||
if (!defined($self->{key_file}) || $self->{key_file} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --key-file option.");
|
||||
|
@ -283,7 +283,7 @@ sub gcp_get_metrics_set_url {
|
|||
|
||||
my $uri = URI::Encode->new({encode_reserved => 1});
|
||||
my $encoded_filter = $uri->encode('metric.type = "' . $options{api} . '/' . $options{metric} . '"');
|
||||
$encoded_filter .= $uri->encode(' AND metric.labels.instance_name = starts_with(' . $options{instance} . ')');
|
||||
$encoded_filter .= $uri->encode(' AND ' . $options{dimension} . ' = starts_with(' . $options{instance} . ')');
|
||||
$encoded_filter .= ' AND ' . $uri->encode(join(' AND ', @{$options{extra_filters}})) if (defined($options{extra_filters}) && $options{extra_filters} ne '');
|
||||
my $encoded_start_time = $uri->encode($options{start_time});
|
||||
my $encoded_end_time = $uri->encode($options{end_time});
|
||||
|
|
|
@ -91,6 +91,7 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
"dimension:s" => { name => 'dimension' },
|
||||
"instance:s" => { name => 'instance' },
|
||||
"metric:s" => { name => 'metric' },
|
||||
"api:s" => { name => 'api' },
|
||||
|
@ -104,6 +105,10 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{dimension})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --dimension <name>.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{instance})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --instance <name>.");
|
||||
$self->{output}->option_exit();
|
||||
|
@ -117,6 +122,7 @@ sub check_options {
|
|||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{gcp_dimension} = $self->{option_results}->{dimension};
|
||||
$self->{gcp_instance} = $self->{option_results}->{instance};
|
||||
$self->{gcp_metric} = $self->{option_results}->{metric};
|
||||
$self->{gcp_api} = $self->{option_results}->{api};
|
||||
|
@ -144,21 +150,22 @@ sub check_options {
|
|||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($results, $raw_results) = $options{custom}->gcp_get_metrics(
|
||||
instance => $self->{gcp_instance},
|
||||
metric => $self->{gcp_metric},
|
||||
api => $self->{gcp_api},
|
||||
extra_filters => $self->{gcp_extra_filters},
|
||||
aggregations => $self->{gcp_aggregation},
|
||||
timeframe => $self->{gcp_timeframe},
|
||||
);
|
||||
|
||||
|
||||
$self->{metrics} = {};
|
||||
|
||||
my ($results, $raw_results) = $options{custom}->gcp_get_metrics(
|
||||
dimension => $self->{gcp_dimension},
|
||||
instance => $self->{gcp_instance},
|
||||
metric => $self->{gcp_metric},
|
||||
api => $self->{gcp_api},
|
||||
extra_filters => $self->{gcp_extra_filters},
|
||||
aggregations => $self->{gcp_aggregation},
|
||||
timeframe => $self->{gcp_timeframe},
|
||||
);
|
||||
|
||||
foreach my $label (keys %{$results}) {
|
||||
foreach my $aggregation (('minimum', 'maximum', 'average', 'total')) {
|
||||
next if (!defined($results->{$label}->{$aggregation}));
|
||||
|
||||
$self->{metrics} = {
|
||||
display => $self->{gcp_instance},
|
||||
label => $label,
|
||||
|
@ -167,7 +174,7 @@ sub manage_selection {
|
|||
perf_label => $label . '_' . $aggregation,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Raw data:\n%s", Dumper($raw_results)), debug => 1);
|
||||
}
|
||||
|
@ -196,6 +203,10 @@ Set GCP API (Required).
|
|||
|
||||
Set stackdriver metric (Required).
|
||||
|
||||
=item B<--dimension>
|
||||
|
||||
Set dimension primary filter (Required).
|
||||
|
||||
=item B<--instance>
|
||||
|
||||
Set instance name (Required).
|
||||
|
|
Loading…
Reference in New Issue