Jboss : Script de Monitoração via CLI

Neste post será apresentado um script criado baseado no post de monitoração via cli , este script também pode ser utilizado para servidores monitoração conseguir coletar dados do Jboss.

Jboss Cli : Monitoração da JVM

 

O script abaixo é necessário passar via argumento o host e a instância.

 

./jboss-mon.sh <OPTION> <HOST> <INSTANCE>

 

./jboss-mon.sh HeapUsed HOST01 INSTANCE01

 

Opções de execução do script :

HeapUsed – Heap Utilizada
HeapMax – Heap Máxima da JVM
PermgenUsed – Permgen Utilizado
PermgenMax – Permgen Máximo da JVM
ThreadsCount – Contagem de threads utilizadas por instância
InstanceList – Lista as instâncias no servidor

Caso haja dúvidas de quais instâncias existem no servidor utilizamos o exemplo abaixo para listar :

root@server# ./jboss-mon.sh InstanceList HOST01;
INSTANCE01 INSTANCE02 

 

#!/bin/bash

### VARIABLES ### 
JCLI_HOME="/opt/jboss/bin"
JUSER_ADMIN=juser
JUSER_PASS=jpass
DOMAIN_HOST=$3
MGMT_PORT=9990
INSTANCE=$2

case "$1" in

HeapUsed)
$JCLI_HOME/jboss-cli.sh --connect --controller=${DOMAIN_HOST}:9999 --user=${JUSER_ADMIN} --password=${JUSER_PASS}  --commands="/host=${DOMAIN_HOST}/server=${INSTANCE}/core-service=platform-mbean/type=memory:read-attribute(name=heap-memory-usage)" |  grep "used" | awk '{print $3}' | sed 's/L,//'
#echo $HeapUsed
;;

 HeapMax)
$JCLI_HOME/jboss-cli.sh --connect --controller=${DOMAIN_HOST}:9999 --user=${JUSER_ADMIN} --password=${JUSER_PASS} --controller=${DOMAIN_HOST}:9999 --connect --commands="/host=${DOMAIN_HOST}/server=${INSTANCE}/core-service=platform-mbean/type=memory:read-attribute(name=heap-memory-usage)" |  grep "max" | awk '{print $3}' | sed 's/L//'
#echo $HeapMax
;;

HeapFree)
HeapMaxVar=`$JCLI_HOME/jboss-cli.sh --connect --controller=${DOMAIN_HOST}:9999 --user=${JUSER_ADMIN} --password=${JUSER_PASS} --controller=${DOMAIN_HOST}:9999 --connect --commands="/host=${DOMAIN_HOST}/server=${INSTANCE}/core-service=platform-mbean/type=memory:read-attribute(name=heap-memory-usage)" |  grep "max" | awk '{print $3}' | sed 's/L//'`

HeapUsedVar=`$JCLI_HOME/jboss-cli.sh --connect --controller=${DOMAIN_HOST}:9999 --user=${JUSER_ADMIN} --password=${JUSER_PASS}  --commands="/host=${DOMAIN_HOST}/server=${INSTANCE}/core-service=platform-mbean/type=memory:read-attribute(name=heap-memory-usage)" |  grep "used" | awk '{print $3}' | sed 's/L,//'`

HeapFreeVar=$((HeapMaxVar - HeapUsedVar))

echo $HeapFreeVar

;;

PermgenUsed)
$JCLI_HOME/jboss-cli.sh  --connect --controller=${DOMAIN_HOST}:9999 --user=${JUSER_ADMIN} --password=${JUSER_PASS}  --commands="/host=${DOMAIN_HOST}/server=${INSTANCE}/core-service=platform-mbean/type=memory:read-attribute(name=non-heap-memory-usage)" |  grep "used" | awk '{print $3}' | sed 's/L,//'
#echo $PermgenUsed
;;

PermgenMax)
$JCLI_HOME/jboss-cli.sh  --connect --controller=${DOMAIN_HOST}:9999 --user=${JUSER_ADMIN} --password=${JUSER_PASS}  --commands="/host=${DOMAIN_HOST}/server=${INSTANCE}/core-service=platform-mbean/type=memory:read-attribute(name=non-heap-memory-usage)" |  grep "max" | awk '{print $3}' | sed 's/L//'
#echo $PermgenMax
;;

PermgenFree)
PermgenMaxVar=`$JCLI_HOME/jboss-cli.sh  --connect --controller=${DOMAIN_HOST}:9999 --user=${JUSER_ADMIN} --password=${JUSER_PASS}  --commands="/host=${DOMAIN_HOST}/server=${INSTANCE}/core-service=platform-mbean/type=memory:read-attribute(name=non-heap-memory-usage)" |  grep "max" | awk '{print $3}' | sed 's/L//'`

PermgenUsedVar=`$JCLI_HOME/jboss-cli.sh  --connect --controller=${DOMAIN_HOST}:9999 --user=${JUSER_ADMIN} --password=${JUSER_PASS}  --commands="/host=${DOMAIN_HOST}/server=${INSTANCE}/core-service=platform-mbean/type=memory:read-attribute(name=non-heap-memory-usage)" |  grep "used" | awk '{print $3}' | sed 's/L,//'`

PermgenFreeVar=$((PermgenMaxVar - PermgenUsedVar))
echo $PermgenFreeVar
;;


ThreadsCount)
$JCLI_HOME/jboss-cli.sh  --connect --controller=${DOMAIN_HOST}:9999 --user=${JUSER_ADMIN} --password=${JUSER_PASS}  --commands="/host=${DOMAIN_HOST}/server=${INSTANCE}/core-service=platform-mbean/type=threading:read-resource(include-runtime=true)" | grep '"thread-count"' | awk '{print $3}' | sed 's/,//'
#echo $ThreadsCount
;;


InstanceList)
$JCLI_HOME/jboss-cli.sh --connect --controller=${DOMAIN_HOST}:9999 --user=${JUSER_ADMIN} --password=${JUSER_PASS}  --commands="ls /host=${DOMAIN_HOST}/server"
echo $InstanceList
;;

Status)
$JCLI_HOME/jboss-cli.sh  --connect --controller=${DOMAIN_HOST}:9999 --user=${JUSER_ADMIN} --password=${JUSER_PASS}  --commands="/host=${DOMAIN_HOST}/server=${INSTANCE}:read-attribute(name=server-state)" | grep "running" | awk '{print $3}'
;;



 *)
   echo "Exemplo de utilizacao : ./jboss-mon <OPTION> <HOST> <INSTANCE>"
   echo "Utilize as opcoes (HeapUsed | HeapMax | PermgenUsed | PermegenMax | PermgenFree | InstanceList | ThreadsCount)"
  esac