Execução lenta de script

2

Eu tenho um problema estranho ...

Meu script:

#!/bin/bash
SECONDS=0

lock_file=/tmp/$0.lock

[ -e $lock_file ] && exit

touch $lock_file

echo "<<<db2_hadr_check>>>"
instances=( db2inst1 db2inst2 )

plog() {
        lfile=/tmp/$0.log

        echo "['date +%T'] $1" >> $lfile
}

for instance in "${instances[@]}"; do
        plog "get dbname for instance $instance"
        name=$(su - $instance -c 'echo $dbname')
        plog "get hadr info for instance $instance"
        arr=($(su - $instance -c 'db2pd -db $dbname -hadr | egrep -i "HADR_CONNECT_STATUS |HADR_LOG_GAP" | cut -d "=" -f 2'))
        plog "check result for instance $instance"

        s=${arr[0]}
        lg=${arr[1]}

        [ -z $s ] && s="DISCONNECTED"
        [ -z $lg ] && lg=0

        plog "return result for instance $instance"

        #dbname hadr_conn_status log_gap
        echo "$name $s $lg"
done
plog "Execution time: $SECONDS"
plog "############################################################"
rm $lock_file

Eu manualmente executo este script no meu servidor de teste (versão 21 do Fedora) ...

Log da minha execução manual:

[11:46:36] get dbname for instance db2inst1
[11:46:37] get hadr info for instance db2inst1
[11:46:37] check result for instance db2inst1
[11:46:37] return result for instance db2inst1
[11:46:37] get dbname for instance db2inst2
[11:46:38] get hadr info for instance db2inst2
[11:46:39] check result for instance db2inst2
[11:46:39] return result for instance db2inst2
[11:46:39] Execution time: 3
[11:46:39] ############################################################

Depois disso, adicionei essa verificação no meu servidor de monitor (nagios + check_mk). Se eu executar o check_mk_agent (que então chama meu script), recebo este tempo de execução:

real    0m2.923s
user    0m0.755s
sys     0m1.982s

Tudo bem.

Aqui está o meu problema ...

Log da execução com o servidor check_mk:

[11:48:38] get dbname for instance db2inst1
[11:49:04] get hadr info for instance db2inst1
[11:49:30] check result for instance db2inst1
[11:49:30] return result for instance db2inst1
[11:49:30] get dbname for instance db2inst2
[11:49:55] get hadr info for instance db2inst2
[11:50:21] check result for instance db2inst2
[11:50:21] return result for instance db2inst2
[11:50:21] Execution time: 103
[11:50:21] ############################################################

quando este script é chamado de check_mk (nagios), ele é executado por 103 segundos !

Alguém pode explicar isso?

Informações adicionais # 1:

servidor check_mk usa xinetd para executar check_mk_agent no host

arquivo de configuração (/etc/xinetd.d/check_mk):

service check_mk
{
        type           = UNLISTED
        port           = 6556
        socket_type    = stream
        protocol       = tcp
        wait           = no
        user           = root
        server         = /usr/bin/check_mk_agent

        log_on_success =

        disable        = no
}

/etc/pam.d/su:

#%PAM-1.0
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient      pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth           required        pam_wheel.so use_uid
auth            substack        system-auth
auth            include         postlogin
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet
account         include         system-auth
password        include         system-auth
session         include         system-auth
session         include         postlogin
session         optional        pam_xauth.so

Informação adicional nº 2:

Depois de @Lambert comentar eu fiz isso:

No servidor nagios em / etc / hosts, adicionei o IP do servidor db2 No servidor db2 / etc / hosts eu adicionei nagios IP do servidor

Eu tentei mais duas coisas:

No servidor nagios :

Comando:

time ssh root@db2server /usr/bin/check_mk_agent

Resultado:

...

real    0m5.917s
user    0m0.025s
sys     0m0.028s

Comando:

time telnet db2server 6556

Resultado:

...

real    0m51.859s
user    0m0.005s
sys     0m0.014s

Eu corri isso várias vezes com os mesmos resultados ...

No db2server em / var / log / messages eu encontrei isto:

Oct 30 14:48:55 db2server su: (to db2inst1) root on pts/0 <- 1. command
Oct 30 14:50:59 db2server su: (to db2inst1) root on none  <- 2. command

Informação adicional nº 3:

Comando:

time ssh root@db2server telnet localhost 6556

Resultado:

real    0m7.510s
user    0m0.029s
sys     0m0.034s

Alguma idéia?

    
por Wolfy 29.10.2015 / 13:10

0 respostas