mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-09 18:30:16 +00:00
Stop agent on 404 while running. Add --[no]agent-api so stop_all_services() works offline. Update sample with histo data again.
This commit is contained in:
24
bin/pt-agent
24
bin/pt-agent
@@ -5523,6 +5523,7 @@ sub main {
|
||||
if ( my $service = $o->get('run-service') ) {
|
||||
eval {
|
||||
run_service(
|
||||
agent_api => $o->get('agent-api'),
|
||||
api_key => $api_key,
|
||||
service => $service,
|
||||
lib_dir => $o->get('lib'),
|
||||
@@ -6227,8 +6228,13 @@ sub get_config {
|
||||
if (blessed($e)) {
|
||||
if ($e->isa('Percona::WebAPI::Exception::Request')) {
|
||||
if ( $e->status == 404 ) {
|
||||
$logger->info('Agent ' . $agent->name. ' is not configured.')
|
||||
unless $quiet;
|
||||
stop_all_services(
|
||||
lib_dir => $lib_dir,
|
||||
);
|
||||
$logger->fatal("API reports agent not found: the agent has been "
|
||||
. "deleted, or its UUID (" . ($agent->uuid || '?') . ") "
|
||||
. "is wrong. Check https://cloud.percona.com/agents for a "
|
||||
. "list of active agents.");
|
||||
}
|
||||
else {
|
||||
$logger->info("$e"); # API error?
|
||||
@@ -6948,6 +6954,7 @@ sub run_service {
|
||||
|
||||
# Optional args
|
||||
my $bin_dir = defined $args{bin_dir} ? $args{bin_dir} : "$FindBin::Bin/";
|
||||
my $agent_api = $args{agent_api};
|
||||
my $client = $args{client}; # for testing
|
||||
my $agent = $args{agent}; # for testing
|
||||
my $entry_links = $args{entry_links}; # for testing
|
||||
@@ -6977,7 +6984,7 @@ sub run_service {
|
||||
|
||||
# Connect to Percona, get entry links.
|
||||
my $logger_client;
|
||||
if ( !$client || !$entry_links ) {
|
||||
if ( $agent_api && (!$client || !$entry_links) ) {
|
||||
($client, $entry_links, $logger_client) = get_api_client(
|
||||
api_key => $api_key,
|
||||
tries => 2,
|
||||
@@ -7003,7 +7010,7 @@ sub run_service {
|
||||
}
|
||||
}
|
||||
|
||||
if ( $entry_links && $entry_links->{agents} ) {
|
||||
if ( $agent_api && $entry_links && $entry_links->{agents} ) {
|
||||
$agent = eval {
|
||||
$client->get(
|
||||
link => $entry_links->{agents} . '/' . $agent->uuid,
|
||||
@@ -8025,7 +8032,7 @@ sub stop_all_services {
|
||||
my $stop_log = "$lib_dir/logs/$service.stop";
|
||||
my $run_log = "$lib_dir/logs/$service.run";
|
||||
my $cmd = ($env_vars ? "$env_vars " : '')
|
||||
. "${bin_dir}pt-agent --run-service $service"
|
||||
. "${bin_dir}pt-agent --run-service $service --no-agent-api"
|
||||
. " </dev/null"
|
||||
. " >$stop_log 2>&1";
|
||||
$logger->info("Stopping $service...");
|
||||
@@ -9156,6 +9163,13 @@ L<"--status">, L<"--stop">, and L<"--reset"> are mutually exclusive.
|
||||
|
||||
=over
|
||||
|
||||
=item --[no]agent-api
|
||||
|
||||
default: yes
|
||||
|
||||
Enable the agent API; do not use this option manually. This option is used
|
||||
internally to allow the agent to stop itself and shutdown quickly.
|
||||
|
||||
=item --agent-uuid
|
||||
|
||||
type: string
|
||||
|
@@ -23,6 +23,18 @@ Content-Disposition: form-data; name="data"
|
||||
"ts" : null
|
||||
},
|
||||
"fingerprint" : "select min(id),max(id) from tbl",
|
||||
"histograms" : {
|
||||
"Query_time" : [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
},
|
||||
"metrics" : {
|
||||
"Lock_time" : {
|
||||
"avg" : "0.009453",
|
||||
|
Reference in New Issue
Block a user