mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
- have some dirs
This commit is contained in:
parent
0b089ea777
commit
08346aac58
687 changed files with 0 additions and 0 deletions
140
plugins/tomcat/jvm-memory
Executable file
140
plugins/tomcat/jvm-memory
Executable file
|
@ -0,0 +1,140 @@
|
|||
#!/bin/bash -e
|
||||
#
|
||||
# Plugin munin affichant la mémoire utilisée, disponible et maximale de la JVM de tomcat.
|
||||
#
|
||||
## Dépendances
|
||||
# xmlstarlet
|
||||
# wget
|
||||
#
|
||||
## Configuration
|
||||
#
|
||||
# Pour pouvoir lire le mot de passe automatiquement, le script doit tourner
|
||||
# sous l'utilisateur tomcat55. Dans /etc/munin/plugin-conf.d/munin-node,
|
||||
# ajouter :
|
||||
#
|
||||
# [tomcat_*]
|
||||
# user tomcat55
|
||||
#
|
||||
# Autres options disponibles :
|
||||
#
|
||||
# env.status_url : URL vers la page « status » en XML du manager
|
||||
# env.http_username : Utilisateur HTTP
|
||||
# env.users_filename : Chemin vers le fichier tomcat-users.xml
|
||||
#
|
||||
##
|
||||
|
||||
TOMCAT_USERS=${users_filename:-'/etc/tomcat5.5/tomcat-users.xml'}
|
||||
USER=${http_username:-'munin'}
|
||||
URLS=( ${status_url:-'http://localhost/manager/status?XML=true https://localhost/manager/status?XML=true http://localhost/manager/status?XML=true'} )
|
||||
|
||||
WARNING=80
|
||||
CRITICAL=90
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////////
|
||||
# Affiche un message d'erreur et termine le script en renvoyant le code d'erreur 1
|
||||
#
|
||||
# @param Message à afficher
|
||||
#/////////////////////////////////////////////////////////////////////////////////
|
||||
die(){
|
||||
echo "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
#////////////////////////////////////////////////////////////////////////////
|
||||
# Récupère le mot de passe de l'utilisateur $1 contenu dans le fichier XML $2
|
||||
#
|
||||
# @param in $1 Nom de l'utilisateur
|
||||
# @param in $2 Fichier XML contenant les utilisateurs Tomcat
|
||||
# @stdout Mot de passe de l'utilisateur
|
||||
#////////////////////////////////////////////////////////////////////////////
|
||||
getPassword(){
|
||||
local PASSWORD=$(xmlstarlet sel -t -m "tomcat-users/user[@username='$1']" -v "@password" "$2" 2> /dev/null)
|
||||
[[ -z $PASSWORD ]] && die "Aucun mot de passe trouvé dans le fichier « $2 » pour le compte « $1 » !"
|
||||
echo $PASSWORD
|
||||
}
|
||||
|
||||
#//////////////////////////////////////////////////////
|
||||
# Récupère la page en XML contenant le statut de la JVM
|
||||
#
|
||||
# @param in $1 Login pour accéder à la page de statut
|
||||
# @param in $2 Mot de passe
|
||||
# @param in $3..$n URL à tester
|
||||
#//////////////////////////////////////////////////////
|
||||
getStatusPage(){
|
||||
local USER="$1"
|
||||
local PASSWORD="$2"
|
||||
while [[ $# -gt 2 ]]; do
|
||||
local STATUS=$(wget -O- -q --no-check-certificate --http-user "$USER" --http-password "$PASSWORD" "$3")
|
||||
[[ -n $STATUS ]] && {
|
||||
echo $STATUS
|
||||
return
|
||||
}
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
#///////////////////////////////////////
|
||||
# Affiche la mémoire maximale allouable
|
||||
#
|
||||
# @param in $1 Page de statut de la JVM
|
||||
# @stdout Mémoire maximale allouable
|
||||
#///////////////////////////////////////
|
||||
getMaxMemory(){
|
||||
local MAX_MEM=$(xmlstarlet sel -t -m "status/jvm/memory" -v "@max" <<< "$1" 2> /dev/null)
|
||||
[[ -z $MAX_MEM ]] && die "Impossible de trouver la mémoire maximale allouable !"
|
||||
echo $MAX_MEM
|
||||
}
|
||||
|
||||
#///////////////////////////////////////////////////////////////////////////
|
||||
# Affiche la configuration du plugin
|
||||
#
|
||||
# @param in $1 Mémoire maximale allouable
|
||||
# @param in $2 Pourcentage à utiliser pour définir les « warnings » [0-100]
|
||||
# @param in $3 Pourcentage à utiliser pour définir les « criticals » [0-100]
|
||||
# @stdout Configuration du plugin
|
||||
#///////////////////////////////////////////////////////////////////////////
|
||||
showConfig(){
|
||||
local TMP=$(echo -e {max,total,free}.{'type GAUGE','min 0','draw AREA'}"\n")
|
||||
echo "graph_category Tomcat
|
||||
graph_title Tomcat JVM
|
||||
graph_info Mémoire de la JVM Tomcat
|
||||
graph_vlabel Mémoire
|
||||
$TMP
|
||||
max.label max
|
||||
total.label total
|
||||
free.label free
|
||||
total.warning $(($1 * $2 / 100))
|
||||
total.critical $(($1 * $3 / 100))
|
||||
" | sed -r 's/^\s+//'
|
||||
exit 0
|
||||
}
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////////////////
|
||||
# Affiche les données sur la mémoire utilisée, disponible et maximale de la JVM de tomcat.
|
||||
#
|
||||
# @param in $1 Page de statut de la JVM
|
||||
# @stdout Données sur la mémoire utilisée, disponible et maximale de la JVM de tomcat
|
||||
#/////////////////////////////////////////////////////////////////////////////////////////
|
||||
showData(){
|
||||
xmlstarlet sel -t -m "status/jvm/memory" \
|
||||
-o "max.value " -v "@max" -n \
|
||||
-o "total.value " -v "@total" -n \
|
||||
-o "free.value " -v "@free" \
|
||||
<<< "$1" 2> /dev/null
|
||||
}
|
||||
|
||||
# Le fichier $TOMCAT_USERS n'est pas lisible => on quitte
|
||||
[[ ! -r $TOMCAT_USERS ]] && die "Impossible de lire le fichier $TOMCAT_USERS !"
|
||||
|
||||
# On récupère le mot de passe de l'utilisateur $USER
|
||||
PASSWORD=$(getPassword $USER $TOMCAT_USERS)
|
||||
|
||||
# On récupère la page de statut de la JVM de tomcat
|
||||
STATUS_PAGE=$(getStatusPage $USER $PASSWORD $URLS)
|
||||
[[ -z $STATUS_PAGE ]] && die 'Erreur : impossible de récupérer la page de statut de Tomcat !' ;
|
||||
|
||||
# On affiche la configuration du plugin
|
||||
[[ $1 == 'config' ]] && showConfig $(getMaxMemory "$STATUS_PAGE") $WARNING $CRITICAL
|
||||
|
||||
# On affiche les données du plugin
|
||||
showData "$STATUS_PAGE"
|
140
plugins/tomcat/jvm-thread-info
Executable file
140
plugins/tomcat/jvm-thread-info
Executable file
|
@ -0,0 +1,140 @@
|
|||
#!/bin/bash -e
|
||||
#
|
||||
# Plugin munin affichant le nombre de threads occupées, disponibles et maximales de la JVM de tomcat.
|
||||
#
|
||||
## Dépendances
|
||||
# xmlstarlet
|
||||
# wget
|
||||
#
|
||||
## Configuration
|
||||
#
|
||||
# Pour pouvoir lire le mot de passe automatiquement, le script doit tourner
|
||||
# sous l'utilisateur tomcat55. Dans /etc/munin/plugin-conf.d/munin-node,
|
||||
# ajouter :
|
||||
#
|
||||
# [tomcat_*]
|
||||
# user tomcat55
|
||||
#
|
||||
# Autres options disponibles :
|
||||
#
|
||||
# env.status_url : URL vers la page « status » en XML du manager
|
||||
# env.http_username : Utilisateur HTTP
|
||||
# env.users_filename : Chemin vers le fichier tomcat-users.xml
|
||||
#
|
||||
##
|
||||
|
||||
TOMCAT_USERS=${users_filename:-'/etc/tomcat5.5/tomcat-users.xml'}
|
||||
USER=${http_username:-'munin'}
|
||||
URLS=( ${status_url:-'http://localhost/manager/status?XML=true https://localhost/manager/status?XML=true http://localhost/manager/status?XML=true'} )
|
||||
|
||||
WARNING=80
|
||||
CRITICAL=90
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////////
|
||||
# Affiche un message d'erreur et termine le script en renvoyant le code d'erreur 1
|
||||
#
|
||||
# @param Message à afficher
|
||||
#/////////////////////////////////////////////////////////////////////////////////
|
||||
die(){
|
||||
echo "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
#////////////////////////////////////////////////////////////////////////////
|
||||
# Récupère le mot de passe de l'utilisateur $1 contenu dans le fichier XML $2
|
||||
#
|
||||
# @param in $1 Nom de l'utilisateur
|
||||
# @param in $2 Fichier XML contenant les utilisateurs Tomcat
|
||||
# @stdout Mot de passe de l'utilisateur
|
||||
#////////////////////////////////////////////////////////////////////////////
|
||||
getPassword(){
|
||||
local PASSWORD=$(xmlstarlet sel -t -m "tomcat-users/user[@username='$1']" -v "@password" "$2" 2> /dev/null)
|
||||
[[ -z $PASSWORD ]] && die "Aucun mot de passe trouvé dans le fichier « $2 » pour le compte « $1 » !"
|
||||
echo $PASSWORD
|
||||
}
|
||||
|
||||
#//////////////////////////////////////////////////////
|
||||
# Récupère la page en XML contenant le statut de la JVM
|
||||
#
|
||||
# @param in $1 Login pour accéder à la page de statut
|
||||
# @param in $2 Mot de passe
|
||||
# @param in $3..$n URL à tester
|
||||
#//////////////////////////////////////////////////////
|
||||
getStatusPage(){
|
||||
local USER="$1"
|
||||
local PASSWORD="$2"
|
||||
while [[ $# -gt 2 ]]; do
|
||||
local STATUS=$(wget -O- -q --no-check-certificate --http-user "$USER" --http-password "$PASSWORD" "$3")
|
||||
[[ -n $STATUS ]] && {
|
||||
echo $STATUS
|
||||
return
|
||||
}
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
#///////////////////////////////////////
|
||||
# Affiche le nombre maximal de threads
|
||||
#
|
||||
# @param in $1 Page de statut de la JVM
|
||||
# @stdout Nombre maximal de threads
|
||||
#///////////////////////////////////////
|
||||
getMaxThreads(){
|
||||
local MAX_THREADS=$(xmlstarlet sel -t -m "status/connector/threadInfo" -v "@maxThreads" <<< "$1" 2> /dev/null)
|
||||
[[ -z $MAX_THREADS ]] && die "Impossible de trouver le nombre maximal de threads !"
|
||||
echo $MAX_THREADS
|
||||
}
|
||||
|
||||
#///////////////////////////////////////////////////////////////////////////
|
||||
# Affiche la configuration du plugin
|
||||
#
|
||||
# @param in $1 Nombre maximal de threads
|
||||
# @param in $2 Pourcentage à utiliser pour définir les « warnings » [0-100]
|
||||
# @param in $3 Pourcentage à utiliser pour définir les « criticals » [0-100]
|
||||
# @stdout Configuration du plugin
|
||||
#///////////////////////////////////////////////////////////////////////////
|
||||
showConfig(){
|
||||
local TMP=$(echo -e {maxThreads,currentThreadCount,currentThreadsBusy}.{'type GAUGE','min 0','draw AREA'}"\n")
|
||||
echo "graph_category Tomcat
|
||||
graph_title Tomcat Threads
|
||||
graph_info nombre de threads occupées, disponibles et maximales de la JVM de tomcat
|
||||
graph_vlabel Threads
|
||||
$TMP
|
||||
maxThreads.label maxThreads
|
||||
currentThreadCount.label currentThreadCount
|
||||
currentThreadsBusy.label currentThreadsBusy
|
||||
currentThreadCount.warning $(($1 * $2 / 100))
|
||||
currentThreadCount.critical $(($1 * $3 / 100))
|
||||
" | sed -r 's/^\s+//'
|
||||
exit 0
|
||||
}
|
||||
|
||||
#////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
# Affiche les données sur le nombre de threads occupées, disponibles et maximales de la JVM de tomcat
|
||||
#
|
||||
# @param in $1 Page de statut de la JVM
|
||||
# @stdout Données sur le nombre de threads occupées, disponibles et maximales de la JVM de tomcat
|
||||
#////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
showData(){
|
||||
xmlstarlet sel -t -m "status/connector/threadInfo" \
|
||||
-o "currentThreadCount.value " -v "@currentThreadCount" -n \
|
||||
-o "currentThreadsBusy.value " -v "@currentThreadsBusy" -n \
|
||||
-o "maxThreads.value " -v "@maxThreads" \
|
||||
<<< "$1" #2> /dev/null
|
||||
}
|
||||
|
||||
# Le fichier $TOMCAT_USERS n'est pas lisible => on quitte
|
||||
[[ ! -r $TOMCAT_USERS ]] && die "Impossible de lire le fichier $TOMCAT_USERS !"
|
||||
|
||||
# On récupère le mot de passe de l'utilisateur $USER
|
||||
PASSWORD=$(getPassword $USER $TOMCAT_USERS)
|
||||
|
||||
# On récupère la page de statut de la JVM de tomcat
|
||||
STATUS_PAGE=$(getStatusPage $USER $PASSWORD $URLS)
|
||||
[[ -z $STATUS_PAGE ]] && die 'Erreur : impossible de récupérer la page de statut de Tomcat !' ;
|
||||
|
||||
# On affiche la configuration du plugin
|
||||
[[ $1 == 'config' ]] && showConfig $(getMaxThreads "$STATUS_PAGE") $WARNING $CRITICAL
|
||||
|
||||
# On affiche les données du plugin
|
||||
showData "$STATUS_PAGE"
|
283
plugins/tomcat/tomcat
Executable file
283
plugins/tomcat/tomcat
Executable file
|
@ -0,0 +1,283 @@
|
|||
#!/usr/bin/ruby
|
||||
#
|
||||
# Plugin to monitor the Tomcat servers.
|
||||
#
|
||||
# Original Author: Rune Nordboe Skillingstad <runesk@linpro.no>
|
||||
# Rewrite: laxis <laxis@magex.hu> 2008.05
|
||||
#
|
||||
# Requirements:
|
||||
# - Needs access to http://<user>:<password>@localhost:8080/manager/status?XML=true (or modify the
|
||||
# address for another host). A munin-user in $CATALINA_HOME/conf/tomcat-users.xml
|
||||
# should be set up for this to work.
|
||||
# - libxml-ruby
|
||||
#
|
||||
# Install:
|
||||
# - copy script to /etc/munin
|
||||
# - cd /etc/munin
|
||||
# - ./tomcat install
|
||||
#
|
||||
# Tip: To see if it's already set up correctly, just run this plugin
|
||||
# with the parameter "autoconf". If you get a "yes", everything should
|
||||
# work like a charm already.
|
||||
#
|
||||
# tomcat-users.xml example:
|
||||
# <user username="munin" password="<set this>" roles="standard,manager"/>
|
||||
#
|
||||
# Parameters supported:
|
||||
#
|
||||
# config
|
||||
# autoconf
|
||||
# install
|
||||
#
|
||||
# Configurable variables
|
||||
#
|
||||
# host - Destination host
|
||||
# port - HTTP port numbers
|
||||
# timeout - Connection timeout
|
||||
# request - Override default status-url
|
||||
# user - Manager username
|
||||
# password - Manager password
|
||||
# connector - Connector to query, defaults to "http-".$PORT
|
||||
#
|
||||
# Sample config:
|
||||
# [tomcat_*]
|
||||
# env.host 127.0.0.1
|
||||
# env.port 8080
|
||||
# env.request /manager/status?XML=true
|
||||
# env.user munin
|
||||
# env.password pass
|
||||
# env.timeout 30
|
||||
# env.connector jk-8009
|
||||
#
|
||||
# Magic markers:
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
|
||||
require 'net/http'
|
||||
require 'xml/libxml'
|
||||
|
||||
@host = ENV.member?('host') ? ENV['host']: "127.0.0.1"
|
||||
@port = ENV.member?('port') ? ENV['port']: 8080
|
||||
@request = ENV.member?('request') ? ENV['request']: "/manager/status?XML=true"
|
||||
@user = ENV.member?('user') ? ENV['user']: "munin"
|
||||
@password = ENV.member?('password') ? ENV['password']: "munin"
|
||||
@timeout = ENV.member?('timeout') ? ENV['timeout']: 30
|
||||
@connector = ENV.member?('connector') ? ENV['connector']: "http-#{@port}";
|
||||
|
||||
# hash
|
||||
w = {
|
||||
"jvmMemory" => { "max" => "U",
|
||||
"total" => "U",
|
||||
"used" => "U" },
|
||||
"threadInfo" => { "maxThreads" => "U",
|
||||
"currentThreadCount" => "U",
|
||||
"currentThreadsBusy" => "U" },
|
||||
"requestMaxTime" => { "maxTime" => "U" },
|
||||
"requestTime" => { "avgTime" => "U" },
|
||||
"requestCount" => { "requestCount" => "U",
|
||||
"errorCount" => "U" },
|
||||
"requestBytes" => { "bytesReceived" => "U",
|
||||
"bytesSent" => "U" }
|
||||
}
|
||||
|
||||
# http request
|
||||
def getstat()
|
||||
Net::HTTP.start(@host, @port) do |http|
|
||||
http.open_timeout = @timeout
|
||||
req = Net::HTTP::Get.new(@request)
|
||||
req.basic_auth @user, @password
|
||||
response = http.request(req)
|
||||
response.value()
|
||||
return response.body
|
||||
end rescue begin
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def autoconf()
|
||||
begin
|
||||
if getstat()
|
||||
puts "yes"
|
||||
return 0
|
||||
end
|
||||
rescue
|
||||
puts "no (#{$!})"
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
if ARGV[0] == "autoconf"
|
||||
exit autoconf()
|
||||
end
|
||||
|
||||
if ARGV[0] == "install"
|
||||
exit if autoconf() != 0
|
||||
Dir["plugins/tomcat*"].each { |f|
|
||||
print "removing #{f}\n"
|
||||
File.unlink f
|
||||
}
|
||||
w.each { |k, v|
|
||||
print "installing plugins/tomcat_#{k}\n"
|
||||
File.symlink "../tomcat", "plugins/tomcat_#{k}" if ! FileTest.symlink? "plugins/tomcat_#{k}"
|
||||
}
|
||||
exit
|
||||
end
|
||||
|
||||
# open stderr
|
||||
e = IO.new(2, "w")
|
||||
|
||||
mode = $0.gsub /.*\/tomcat_/, ""
|
||||
if mode =~ /tomcat/ then
|
||||
e.puts "Invalid mode"
|
||||
exit 1
|
||||
end
|
||||
|
||||
# munin config request
|
||||
if ARGV[0] == "config"
|
||||
puts "graph_title tomcat_#{mode}"
|
||||
puts "graph_args -l 0 --base 1000"
|
||||
#print "graph_order "
|
||||
#w[mode].each { |k, v|
|
||||
#print "#{k} "
|
||||
#}
|
||||
#puts
|
||||
case mode
|
||||
when "jvmMemory"
|
||||
puts "graph_category tomcat"
|
||||
puts "graph_vlabel bytes"
|
||||
puts "graph_order max total used"
|
||||
w[mode].each { |k, v|
|
||||
puts "#{k}.label #{k}"
|
||||
puts "#{k}.type GAUGE"
|
||||
puts "#{k}.min 0"
|
||||
puts "#{k}.draw AREA"
|
||||
}
|
||||
when "requestCount"
|
||||
puts "graph_category tomcat"
|
||||
puts "graph_order requestCount errorCount"
|
||||
puts "graph_vlabel Request / sec"
|
||||
w[mode].each { |k, v|
|
||||
puts "#{k}.label #{k}"
|
||||
puts "#{k}.type COUNTER"
|
||||
puts "#{k}.min 0"
|
||||
puts "#{k}.draw AREA" if k == "requestCount"
|
||||
puts "#{k}.draw LINE2" if k != "requestCount"
|
||||
}
|
||||
when "requestBytes"
|
||||
puts "graph_category tomcat"
|
||||
puts "graph_vlabel bytes in (-) / out (+) per ${graph_period}"
|
||||
w[mode].each { |k, v|
|
||||
puts "#{k}.label #{k}"
|
||||
puts "#{k}.type DERIVE"
|
||||
puts "#{k}.min 0"
|
||||
puts "#{k}.graph no" if k == "bytesReceived"
|
||||
puts "#{k}.negative bytesReceived" if k == "bytesSent"
|
||||
|
||||
}
|
||||
when "requestMaxTime"
|
||||
puts "graph_category tomcat"
|
||||
puts "graph_vlabel sec"
|
||||
w[mode].each { |k, v|
|
||||
puts "#{k}.label #{k}"
|
||||
puts "#{k}.type GAUGE"
|
||||
puts "#{k}.min 0"
|
||||
puts "#{k}.draw LINE2"
|
||||
}
|
||||
when "requestTime"
|
||||
puts "graph_category tomcat"
|
||||
puts "graph_vlabel Average RequestTime (sec) / Request"
|
||||
w[mode].each { |k, v|
|
||||
puts "#{k}.label #{k}"
|
||||
puts "#{k}.type GAUGE"
|
||||
puts "#{k}.min 0"
|
||||
puts "#{k}.draw LINE2"
|
||||
}
|
||||
when "threadInfo"
|
||||
puts "graph_category tomcat"
|
||||
puts "graph_order maxThreads currentThreadCount currentThreadsBusy"
|
||||
w[mode].each { |k, v|
|
||||
puts "#{k}.label #{k}"
|
||||
puts "#{k}.type GAUGE"
|
||||
puts "#{k}.min 0"
|
||||
puts "#{k}.draw AREA"
|
||||
}
|
||||
end
|
||||
exit 0
|
||||
end
|
||||
|
||||
|
||||
# XML parsolasa
|
||||
begin
|
||||
parser = XML::Parser.string(getstat())
|
||||
doc = parser.parse
|
||||
end rescue begin
|
||||
e.puts "Parse error"
|
||||
exit 1
|
||||
end
|
||||
|
||||
# root element kivalasztasa
|
||||
root = doc.root
|
||||
if root.name != "status"
|
||||
e.puts "Invalid XML"
|
||||
exit 1
|
||||
end
|
||||
|
||||
# copy jvm memory datas to hash
|
||||
node = doc.find('//status/jvm/memory').first
|
||||
w["jvmMemory"]["used"] = node.property("total").to_i - node.property("free").to_i
|
||||
w["jvmMemory"]["total"] = node.property("total")
|
||||
w["jvmMemory"]["max"] = node.property("max")
|
||||
|
||||
# copy connector datas to hash
|
||||
doc.find('//status/connector').each do |node|
|
||||
if node.property("name") == @connector
|
||||
node.each do |child|
|
||||
if child.name == "threadInfo"
|
||||
w["threadInfo"]["maxThreads"] = child.property("maxThreads")
|
||||
w["threadInfo"]["currentThreadCount"] = child.property("currentThreadCount")
|
||||
w["threadInfo"]["currentThreadsBusy"] = child.property("currentThreadsBusy")
|
||||
end
|
||||
if child.name == "requestInfo"
|
||||
w["requestMaxTime"]["maxTime"] = child.property("maxTime")
|
||||
w["requestTime"]["avgTime"] = sprintf "%.2f", (child.property("processingTime").to_f / child.property("requestCount").to_f / 1000)
|
||||
w["requestCount"]["requestCount"] = child.property("requestCount")
|
||||
w["requestCount"]["errorCount"] = child.property("errorCount")
|
||||
w["requestBytes"]["bytesReceived"] = child.property("bytesReceived")
|
||||
w["requestBytes"]["bytesSent"] = child.property("bytesSent")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# print result
|
||||
w[mode].each do |k, v|
|
||||
printf "#{k}.value %s\n", v
|
||||
end
|
||||
|
||||
# XML Output:
|
||||
#<?xml version="1.0" encoding="utf-8"?>
|
||||
#<?xml-stylesheet type="text/xsl" href="/manager/xform.xsl" ?>
|
||||
#<status>
|
||||
# <jvm>
|
||||
# <memory free='110552760' total='257425408' max='1034027008'/>
|
||||
# </jvm>
|
||||
# <connector name='http-8080'>
|
||||
# <threadInfo maxThreads="40" currentThreadCount="1" currentThreadsBusy="1" />
|
||||
# <requestInfo maxTime="14" processingTime="2619" requestCount="1911" errorCount="5" bytesReceived="0" bytesSent="3294996" />
|
||||
# <workers>
|
||||
# <worker stage="S" requestProcessingTime="0" requestBytesSent="0" requestBytesReceived="0" remoteAddr="127.0.0.1" virtualHost="localhost" method="GET" currentUri="/manager/status" currentQueryString="XML=true" protocol="HTTP/1.0" />
|
||||
# </workers>
|
||||
# </connector>
|
||||
# <connector name='jk-8009'>
|
||||
# <threadInfo maxThreads="200" currentThreadCount="8" currentThreadsBusy="6" />
|
||||
# <requestInfo maxTime="36961" processingTime="273750" requestCount="5485" errorCount="43" bytesReceived="0" bytesSent="57138822" />
|
||||
# <workers>
|
||||
# <worker stage="K" requestProcessingTime="22683456" requestBytesSent="0" requestBytesReceived="0" remoteAddr="86.101.240.226" virtualHost="?" method="?" currentUri="?" currentQueryString="?" protocol="?" />
|
||||
# <worker stage="K" requestProcessingTime="35807" requestBytesSent="0" requestBytesReceived="0" remoteAddr="217.20.130.27" virtualHost="?" method="?" currentUri="?" currentQueryString="?" protocol="?" />
|
||||
# <worker stage="K" requestProcessingTime="32247045" requestBytesSent="0" requestBytesReceived="0" remoteAddr="89.147.76.234" virtualHost="?" method="?" currentUri="?" currentQueryString="?" protocol="?" />
|
||||
# <worker stage="K" requestProcessingTime="95860" requestBytesSent="0" requestBytesReceived="0" remoteAddr="217.20.130.27" virtualHost="?" method="?" currentUri="?" currentQueryString="?" protocol="?" />
|
||||
# <worker stage="K" requestProcessingTime="155940" requestBytesSent="0" requestBytesReceived="0" remoteAddr="217.20.130.27" virtualHost="?" method="?" currentUri="?" currentQueryString="?" protocol="?" />
|
||||
# </workers>
|
||||
# </connector>
|
||||
#</status>
|
162
plugins/tomcat/tomcat_
Normal file
162
plugins/tomcat/tomcat_
Normal file
|
@ -0,0 +1,162 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
'''
|
||||
Wildcard plugin to monitor Apache Tomcat connectors and/or JBoss' JVM.
|
||||
|
||||
To use this plugin:
|
||||
1. Set site, username and password variables before you do anything else.
|
||||
2. Run plugin with suggest argument to get all the available options.
|
||||
3. Copy plugin to munin plugins folder and make it executable.
|
||||
4. Create symbolic links based on output from step 2. Examples:
|
||||
tomcat_jvm - monitor JVM usage
|
||||
tomcat_ajp-127.0.0.1-8009 - monitor ajp connector
|
||||
tomcat_http-127.0.0.1-8080 - monitor http connector
|
||||
5. Check links by running them.
|
||||
6. Restart munin-node.
|
||||
7. Enjoy graphs.
|
||||
|
||||
Munin's muni-node-configure can be used to do steps 2, 3 and 4 for you.
|
||||
|
||||
Example of using munin-node configuration to configure the plugin:
|
||||
|
||||
[tomcat_jvm]
|
||||
env.site http://127.0.0.1:8080/status?XML=true
|
||||
env.username admin
|
||||
env.password admin
|
||||
|
||||
Magic markers
|
||||
#%# capabilities=autoconf suggest
|
||||
#%# family=auto
|
||||
'''
|
||||
|
||||
import urllib2
|
||||
import base64
|
||||
import xml.dom.minidom
|
||||
import sys, os, re
|
||||
|
||||
# Configure me ...
|
||||
site = 'http://127.0.0.1:8080/status?XML=true'
|
||||
username = 'admin'
|
||||
password = 'admin'
|
||||
|
||||
# Or do it with the environment variables in munin-node configuration.
|
||||
if os.environ.has_key('site'):
|
||||
site = os.environ['site']
|
||||
|
||||
if os.environ.has_key('username'):
|
||||
username = os.environ['username']
|
||||
|
||||
if os.environ.has_key('password'):
|
||||
password = os.environ['password']
|
||||
|
||||
# Timeout for urlopen.
|
||||
required_version = (2, 6)
|
||||
current_version = sys.version_info[:2]
|
||||
|
||||
connector_attrs = (
|
||||
'maxThreads',
|
||||
'minSpareThreads',
|
||||
'maxSpareThreads',
|
||||
'currentThreadCount',
|
||||
'currentThreadBusy'
|
||||
)
|
||||
|
||||
jvm_attrs = (
|
||||
'free',
|
||||
'total',
|
||||
'max'
|
||||
)
|
||||
|
||||
ctx = sys.argv[0].rstrip('.py').split('_')[1]
|
||||
|
||||
def site_auth():
|
||||
# Prepare base64 encoded string
|
||||
enc_string = base64.encodestring('%s:%s' % (username, password))
|
||||
|
||||
# Prepare request and add headers
|
||||
request = urllib2.Request(url=site, headers={"Authorization": "Basic %s" % enc_string})
|
||||
try:
|
||||
if current_version >= required_version:
|
||||
return (0, urllib2.urlopen(request, timeout=5).read())
|
||||
else:
|
||||
return (0, urllib2.urlopen(request).read())
|
||||
except:
|
||||
return (-1, "Failed to access %s" % site)
|
||||
|
||||
def jvm_data(data):
|
||||
document = data.documentElement
|
||||
for sub_document in document.childNodes:
|
||||
if sub_document.nodeName == 'jvm':
|
||||
node = sub_document.firstChild
|
||||
for attr in jvm_attrs:
|
||||
print "%s.value %s" % (attr, int(node.getAttribute(attr)))
|
||||
|
||||
def connector_data(data, connector_name):
|
||||
document = data.documentElement
|
||||
for sub_document in document.childNodes:
|
||||
if sub_document.nodeName == 'connector' and sub_document.getAttribute('name') == connector_name:
|
||||
node = sub_document.firstChild
|
||||
for attr in connector_attrs:
|
||||
try:
|
||||
print "%s.value %s" % (attr, int(node.getAttribute(attr)))
|
||||
except:
|
||||
pass
|
||||
|
||||
def suggest(data):
|
||||
document = data.documentElement
|
||||
for sub_document in document.childNodes:
|
||||
if sub_document.nodeName == 'jvm':
|
||||
print "jvm"
|
||||
elif sub_document.nodeName == 'connector':
|
||||
print sub_document.getAttribute('name')
|
||||
else:
|
||||
pass
|
||||
|
||||
def configure():
|
||||
print "graph_title Tomcat status - %s" % ctx
|
||||
print "graph_category tomcat"
|
||||
if ctx == 'jvm':
|
||||
print "graph_args --base 1024 -l 0"
|
||||
print "graph_scale yes"
|
||||
print "graph_vlabel JVM in bytes"
|
||||
print "graph_info This graph shows JVM usage of Tomcat."
|
||||
for attr in jvm_attrs:
|
||||
print "%s.label %s" % (attr, attr)
|
||||
print "%s.type GAUGE" % (attr)
|
||||
print "%s.min 0" % (attr)
|
||||
print "%s.draw LINE1" % (attr)
|
||||
print "%s.info %s %s in bytes" % (attr, ctx, attr)
|
||||
else:
|
||||
print "graph_args --base 1000 -l 0"
|
||||
print "graph_scale no"
|
||||
print "graph_vlabel Connector threads"
|
||||
print "graph_info This graph shows connector threads for %s" % ctx
|
||||
for attr in connector_attrs:
|
||||
print "%s.label %s" % (attr, attr)
|
||||
print "%s.type GAUGE" % (attr)
|
||||
print "%s.min 0" % (attr)
|
||||
print "%s.draw LINE1" % (attr)
|
||||
print "%s.info %s %s count" % (attr, ctx, attr)
|
||||
|
||||
if __name__ == "__main__":
|
||||
status, data = site_auth()
|
||||
if len(sys.argv) == 2 and sys.argv[1] == 'config':
|
||||
configure()
|
||||
sys.exit(0)
|
||||
|
||||
elif len(sys.argv) == 2 and sys.argv[1] == 'suggest':
|
||||
suggest(xml.dom.minidom.parseString(data))
|
||||
sys.exit(0)
|
||||
|
||||
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
||||
if status == 0:
|
||||
print "yes"
|
||||
else:
|
||||
print "no (%s)" % data
|
||||
sys.exit(0)
|
||||
|
||||
else:
|
||||
if ctx == 'jvm':
|
||||
jvm_data(xml.dom.minidom.parseString(data))
|
||||
else:
|
||||
connector_data(xml.dom.minidom.parseString(data), ctx)
|
46
plugins/tomcat/tomcatthreads
Executable file
46
plugins/tomcat/tomcatthreads
Executable file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env groovy
|
||||
/*
|
||||
* Reports tomcat thread status from the tomcat manager application
|
||||
*
|
||||
* Stian B. Lindhom <stian@lindhom.no> 2010
|
||||
*/
|
||||
|
||||
def username = ''
|
||||
def password = ''
|
||||
def addr = 'http://localhost:8080/manager/status?XML=true'
|
||||
def connector = 'http-8080'
|
||||
|
||||
def authString = (username + ":" + password).getBytes().encodeBase64()
|
||||
def conn = addr.toURL().openConnection()
|
||||
|
||||
def maxthreads
|
||||
def threadsBusy
|
||||
def threadCount
|
||||
conn.setRequestProperty("Authorization", "Basic ${authString}")
|
||||
if (conn.responseCode == 200) {
|
||||
def doc = new XmlParser().parseText(conn.content.text)
|
||||
httpConnector = doc.connector.findAll{ it.'@name'.contains(connector) }[0]
|
||||
maxthreads = Integer.parseInt(httpConnector.threadInfo.'@maxThreads'.text())
|
||||
threadsBusy = Integer.parseInt(httpConnector.threadInfo.'@currentThreadsBusy'.text())
|
||||
threadCount = Integer.parseInt(httpConnector.threadInfo.'@currentThreadCount'.text())
|
||||
}
|
||||
|
||||
if (args && args[0] == 'config') {
|
||||
warningThreshold = (Integer) (maxthreads - (maxthreads* 0.2))
|
||||
criticalThreshold = (Integer) (maxthreads - (maxthreads * 0.05))
|
||||
|
||||
println """graph_category Tomcat
|
||||
graph_title Tomcat threads
|
||||
graph_info The number of busy threads describes how many HTTP requests are being processed at the moment
|
||||
graph_vlabel Threads
|
||||
currentThreadCount.label currentThreadCount
|
||||
currentThreadsBusy.label currentThreadsBusy
|
||||
maxThreads.label maxThreads
|
||||
currentThreadCount.warning ${warningThreshold}
|
||||
currentThreadCount.critical ${criticalThreshold}"""
|
||||
return;
|
||||
}
|
||||
|
||||
println """currentThreadCount.value ${threadCount}
|
||||
currentThreadsBusy.value ${threadsBusy}
|
||||
maxThreads.value ${maxthreads}"""
|
Loading…
Add table
Add a link
Reference in a new issue