root / plugins / network / netatalk3 @ 8589c6df
Historique | Voir | Annoter | Télécharger (4,27 ko)
| 1 |
#!/bin/bash - |
|---|---|
| 2 |
# |
| 3 |
#### Abstract ################################################################ |
| 4 |
# |
| 5 |
# Munin contributed plugin to measure open, locked and files being hold by |
| 6 |
# Netatalk version 3.*; |
| 7 |
# |
| 8 |
#### Author ################################################################## |
| 9 |
# |
| 10 |
# Otavio Fernandes <otaviof@gmail.com> |
| 11 |
# Wednesday, 01/01/2014 |
| 12 |
# |
| 13 |
|
| 14 |
#### Functions ############################################################### |
| 15 |
# |
| 16 |
|
| 17 |
function afpd_full_path () {
|
| 18 |
echo $(which afpd |head -n 1) |
| 19 |
} |
| 20 |
|
| 21 |
function afp_related_file_exists () {
|
| 22 |
local afp_file_path=$1 |
| 23 |
if [ -z "$afp_file_path" -o ! -f "$afp_file_path" ]; then |
| 24 |
echo "ERROR: AFP related file not found: \"${afpd_bin_path}\";" >&2
|
| 25 |
exit 1 |
| 26 |
fi |
| 27 |
} |
| 28 |
|
| 29 |
function is_netatalk_version_3 () {
|
| 30 |
local afpd_bin_path=$1 |
| 31 |
version_string="$(${afpd_bin_path} -version |head -n1 |grep '^afpd' |cut -d' ' -f2)"
|
| 32 |
if [[ $version_string != 3\.* ]]; then |
| 33 |
cat <<EOM >&2 |
| 34 |
ERROR: Netatalk is not version 3. |
| 35 |
Binary: ${afpd_bin_path};
|
| 36 |
Version: ${version_string};
|
| 37 |
EOM |
| 38 |
exit 1 |
| 39 |
fi |
| 40 |
} |
| 41 |
|
| 42 |
function count_running_procs () {
|
| 43 |
local afpd_bin_path=$1 |
| 44 |
echo $(ps ax --no-headers -o command |grep "^${afpd_bin_path}" |wc -l)
|
| 45 |
} |
| 46 |
|
| 47 |
function count_connected_users () {
|
| 48 |
local afpd_bin_path=$1 |
| 49 |
afpd_procs=$(ps anx --no-headers -o uid,command |grep -E "\w+\d+*\s${afpd_bin_path}" |wc -l)
|
| 50 |
# one of those processes will be always from root user, so it's not being |
| 51 |
# used to externaly connect volumes, therefor being disconsider. |
| 52 |
echo $(echo "${afpd_procs} - 1" |bc)
|
| 53 |
} |
| 54 |
|
| 55 |
function base_lsof () {
|
| 56 |
local afpd_bin_path=$1 |
| 57 |
process_name="$(basename ${afpd_bin_path})"
|
| 58 |
excluded_fds="^DEL,^err,^jld,^ltx,^Mxx,^m86,^mem,^mmap,^pd,^rtd,^tr,^txt,^v86" |
| 59 |
echo "lsof -a -c ${process_name} -d ${excluded_fds}"
|
| 60 |
} |
| 61 |
|
| 62 |
function count_locked_files () {
|
| 63 |
local afpd_bin_path=$1 |
| 64 |
cmd_suffix="$(base_lsof "${afpd_bin_path}")"
|
| 65 |
echo "$(${cmd_suffix} -F -l |grep '^l[rRwWu]' |wc -l)"
|
| 66 |
} |
| 67 |
|
| 68 |
function probe_afp_conf_file () {
|
| 69 |
local afpd_bin_path=$1 |
| 70 |
echo "$(${afpd_bin_path} -version 2>&1 |grep -E '^\s+afp.conf\:' |awk '{print $2}')"
|
| 71 |
} |
| 72 |
|
| 73 |
function count_open_shares () {
|
| 74 |
local afpd_bin_path=$1 |
| 75 |
local afp_conf_path=$2 |
| 76 |
|
| 77 |
mounted=0 |
| 78 |
declare -a shares=($(grep '^path.*\=' ${afp_conf_path} |awk -F '=' '{print $2}' |sed -E 's/^\s+//g'))
|
| 79 |
if [ ! -z "$shares" ]; then |
| 80 |
# narrowing lsof results to only list configured mount directories |
| 81 |
cmd_lookup_prefix=$(echo ${shares[@]} |tr " " "|")
|
| 82 |
cmd_suffix="$(base_lsof "${afpd_bin_path}")"
|
| 83 |
mounted=$(${cmd_suffix} -F n |grep '^n' |egrep "(${cmd_lookup_prefix})" |wc -l)
|
| 84 |
fi |
| 85 |
echo $mounted |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
#### Main #################################################################### |
| 90 |
# For all routines, holds the entry points dealing with the informed parameter |
| 91 |
# or lack of it, meaning just print out collected data. |
| 92 |
# |
| 93 |
|
| 94 |
case "$1" in |
| 95 |
config) |
| 96 |
# printing configuration for this plugin's produced data |
| 97 |
cat <<EOM |
| 98 |
graph_title Netatalk v3 Status |
| 99 |
graph_title Netatalk status |
| 100 |
graph_args --logarithmic --lower-limit 0.1 |
| 101 |
graph_vlabel Number |
| 102 |
graph_category fs |
| 103 |
proc.label Running processes |
| 104 |
proc.info Running AFPd processes |
| 105 |
proc.min 0 |
| 106 |
user.label Connected users |
| 107 |
user.info Connected users |
| 108 |
user.min 0 |
| 109 |
lock.label Locked files |
| 110 |
lock.info AFPd locked files |
| 111 |
lock.min 0 |
| 112 |
share.label Open shares |
| 113 |
share.info Netatalk open shares |
| 114 |
share.min 0 |
| 115 |
EOM |
| 116 |
exit 0 |
| 117 |
;; |
| 118 |
*) |
| 119 |
#### Boilerplates #################################################### |
| 120 |
# Locating AFP related files: |
| 121 |
# * Binary: Using the first result of "which" command; |
| 122 |
# * Config: Using "afpd" with parameters to pring configuration file |
| 123 |
# location; |
| 124 |
# |
| 125 |
|
| 126 |
AFPD_PATH="$(afpd_full_path)" |
| 127 |
afp_related_file_exists "${AFPD_PATH}"
|
| 128 |
is_netatalk_version_3 "${AFPD_PATH}"
|
| 129 |
|
| 130 |
AFP_CONF_PATH="$(probe_afp_conf_file "${AFPD_PATH}")"
|
| 131 |
afp_related_file_exists "${AFP_CONF_PATH}"
|
| 132 |
|
| 133 |
#### Collecting Metrics ############################################## |
| 134 |
# |
| 135 |
echo "proc.value" $(count_running_procs "${AFPD_PATH}")
|
| 136 |
echo "user.value" $(count_connected_users "${AFPD_PATH}")
|
| 137 |
echo "lock.value" $(count_locked_files "${AFPD_PATH}")
|
| 138 |
echo "share.value" $(count_open_shares "${AFPD_PATH}" "${AFP_CONF_PATH}")
|
| 139 |
|
| 140 |
exit 0 |
| 141 |
;; |
| 142 |
esac |
| 143 |
|
| 144 |
# EOF |
