From 1746898cefcb17f58b5cf27b4dad3d28236f1152 Mon Sep 17 00:00:00 2001 From: Lennart Weller Date: Mon, 5 Sep 2016 10:27:21 +0200 Subject: Imported Upstream version 1.3.0+dfsg --- charts.d/Makefile.am | 4 +- charts.d/Makefile.in | 6 +- charts.d/README.md | 30 ++++ charts.d/airsearches.chart.sh | 91 ---------- charts.d/ap.chart.sh | 4 +- charts.d/apache.chart.sh | 62 ++++--- charts.d/cpu_apps.chart.sh | 2 +- charts.d/cpufreq.chart.sh | 4 +- charts.d/crsproxy.chart.sh | 151 ----------------- charts.d/example.chart.sh | 94 +++++++---- charts.d/exim.chart.sh | 52 ++++++ charts.d/hddtemp.chart.sh | 66 ++++++++ charts.d/load_average.chart.sh | 2 +- charts.d/mem_apps.chart.sh | 2 +- charts.d/mysql.chart.sh | 375 ++++++++++++++--------------------------- charts.d/nginx.chart.sh | 21 +-- charts.d/nut.chart.sh | 2 +- charts.d/opensips.chart.sh | 2 +- charts.d/phpfpm.chart.sh | 37 ++-- charts.d/postfix.chart.sh | 10 +- charts.d/sensors.chart.sh | 15 +- charts.d/squid.chart.sh | 20 +-- charts.d/tomcat.chart.sh | 38 +++-- 23 files changed, 473 insertions(+), 617 deletions(-) delete mode 100755 charts.d/airsearches.chart.sh delete mode 100755 charts.d/crsproxy.chart.sh create mode 100644 charts.d/exim.chart.sh create mode 100755 charts.d/hddtemp.chart.sh (limited to 'charts.d') diff --git a/charts.d/Makefile.am b/charts.d/Makefile.am index ad11e972a..e131d508f 100644 --- a/charts.d/Makefile.am +++ b/charts.d/Makefile.am @@ -4,13 +4,13 @@ MAINTAINERCLEANFILES= $(srcdir)/Makefile.in dist_charts_SCRIPTS = \ - airsearches.chart.sh \ ap.chart.sh \ apache.chart.sh \ cpu_apps.chart.sh \ cpufreq.chart.sh \ - crsproxy.chart.sh \ example.chart.sh \ + exim.chart.sh \ + hddtemp.chart.sh \ load_average.chart.sh \ mem_apps.chart.sh \ mysql.chart.sh \ diff --git a/charts.d/Makefile.in b/charts.d/Makefile.in index 3aff5a94c..5dfb3cc4b 100644 --- a/charts.d/Makefile.in +++ b/charts.d/Makefile.in @@ -263,6 +263,8 @@ pluginsdir = @pluginsdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +pythondir = @pythondir@ +registrydir = @registrydir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -279,13 +281,13 @@ webdir = @webdir@ # MAINTAINERCLEANFILES = $(srcdir)/Makefile.in dist_charts_SCRIPTS = \ - airsearches.chart.sh \ ap.chart.sh \ apache.chart.sh \ cpu_apps.chart.sh \ cpufreq.chart.sh \ - crsproxy.chart.sh \ example.chart.sh \ + exim.chart.sh \ + hddtemp.chart.sh \ load_average.chart.sh \ mem_apps.chart.sh \ mysql.chart.sh \ diff --git a/charts.d/README.md b/charts.d/README.md index fd66c0d6a..37c9d22ec 100644 --- a/charts.d/README.md +++ b/charts.d/README.md @@ -181,6 +181,36 @@ sensors_source_update=1 # how frequently to collect sensor data # the default is to collect it at every iteration of charts.d sensors_update_every= + +# array of sensors which are excluded +# the default is to include all +sensors_excluded=() +``` + +--- + +# hddtemp + +The plugin will collect temperatures from disks + +It will create one chart with all active disks + +1. **temperature in Celsius** + +### configuration + +hddtemp needs to be running in daemonized mode + +```sh +# host with daemonized hddtemp +hddtemp_host="localhost" + +# port on which hddtemp is showing data +hddtemp_port="7634" + +# array of included disks +# the default is to include all +hddtemp_disks=() ``` --- diff --git a/charts.d/airsearches.chart.sh b/charts.d/airsearches.chart.sh deleted file mode 100755 index 449b14255..000000000 --- a/charts.d/airsearches.chart.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/sh - -airsearches_url= -airsearches_cmds= -airsearches_update_every=15 - -airsearches_get() { - wget 2>/dev/null -O - "$airsearches_url" |\ - sed -e "s|
|\n|g" -e "s|: |=|g" -e "s| \+|_|g" -e "s/^/airsearches_/g" |\ - tr "[A-Z]\.\!@#\$%^&*()_+\-" "[a-z]_____________" |\ - egrep "^airsearches_[a-z0-9_]+=[0-9]+$" -} - -airsearches_check() { - # make sure we have all the commands we need - require_cmd wget || return 1 - - # make sure we are configured - if [ -z "$airsearches_url" ] - then - echo >&2 "$PROGRAM_NAME: airsearches: not configured. Please set airsearches_url='url' in $confd/airsearches.conf" - return 1 - fi - - # check once if the url works - wget 2>/dev/null -O /dev/null "$airsearches_url" - if [ ! $? -eq 0 ] - then - echo >&2 "$PROGRAM_NAME: airsearches: cannot fetch the url: $airsearches_url. Please set airsearches_url='url' in $confd/airsearches.conf" - return 1 - fi - - # if the admin did not give any commands - # find the available ones - if [ -z "$airsearches_cmds" ] - then - airsearches_cmds="$(airsearches_get | cut -d '=' -f 1 | sed "s/^airsearches_//g" | sort -u)" - echo - fi - - # did we find any commands? - if [ -z "$airsearches_cmds" ] - then - echo >&2 "$PROGRAM_NAME: airsearches: cannot find command list automatically. Please set airsearches_cmds='...' in $confd/airsearches.conf" - return 1 - fi - - # ok we can do it - return 0 -} - -airsearches_create() { - [ -z "$airsearches_cmds" ] && return 1 - - # create the charts - local x= - echo "CHART airsearches.affiliates '' 'Air Searches per affiliate' 'requests / min' airsearches '' stacked 20000 $airsearches_update_every" - for x in $airsearches_cmds - do - echo "DIMENSION $x '' incremental 60 1" - done - - return 0 -} - -airsearches_update() { - # the first argument to this function is the microseconds since last update - # pass this parameter to the BEGIN statement (see bellow). - - # do all the work to collect / calculate the values - # for each dimension - # remember: KEEP IT SIMPLE AND SHORT - - # get the values from airsearches - eval "$(airsearches_get)" - - # write the result of the work. - local x= - - echo "BEGIN airsearches.affiliates $1" - for x in $airsearches_cmds - do - eval "v=\$airsearches_$x" - echo "SET $x = $v" - done - echo "END" - - airsearches_dt=0 - - return 0 -} diff --git a/charts.d/ap.chart.sh b/charts.d/ap.chart.sh index aed51c1b6..7b4f690bb 100755 --- a/charts.d/ap.chart.sh +++ b/charts.d/ap.chart.sh @@ -1,4 +1,4 @@ -#!/bin/bash +# no need for shebang - this file is loaded from charts.d.plugin # _update_every is a special variable - it holds the number of seconds # between the calls of the _update() function @@ -11,6 +11,8 @@ export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin" # _check is called once, to find out if this chart should be enabled or not ap_check() { + require_cmd iw || return 1 + local ev=$(iw dev | awk ' BEGIN { i = ""; diff --git a/charts.d/apache.chart.sh b/charts.d/apache.chart.sh index dbf14a432..2d68d43b2 100755 --- a/charts.d/apache.chart.sh +++ b/charts.d/apache.chart.sh @@ -1,7 +1,8 @@ -#!/bin/bash +# no need for shebang - this file is loaded from charts.d.plugin # the URL to download apache status info apache_url="http://127.0.0.1:80/server-status?auto" +apache_curl_opts= # _update_every is a special variable - it holds the number of seconds # between the calls of the _update() function @@ -66,19 +67,14 @@ apache_detect() { # we will not check of the Conns* # keys, since these are apache 2.4 specific - if [ -z "${apache_key_accesses}" \ - -o -z "${apache_key_kbytes}" \ - -o -z "${apache_key_reqpersec}" \ - -o -z "${apache_key_bytespersec}" \ - -o -z "${apache_key_bytesperreq}" \ - -o -z "${apache_key_busyworkers}" \ - -o -z "${apache_key_idleworkers}" \ - -o -z "${apache_key_scoreboard}" \ - ] - then - echo >&2 "apache: Invalid response or missing keys from apache server: ${*}" - return 1 - fi + [ -z "${apache_key_accesses}" ] && echo >&2 "apache: missing 'Total Accesses' from apache server: ${*}" && return 1 + [ -z "${apache_key_kbytes}" ] && echo >&2 "apache: missing 'Total kBytes' from apache server: ${*}" && return 1 + [ -z "${apache_key_reqpersec}" ] && echo >&2 "apache: missing 'ReqPerSec' from apache server: ${*}" && return 1 + [ -z "${apache_key_bytespersec}" ] && echo >&2 "apache: missing 'BytesPerSec' from apache server: ${*}" && return 1 + [ -z "${apache_key_bytesperreq}" ] && echo >&2 "apache: missing 'BytesPerReq' from apache server: ${*}" && return 1 + [ -z "${apache_key_busyworkers}" ] && echo >&2 "apache: missing 'BusyWorkers' from apache server: ${*}" && return 1 + [ -z "${apache_key_idleworkers}" ] && echo >&2 "apache: missing 'IdleWorkers' from apache server: ${*}" && return 1 + [ -z "${apache_key_scoreboard}" ] && echo >&2 "apache: missing 'Scoreboard' from apache server: ${*}" && return 1 if [ ! -z "${apache_key_connstotal}" \ -a ! -z "${apache_key_connsasyncwriting}" \ @@ -87,6 +83,8 @@ apache_detect() { ] then apache_has_conns=1 + else + apache_has_conns=0 fi return 0 @@ -94,7 +92,7 @@ apache_detect() { apache_get() { local oIFS="${IFS}" ret - IFS=$':\n' apache_response=($(curl -Ss "${apache_url}")) + IFS=$':\n' apache_response=($(curl -Ss ${apache_curl_opts} "${apache_url}")) ret=$? IFS="${oIFS}" @@ -167,27 +165,27 @@ apache_check() { # _create is called once, to create the charts apache_create() { cat <&2 "charts.d: cpufreq: on file='$file', dir='$dir', cpu='$cpu', id='$id'" echo "DIMENSION $id '$id' absolute 1 1000" - echo >>$TMP_DIR/cpufreq.sh "printf \"SET $id = \"; cat $file " + echo >>$TMP_DIR/cpufreq.sh "echo \"SET $id = \"\$(< $file )" done echo >>$TMP_DIR/cpufreq.sh "echo END" diff --git a/charts.d/crsproxy.chart.sh b/charts.d/crsproxy.chart.sh deleted file mode 100755 index 9ad8b3382..000000000 --- a/charts.d/crsproxy.chart.sh +++ /dev/null @@ -1,151 +0,0 @@ -#!/bin/sh - -crsproxy_url= -crsproxy_cmds= -crsproxy_update_every=15 - -crsproxy_get() { - wget 2>/dev/null -O - "$crsproxy_url" |\ - sed \ - -e "s/ \+/ /g" \ - -e "s/\./_/g" \ - -e "s/ =/=/g" \ - -e "s/= /=/g" \ - -e "s/^/crsproxy_/g" |\ - egrep "^crsproxy_[a-zA-Z][a-zA-Z0-9_]*=[0-9]+$" -} - -crsproxy_check() { - # make sure we have all the commands we need - require_cmd wget || return 1 - - if [ -z "$crsproxy_url" ] - then - echo >&2 "$PROGRAM_NAME: crsproxy: not configured. Please set crsproxy_url='url' in $confd/crsproxy.conf" - return 1 - fi - - # check once if the url works - wget 2>/dev/null -O /dev/null "$crsproxy_url" - if [ ! $? -eq 0 ] - then - echo >&2 "$PROGRAM_NAME: crsproxy: cannot fetch the url: $crsproxy_url. Please set crsproxy_url='url' in $confd/crsproxy.conf" - return 1 - fi - - # if the user did not request specific commands - # find the commands available - if [ -z "$crsproxy_cmds" ] - then - crsproxy_cmds="$(crsproxy_get | cut -d '=' -f 1 | sed "s/^crsproxy_cmd_//g" | sort -u)" - fi - - # if no commands are available - if [ -z "$crsproxy_cmds" ] - then - echo >&2 "$PROGRAM_NAME: crsproxy: cannot find command list automatically. Please set crsproxy_cmds='...' in $confd/crsproxy.conf" - return 1 - fi - return 0 -} - -crsproxy_create() { - # create the charts - cat <&2 "example: you have to set example_magic_number=$example_magic_number in example.conf to start example chart." && return 1 + + # check that we can collect data + example_get || return 1 + return 0 } @@ -34,46 +91,21 @@ EOF } # _update is called continiously, to collect the values -example_last=0 -example_count=0 example_update() { - local value1 value2 value3 value4 mode - # the first argument to this function is the microseconds since last update # pass this parameter to the BEGIN statement (see bellow). - # do all the work to collect / calculate the values - # for each dimension - # remember: KEEP IT SIMPLE AND SHORT - - value1=$RANDOM - value2=$RANDOM - value3=$RANDOM - value4=$((8192 + (RANDOM * 16383 / 32767) )) - - if [ $example_count -gt 0 ] - then - example_count=$((example_count - 1)) - - [ $example_last -gt 16383 ] && value4=$((example_last + (RANDOM * ( (32767 - example_last) / 2) / 32767))) - [ $example_last -le 16383 ] && value4=$((example_last - (RANDOM * (example_last / 2) / 32767))) - else - example_count=$((1 + (RANDOM * 5 / 32767) )) - - [ $example_last -gt 16383 -a $value4 -gt 16383 ] && value4=$((value4 - 16383)) - [ $example_last -le 16383 -a $value4 -lt 16383 ] && value4=$((value4 + 16383)) - fi - example_last=$value4 + example_get || return 1 # write the result of the work. cat <&2 "example_count = $example_count value = $value4" diff --git a/charts.d/exim.chart.sh b/charts.d/exim.chart.sh new file mode 100644 index 000000000..c60ae9460 --- /dev/null +++ b/charts.d/exim.chart.sh @@ -0,0 +1,52 @@ +# no need for shebang - this file is loaded from charts.d.plugin + +exim_command= + +# how frequently to collect queue size +exim_update_every=5 + +exim_priority=60000 + +exim_check() { + if [ -z "$exim_command" -o ! -x "$exim_command" ] + then + local d= + for d in /sbin /usr/sbin /usr/local/sbin + do + if [ -x "$d/exim" ] + then + exim_command="$d/exim" + break + fi + done + fi + + if [ -z "$exim_command" -o ! -x "$exim_command" ] + then + echo >&2 "$PROGRAM_NAME: exim: cannot find exim executable. Please set 'exim_command=/path/to/exim' in $confd/exim.conf" + return 1 + fi + + if [ `$exim_command -bpc 2>&1 | grep -c denied` -ne 0 ] + then + echo >&2 "$PROGRAM_NAME: exim: permission denied. Please set 'queue_list_requires_admin = false' in your exim options file" + return 1 + fi + + return 0 +} + +exim_create() { +cat </dev/null && return 0 || return 1 +} + +# _create is called once, to create the charts +hddtemp_create() { + if [ ${#hddtemp_disks[@]} -eq 0 ]; then + local all + all=$(nc $hddtemp_host $hddtemp_port ) + unset hddtemp_disks + hddtemp_disks=( `grep -Po '/dev/[^|]+' <<< "$all" | cut -c 6-` ) + fi +# local disk_names +# disk_names=(`sed -e 's/||/\n/g;s/^|//' <<< "$all" | cut -d '|' -f2 | tr ' ' '_'`) + + echo "CHART hddtemp.temperature 'disks_temp' 'temperature' 'Celsius' 'Disks temperature' 'hddtemp.temp' line $((hddtemp_priority)) $hddtemp_update_every" + for i in `seq 0 $((${#hddtemp_disks[@]}-1))`; do +# echo "DIMENSION ${hddtemp_disks[i]} ${disk_names[i]} absolute 1 1" + echo "DIMENSION ${hddtemp_disks[$i]} '' absolute 1 1" + done + return 0 +} + +# _update is called continiously, to collect the values +hddtemp_last=0 +hddtemp_count=0 +hddtemp_update() { +# local all=( `nc $hddtemp_host $hddtemp_port | sed -e 's/||/\n/g;s/^|//' | cut -d '|' -f3` ) +# local all=( `nc $hddtemp_host $hddtemp_port | awk 'BEGIN { FS="|" };{i=4; while (i <= NF) {print $i+0;i+=5;};}'` ) + OLD_IFS=$IFS + set -f + IFS="|" all=( $(nc $hddtemp_host $hddtemp_port 2>/dev/null) ) + set +f + IFS=$OLD_IFS + + # check if there is some data + if [ -z "${all[3]}" ]; then + return 1 + fi + + # write the result of the work. + echo "BEGIN hddtemp.temperature $1" + end=${#hddtemp_disks[@]} + for ((i=0; i&2 "phpfpm: invalid response from phpfpm status server: ${phpfpm_response[*]}" @@ -61,7 +62,12 @@ phpfpm_get() { phpfpm_total_processes="${phpfpm_response[34]}" phpfpm_max_active_processes="${phpfpm_response[38]}" phpfpm_max_children_reached="${phpfpm_response[42]}" - phpfpm_slow_requests="${phpfpm_response[45]}" + if [ "${phpfpm_response[43]}" == "slow" ] + then + phpfpm_slow_requests="${phpfpm_response[45]}" + else + phpfpm_slow_requests="-1" + fi if [[ -z "${phpfpm_pool}" \ || -z "${phpfpm_start_time}" \ @@ -75,7 +81,6 @@ phpfpm_get() { || -z "${phpfpm_total_processes}" \ || -z "${phpfpm_max_active_processes}" \ || -z "${phpfpm_max_children_reached}" \ - || -z "${phpfpm_slow_requests}" \ ]] then echo >&2 "phpfpm: empty values got from phpfpm status server: ${phpfpm_response[*]}" @@ -94,7 +99,7 @@ phpfpm_check() { local m for m in "${!phpfpm_urls[@]}" do - phpfpm_get "${phpfpm_urls[$m]}" + phpfpm_get "${phpfpm_curl_opts[$m]}" "${phpfpm_urls[$m]}" if [ $? -ne 0 ]; then echo >&2 "phpfpm: cannot find status on URL '${phpfpm_url[$m]}'. Please set phpfpm_urls[$m]='http://localhost/status' in $confd/phpfpm.conf" unset phpfpm_urls[$m] @@ -130,8 +135,11 @@ DIMENSION requests '' incremental 1 1 CHART phpfpm_$m.performance '' "PHP-FPM Performance" "status" phpfpm phpfpm.performance line $((phpfpm_priority + 3)) $phpfpm_update_every DIMENSION reached 'max children reached' absolute 1 1 -DIMENSION slow 'slow requests' absolute 1 1 EOF + if [ $((phpfpm_slow_requests)) -ne -1 ] + then + echo "DIMENSION slow 'slow requests' absolute 1 1" + fi done return 0 @@ -149,7 +157,7 @@ phpfpm_update() { local m for m in "${!phpfpm_urls[@]}" do - phpfpm_get "${phpfpm_urls[$m]}" + phpfpm_get "${phpfpm_curl_opts[$m]}" "${phpfpm_urls[$m]}" if [ $? -ne 0 ]; then continue fi @@ -166,10 +174,17 @@ SET requests = $((phpfpm_accepted_conn)) END BEGIN phpfpm_$m.performance $1 SET reached = $((phpfpm_max_children_reached)) -SET slow = $((phpfpm_slow_requests)) -END EOF + if [ $((phpfpm_slow_requests)) -ne -1 ] + then + echo "SET slow = $((phpfpm_slow_requests))" + fi + echo "END" done return 0 } + +phpfpm_check +phpfpm_create +phpfpm_update diff --git a/charts.d/postfix.chart.sh b/charts.d/postfix.chart.sh index f4f710275..7f07a1868 100755 --- a/charts.d/postfix.chart.sh +++ b/charts.d/postfix.chart.sh @@ -1,4 +1,4 @@ -#!/bin/sh +# no need for shebang - this file is loaded from charts.d.plugin # the postqueue command # if empty, it will use the one found in the system path @@ -43,9 +43,9 @@ postfix_check() { postfix_create() { cat </dev/null } @@ -47,15 +49,20 @@ sensors_check() { sensors_check_files() { # we only need sensors that report a non-zero value + # also remove not needed sensors - local f= v= + local f= v= excluded= for f in $* do [ ! -f "$f" ] && continue + for ex in ${sensors_excluded[@]}; do + [[ $f =~ .*$ex$ ]] && excluded='1' && break + done - v="$( cat $f )" + [ "$excluded" != "1" ] && v="$( cat $f )" || v=0 v=$(( v + 1 - 1 )) [ $v -ne 0 ] && echo "$f" && continue + excluded= echo >&2 "$PROGRAM_NAME: sensors: $f gives zero values" done @@ -206,7 +213,7 @@ sensors_create() { fi echo "DIMENSION $fid '$labelname' $algorithm $multiplier $divisor" - echo >>$TMP_DIR/sensors.sh "printf \"SET $fid = \"; cat $file " + echo >>$TMP_DIR/sensors.sh "echo \"SET $fid = \"\$(< $file )" done echo >>$TMP_DIR/sensors.sh "echo END" diff --git a/charts.d/squid.chart.sh b/charts.d/squid.chart.sh index f6154b256..3e72ba6df 100755 --- a/charts.d/squid.chart.sh +++ b/charts.d/squid.chart.sh @@ -1,10 +1,10 @@ -#!/bin/sh +# no need for shebang - this file is loaded from charts.d.plugin squid_host= squid_port= squid_url= squid_timeout=2 -squid_update_every=5 +squid_update_every=2 squid_priority=60000 squid_get_stats_internal() { @@ -63,21 +63,21 @@ squid_check() { squid_create() { # create the charts cat <&2 "tomcat url is unset or set to the empty string" return 1 fi - if [ -z "${tomcatUser}" ]; then - echo >&2 "tomcat user is unset or set to the empty string" - return 1 + if [ -z "${tomcat_user}" ]; then + # check backwards compatibility + if [ -z "${tomcatUser}" ]; then + echo >&2 "tomcat user is unset or set to the empty string" + return 1 + else + tomcat_user="${tomcatUser}" + fi fi - if [ -z "${tomcatPassword}" ]; then - echo >&2 "tomcat password is unset or set to the empty string" - return 1 + if [ -z "${tomcat_password}" ]; then + # check backwards compatibility + if [ -z "${tomcatPassword}" ]; then + echo >&2 "tomcat password is unset or set to the empty string" + return 1 + else + tomcat_password="${tomcatPassword}" + fi fi # check if we can get to tomcat's status page @@ -62,13 +73,14 @@ tomcat_check() { } tomcat_get() { - # Collect tomcat values - mapfile -t lines < <(curl -u "$tomcatUser":"$tomcatPassword" -Ss "$tomcat_url" |\ + # collect tomcat values + tomcat_port="$(IFS=/ read -ra a <<< "$tomcat_url"; hostport=${a[2]}; echo "${hostport#*:}")" + mapfile -t lines < <(curl -u "$tomcat_user":"$tomcat_password" -Ss ${tomcat_curl_opts} "$tomcat_url" |\ xmlstarlet sel \ -t -m "/status/jvm/memory" -v @free \ - -n -m "/status/connector[@name='\"http-bio-8080\"']/threadInfo" -v @currentThreadCount \ + -n -m "/status/connector[@name='\"http-bio-$tomcat_port\"']/threadInfo" -v @currentThreadCount \ -n -v @currentThreadsBusy \ - -n -m "/status/connector[@name='\"http-bio-8080\"']/requestInfo" -v @requestCount \ + -n -m "/status/connector[@name='\"http-bio-$tomcat_port\"']/requestInfo" -v @requestCount \ -n -v @bytesSent -n -) tomcat_jvm_freememory="${lines[0]}" -- cgit v1.2.3