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.

Update 12/01/2018 – O script foi atualizado para coletar via JSON os nomes das instâncias.

 

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

InstanceDiscovery – Utilizado pelo Zabbix para montar o JSON .

 

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

# Utilize na variavel DOMAIN_HOST $3 para monitoração simples ou $(hostname) para monitoração via LLD.
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,//’
;;

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//’
;;

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,//’
;;

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//’
;;

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/,//’
;;

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
;;

InstanceDiscovery)
APPLIST=$($JCLI_HOME/jboss-cli.sh –connect –controller=${DOMAIN_HOST}:9999 –user=${JUSER_ADMIN} –password=${JUSER_PASS} –commands=”ls /host=${DOMAIN_HOST}/server”)

echo -e “{\n” # >> zabbix_lld_instancias.txt
echo -e “\t\”data\”:[\n” # >> zabbix_lld_instancias.txt

for INSTAPP in $APPLIST; do
echo -e “{\”{#INSTANCE}\”:\”`echo “$INSTAPP” | head -26 | tail -1`\”},” # >> zabbix_lld_instancias.txt
done
echo -e “{\”INST\”:\”instance\”}” # >> zabbix_lld_instancias.txt
printf “\n” # >> zabbix_lld_instancias.txt
printf “\t]\n” # >> zabbix_lld_instancias.txt
printf “}\n” # >> zabbix_lld_instancias.txt
;;

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