From b1869d13cd03a795da7e57fb5835e6691fbeaf30 Mon Sep 17 00:00:00 2001 From: David Bjornsson Date: Thu, 23 Feb 2012 19:58:17 +0000 Subject: [PATCH 01/15] Adding a new ZFS statistic plugin --- plugins/zfs/zfs_stats_ | 254 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100755 plugins/zfs/zfs_stats_ diff --git a/plugins/zfs/zfs_stats_ b/plugins/zfs/zfs_stats_ new file mode 100755 index 00000000..d218e46d --- /dev/null +++ b/plugins/zfs/zfs_stats_ @@ -0,0 +1,254 @@ +#!/bin/sh +# ZFS statistics for FreeBSD +# Author: David Bjornsson +# +# Description: +# This is a rewrite of the zfs-stats-for-freebsd +# scripts by patpro. Rather then pulling the +# information from the zfs-stats utility, it +# pulls it straight from sysctl. +# +# Tested on FreeBSD 9.0-RELEASE +# +# Usage: zfs_stats_FUNCTION +# +# Available functions: +# efficiency - ARC efficiency +# cachehitlist - Cache hit by cache list +# cachehitdtype - Cache hit by data type +# dmuprefetch - DMU prefetch +# utilization - ARC size breakdown +# +#%# family=auto + +FUNCTION=$(basename $0 | cut -d_ -f3) +PAGESIZE=`/sbin/sysctl -n vm.stats.vm.v_page_size` +MEMSIZE=`/sbin/sysctl -n vm.stats.vm.v_page_count` +MEMMAX=`echo 'scale=2;' $PAGESIZE*$MEMSIZE | /usr/bin/bc -q` +BC='/usr/bin/bc -q' +SYS='/sbin/sysctl -n' + +# +# Sysctl macros +# + +ARC_HITS=`$SYS kstat.zfs.misc.arcstats.hits` +ARC_MISSES=`$SYS kstat.zfs.misc.arcstats.misses` + +DEMAND_DATA_HITS=`$SYS kstat.zfs.misc.arcstats.demand_data_hits` +DEMAND_DATA_MISSES=`$SYS kstat.zfs.misc.arcstats.demand_data_misses` +DEMAND_METADATA_HITS=`$SYS kstat.zfs.misc.arcstats.demand_metadata_hits` +DEMAND_METADATA_MISSES=`$SYS kstat.zfs.misc.arcstats.demand_metadata_misses` + +MFU_GHOST_HITS=`$SYS kstat.zfs.misc.arcstats.mfu_ghost_hits` +MFU_HITS=`$SYS kstat.zfs.misc.arcstats.mfu_hits` +MRU_GHOST_HITS=`$SYS kstat.zfs.misc.arcstats.mru_ghost_hits` +MRU_HITS=`$SYS kstat.zfs.misc.arcstats.mru_hits` + +PREFETCH_DATA_HITS=`$SYS kstat.zfs.misc.arcstats.prefetch_data_hits` +PREFETCH_DATA_MISSES=`$SYS kstat.zfs.misc.arcstats.prefetch_data_misses` +PREFETCH_METADATA_HITS=`$SYS kstat.zfs.misc.arcstats.prefetch_metadata_hits` +PREFETCH_METADATA_MISSES=`$SYS kstat.zfs.misc.arcstats.prefetch_metadata_misses` + +DMU_HITS=`$SYS kstat.zfs.misc.zfetchstats.hits` +DMU_MISSES=`$SYS kstat.zfs.misc.zfetchstats.misses` + +SIZE=`$SYS kstat.zfs.misc.arcstats.size` +MRU_SIZE=`$SYS kstat.zfs.misc.arcstats.p` +MAX_SIZE=`$SYS kstat.zfs.misc.arcstats.c_max` +MIN_SIZE=`$SYS kstat.zfs.misc.arcstats.c_min` +TARGET_SIZE=`$SYS kstat.zfs.misc.arcstats.c` + + +# +# Calculation macros +# + +ANON_HITS=`echo "$ARC_HITS-($MFU_HITS+$MRU_HITS+$MFU_GHOST_HITS+$MRU_GHOST_HITS)" | $BC` +ARC_ACCESSES_TOTAL=`echo "$ARC_HITS+$ARC_MISSES" | $BC` +DEMAND_DATA_TOTAL=`echo "$DEMAND_DATA_HITS+$DEMAND_DATA_MISSES" | $BC` +PREFETCH_DATA_TOTAL=`echo "$PREFETCH_DATA_HITS+$PREFETCH_DATA_MISSES" | $BC` +REAL_HITS=`echo "$MFU_HITS+$MRU_HITS" | $BC` + +CACHE_HIT_RATIO_PERC=`echo "scale=2 ; (100*$ARC_HITS/$ARC_ACCESSES_TOTAL)" | $BC` +CACHE_MISS_RATIO_PERC=`echo "scale=2 ; (100*$ARC_MISSES/$ARC_ACCESSES_TOTAL)" | $BC` +ACTUAL_HIT_RATIO_PERC=`echo "scale=2 ; (100*$REAL_HITS/$ARC_ACCESSES_TOTAL)" | $BC` +DATA_DEMAND_EFFICIENCY_PERC=`echo "scale=2 ; (100*$DEMAND_DATA_HITS/$DEMAND_DATA_TOTAL)" | $BC` +DATA_PREFETCH_EFFICENCY_PERC=`echo "scale=2 ; (100*$PREFETCH_DATA_HITS/$PREFETCH_DATA_TOTAL)" | $BC` + +ANONYMOUSLY_USED_PERC=`echo "scale=2 ; (100*$ANON_HITS/$ARC_HITS)" | $BC` +MOST_RECENTLY_USED_PERC=`echo "scale=2 ; (100*$MRU_HITS/$ARC_HITS)" | $BC` +MOST_FREQUENTLY_USED_PERC=`echo "scale=2 ; (100*$MFU_HITS/$ARC_HITS)" | $BC` +MOST_RECENTLY_USED_GHOST_PERC=`echo "scale=2 ; (100*$MRU_GHOST_HITS/$ARC_HITS)" | $BC` +MOST_FREQUENTLY_USED_GHOST_PERC=`echo "scale=2 ; (100*$MFU_GHOST_HITS/$ARC_HITS)" | $BC` + +DEMAND_DATA_HIT_PERC=`echo "scale=2 ; (100*$DEMAND_DATA_HITS/$ARC_HITS)" | $BC` +DEMAND_DATA_MISS_PERC=`echo "scale=2 ; (100*$DEMAND_DATA_MISSES/$ARC_HITS)" | $BC` +PREFETCH_DATA_HIT_PERC=`echo "scale=2 ; (100*$PREFETCH_DATA_HITS/$ARC_HITS)" | $BC` +PREFETCH_DATA_MISS_PERC=`echo "scale=2 ; (100*$PREFETCH_DATA_MISSES/$ARC_HITS)" | $BC` +DEMAND_METADATA_HIT_PERC=`echo "scale=2 ; (100*$DEMAND_METADATA_HITS/$ARC_HITS)" | $BC` +DEMAND_METADATA_MISS_PERC=`echo "scale=2 ; (100*$DEMAND_METADATA_MISSES/$ARC_HITS)" | $BC` +PREFETCH_METADATA_HIT_PERC=`echo "scale=2 ; (100*$PREFETCH_METADATA_HITS/$ARC_HITS)" | $BC` +PREFETCH_METADATA_MISSES_PERC=`echo "scale=2 ; (100*$PREFETCH_METADATA_MISSES/$ARC_HITS)" | $BC` + +DMU_TOTAL=`echo "$DMU_HITS+$DMU_MISSES" | $BC` +DMU_HITS_PERC=`echo "scale=2 ; (100*$DMU_HITS/$DMU_TOTAL)" | $BC` +DMU_MISSES_PERC=`echo "scale=2 ; (100*$DMU_MISSES/$DMU_TOTAL)" | $BC` + +if [ $SIZE -gt $TARGET_SIZE ]; then + MFU_SIZE=`echo "$SIZE-$MRU_SIZE" | $BC` +else + MFU_SIZE=`echo "$TARGET_SIZE-$MRU_SIZE" | $BC` +fi + + +efficiency() { + + if [ "$1" = "config" ]; then + echo 'graph_title ZFS ARC Efficiency' + echo 'graph_args -u 100' + echo 'graph_vlabel %' + echo 'graph_category ZFS' + echo 'graph_info This graph shows the ARC Efficiency' + + echo 'hits.label Cache Hit Ratio' + echo 'misses.label Cache Miss Ratio' + echo 'actual_hits.label Actual Hit Ratio' + echo 'data_demand_efficiency.label Data Demand Efficiency' + echo 'data_prefetch_efficiency.label Data Prefetch Efficiency' + + exit 0 + else + echo 'hits.value ' $CACHE_HIT_RATIO_PERC + echo 'misses.value ' $CACHE_MISS_RATIO_PERC + echo 'actual_hits.value ' $ACTUAL_HIT_RATIO_PERC + echo 'data_demand_efficiency.value ' $DATA_DEMAND_EFFICIENCY_PERC + echo 'data_prefetch_efficiency.value ' $DATA_PREFETCH_EFFICENCY_PERC + fi +} + +cachehitlist() { + if [ "$1" = "config" ]; then + echo 'graph_title ZFS ARC Efficiency: Cache hits by cache list' + echo 'graph_args -u 100' + echo 'graph_vlabel %' + echo 'graph_category ZFS' + echo 'graph_info This graph shows the ARC Efficiency' + + echo 'cache_list_anon.label Anonymously Used' + echo 'cache_list_most_rec.label Most Recently Used' + echo 'cache_list_most_freq.label Most Frequently Used' + echo 'cache_list_most_rec_ghost.label Most Recently Used Ghost' + echo 'cache_list_most_freq_ghost.label Most Frequently Used Ghost' + + exit 0 + else + echo 'cache_list_anon.value ' $ANONYMOUSLY_USED_PERC + echo 'cache_list_most_rec.value ' $MOST_RECENTLY_USED_PERC + echo 'cache_list_most_freq.value ' $MOST_FREQUENTLY_USED_PERC + echo 'cache_list_most_rec_ghost.value ' $MOST_RECENTLY_USED_GHOST_PERC + echo 'cache_list_most_freq_ghost.value ' $MOST_FREQUENTLY_USED_GHOST_PERC + fi +} + +cachehitdtype() { + if [ "$1" = "config" ]; then + echo 'graph_title ZFS ARC Efficiency: Cache hits by data type' + echo 'graph_args -u 100' + echo 'graph_vlabel %' + echo 'graph_category ZFS' + echo 'graph_info This graph shows the ARC Efficiency' + + echo 'data_type_demand_hits.label Demand Data Hit Ratio' + echo 'data_type_demand_misses.label Demand Data Miss Ratio' + echo 'data_type_prefetch_hits.label Prefetch Data Hit Ratio' + echo 'data_type_prefetch_misses.label Prefetch Data Miss Ratio' + echo 'data_type_demand_metadata_hits.label Demand Metadata Hit Ratio' + echo 'data_type_demand_metadata_misses.label Demand Metadata Miss Ratio' + echo 'data_type_prefetch_metadata_hits.label Prefetch Metadata Hit Ratio' + echo 'data_type_prefetch_metadata_misses.label Prefetch Metadata Miss Ratio' + + exit 0 + else + echo 'data_type_demand_hits.value ' $DEMAND_DATA_HIT_PERC + echo 'data_type_demand_misses.value ' $DEMAND_DATA_MISS_PERC + echo 'data_type_prefetch_hits.value ' $PREFETCH_DATA_HIT_PERC + echo 'data_type_prefetch_misses.value ' $PREFETCH_DATA_MISS_PERC + echo 'data_type_demand_metadata_hits.value ' $DEMAND_METADATA_HIT_PERC + echo 'data_type_demand_metadata_misses.value ' $DEMAND_METADATA_MISS_PERC + echo 'data_type_prefetch_metadata_hits.value ' $PREFETCH_METADATA_HIT_PERC + echo 'data_type_prefetch_metadata_misses.value ' $PREFETCH_METADATA_MISSES_PERC + fi +} + +dmuprefetch() { + + if [ "$1" = "config" ]; then + echo 'graph_title ZFS DMU prefetch stats' + echo 'graph_args -u 100' + echo 'graph_vlabel %' + echo 'graph_category ZFS' + echo 'graph_info This graph shows the DMU prefetch stats' + + echo 'hits.label Hit percentage' + echo 'misses.label Miss percentage' + + exit 0 + else + echo 'hits.value ' $DMU_HITS_PERC + echo 'misses.value ' $DMU_MISSES_PERC + fi +} + +utilization() { + + if [ "$1" = "config" ]; then + echo 'graph_title ZFS ARC Size' + echo 'graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit '$MEMMAX + echo 'graph_vlabel Size in MB' + echo 'graph_category ZFS' + echo 'graph_info This graph shows the ARC Size utilization' + + echo 'max_size.label Maximum Size' + echo 'max_size.draw AREA' + echo 'target_size.label Target Size' + echo 'target_size.draw AREA' + echo 'size.label Size' + echo 'size.draw AREA' + echo 'recently_size.label Recently Used Cache Size' + echo 'recently_size.draw AREA' + echo 'frequently_size.label Frequently Used Cache Size' + echo 'frequently_size.draw AREA' + echo 'min_size.label Minimum Size' + echo 'min_size.draw AREA' + + exit 0 + else + echo 'max_size.value ' $MAX_SIZE + echo 'target_size.value ' $TARGET_SIZE + echo 'size.value ' $SIZE + echo 'recently_size.value ' $MRU_SIZE + echo 'frequently_size.value ' $MFU_SIZE + echo 'min_size.value ' $MIN_SIZE + fi +} + +[ "$1" = "config" ] && echo "graph_category zfs" + +case "$FUNCTION" in + efficiency) + efficiency $1 + ;; + cachehitlist) + cachehitlist $1 + ;; + cachehitdtype) + cachehitdtype $1 + ;; + dmuprefetch) + dmuprefetch $1 + ;; + utilization) + utilization $1 + ;; +esac From 281bd584c43a02c42958ef775270cbb3274caa1d Mon Sep 17 00:00:00 2001 From: Matt West Date: Thu, 23 Feb 2012 18:24:31 -0800 Subject: [PATCH 02/15] Fixing Evictions Stats Key Collision --- plugins/memcached/memcached_multi_ | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/memcached/memcached_multi_ b/plugins/memcached/memcached_multi_ index e574861f..3df9f8bb 100755 --- a/plugins/memcached/memcached_multi_ +++ b/plugins/memcached/memcached_multi_ @@ -810,6 +810,9 @@ sub fetch_stats { while (my $line = <$s>) { if ($line =~ /STAT\s(.+?)\s(.*)/) { my ($skey,$svalue) = ($1,$2); + if ($skey eq 'evictions') { + $skey = 'evictions_active'; + } $stats{$skey} = $svalue; } last if $line =~ /^END/; From 8315962063d51a9cbc7eb01f5232b79e7209baa8 Mon Sep 17 00:00:00 2001 From: dabb Date: Fri, 24 Feb 2012 11:51:03 +0000 Subject: [PATCH 03/15] Fixing typos in data type calculations --- plugins/zfs/zfs_stats_ | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/zfs/zfs_stats_ b/plugins/zfs/zfs_stats_ index d218e46d..bef05684 100755 --- a/plugins/zfs/zfs_stats_ +++ b/plugins/zfs/zfs_stats_ @@ -83,13 +83,13 @@ MOST_RECENTLY_USED_GHOST_PERC=`echo "scale=2 ; (100*$MRU_GHOST_HITS/$ARC_HITS)" MOST_FREQUENTLY_USED_GHOST_PERC=`echo "scale=2 ; (100*$MFU_GHOST_HITS/$ARC_HITS)" | $BC` DEMAND_DATA_HIT_PERC=`echo "scale=2 ; (100*$DEMAND_DATA_HITS/$ARC_HITS)" | $BC` -DEMAND_DATA_MISS_PERC=`echo "scale=2 ; (100*$DEMAND_DATA_MISSES/$ARC_HITS)" | $BC` +DEMAND_DATA_MISS_PERC=`echo "scale=2 ; (100*$DEMAND_DATA_MISSES/$ARC_MISSES)" | $BC` PREFETCH_DATA_HIT_PERC=`echo "scale=2 ; (100*$PREFETCH_DATA_HITS/$ARC_HITS)" | $BC` -PREFETCH_DATA_MISS_PERC=`echo "scale=2 ; (100*$PREFETCH_DATA_MISSES/$ARC_HITS)" | $BC` +PREFETCH_DATA_MISS_PERC=`echo "scale=2 ; (100*$PREFETCH_DATA_MISSES/$ARC_MISSES)" | $BC` DEMAND_METADATA_HIT_PERC=`echo "scale=2 ; (100*$DEMAND_METADATA_HITS/$ARC_HITS)" | $BC` -DEMAND_METADATA_MISS_PERC=`echo "scale=2 ; (100*$DEMAND_METADATA_MISSES/$ARC_HITS)" | $BC` +DEMAND_METADATA_MISS_PERC=`echo "scale=2 ; (100*$DEMAND_METADATA_MISSES/$ARC_MISSES)" | $BC` PREFETCH_METADATA_HIT_PERC=`echo "scale=2 ; (100*$PREFETCH_METADATA_HITS/$ARC_HITS)" | $BC` -PREFETCH_METADATA_MISSES_PERC=`echo "scale=2 ; (100*$PREFETCH_METADATA_MISSES/$ARC_HITS)" | $BC` +PREFETCH_METADATA_MISSES_PERC=`echo "scale=2 ; (100*$PREFETCH_METADATA_MISSES/$ARC_MISSES)" | $BC` DMU_TOTAL=`echo "$DMU_HITS+$DMU_MISSES" | $BC` DMU_HITS_PERC=`echo "scale=2 ; (100*$DMU_HITS/$DMU_TOTAL)" | $BC` From 6b7922c3793e6d4b8d92b7e1dafc75a9a41e9a7d Mon Sep 17 00:00:00 2001 From: dabb Date: Fri, 24 Feb 2012 12:46:10 +0000 Subject: [PATCH 04/15] Removing unnecessary graph_category attributes --- plugins/zfs/zfs_stats_ | 5 ----- 1 file changed, 5 deletions(-) diff --git a/plugins/zfs/zfs_stats_ b/plugins/zfs/zfs_stats_ index bef05684..d062c562 100755 --- a/plugins/zfs/zfs_stats_ +++ b/plugins/zfs/zfs_stats_ @@ -108,7 +108,6 @@ efficiency() { echo 'graph_title ZFS ARC Efficiency' echo 'graph_args -u 100' echo 'graph_vlabel %' - echo 'graph_category ZFS' echo 'graph_info This graph shows the ARC Efficiency' echo 'hits.label Cache Hit Ratio' @@ -132,7 +131,6 @@ cachehitlist() { echo 'graph_title ZFS ARC Efficiency: Cache hits by cache list' echo 'graph_args -u 100' echo 'graph_vlabel %' - echo 'graph_category ZFS' echo 'graph_info This graph shows the ARC Efficiency' echo 'cache_list_anon.label Anonymously Used' @@ -156,7 +154,6 @@ cachehitdtype() { echo 'graph_title ZFS ARC Efficiency: Cache hits by data type' echo 'graph_args -u 100' echo 'graph_vlabel %' - echo 'graph_category ZFS' echo 'graph_info This graph shows the ARC Efficiency' echo 'data_type_demand_hits.label Demand Data Hit Ratio' @@ -187,7 +184,6 @@ dmuprefetch() { echo 'graph_title ZFS DMU prefetch stats' echo 'graph_args -u 100' echo 'graph_vlabel %' - echo 'graph_category ZFS' echo 'graph_info This graph shows the DMU prefetch stats' echo 'hits.label Hit percentage' @@ -206,7 +202,6 @@ utilization() { echo 'graph_title ZFS ARC Size' echo 'graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit '$MEMMAX echo 'graph_vlabel Size in MB' - echo 'graph_category ZFS' echo 'graph_info This graph shows the ARC Size utilization' echo 'max_size.label Maximum Size' From 20cc0e049134bf8869a57163bd54672ea279b99f Mon Sep 17 00:00:00 2001 From: dabb Date: Fri, 24 Feb 2012 13:30:14 +0000 Subject: [PATCH 05/15] Added a L2ARC size function and some cleanup --- plugins/zfs/zfs_stats_ | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/plugins/zfs/zfs_stats_ b/plugins/zfs/zfs_stats_ index d062c562..81265ecd 100755 --- a/plugins/zfs/zfs_stats_ +++ b/plugins/zfs/zfs_stats_ @@ -59,6 +59,8 @@ MAX_SIZE=`$SYS kstat.zfs.misc.arcstats.c_max` MIN_SIZE=`$SYS kstat.zfs.misc.arcstats.c_min` TARGET_SIZE=`$SYS kstat.zfs.misc.arcstats.c` +L2_SIZE=`$SYS kstat.zfs.misc.arcstats.l2_size` +L2_HDR_SIZE=`$SYS kstat.zfs.misc.arcstats.l2_hdr_size` # # Calculation macros @@ -103,7 +105,6 @@ fi efficiency() { - if [ "$1" = "config" ]; then echo 'graph_title ZFS ARC Efficiency' echo 'graph_args -u 100' @@ -179,7 +180,6 @@ cachehitdtype() { } dmuprefetch() { - if [ "$1" = "config" ]; then echo 'graph_title ZFS DMU prefetch stats' echo 'graph_args -u 100' @@ -197,7 +197,6 @@ dmuprefetch() { } utilization() { - if [ "$1" = "config" ]; then echo 'graph_title ZFS ARC Size' echo 'graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit '$MEMMAX @@ -228,6 +227,25 @@ utilization() { fi } +l2utilization() { + if [ "$1" = "config" ]; then + echo 'graph_title ZFS L2ARC Size' + echo 'graph_args --base 1024 -r -l 0 --vertical-label Bytes' + echo 'graph_vlabel Size in MB' + echo 'graph_info This graph shows the L2ARC Size utilization' + + echo 'size.label Size' + echo 'size.draw AREA' + echo 'hdr_size.label Header Size' + echo 'hdr_size.draw AREA' + + exit 0 + else + echo 'size.value ' $L2_SIZE + echo 'hdr_size.value ' $L2_HDR_SIZE + fi +} + [ "$1" = "config" ] && echo "graph_category zfs" case "$FUNCTION" in @@ -246,4 +264,7 @@ case "$FUNCTION" in utilization) utilization $1 ;; + l2utilization) + l2utilization $1 + ;; esac From 55ba113d2f40c570ec9c7b8b750f8d8e6a895815 Mon Sep 17 00:00:00 2001 From: David Bjornsson Date: Fri, 24 Feb 2012 14:36:50 +0000 Subject: [PATCH 06/15] Added a L2ARC efficiency function, also some label consistency changes --- plugins/zfs/zfs_stats_ | 44 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/plugins/zfs/zfs_stats_ b/plugins/zfs/zfs_stats_ index 81265ecd..64d5657a 100755 --- a/plugins/zfs/zfs_stats_ +++ b/plugins/zfs/zfs_stats_ @@ -18,6 +18,8 @@ # cachehitdtype - Cache hit by data type # dmuprefetch - DMU prefetch # utilization - ARC size breakdown +# l2utilization - L2ARC size breakdown +# l2efficiency - L2ARC efficiency # #%# family=auto @@ -61,6 +63,12 @@ TARGET_SIZE=`$SYS kstat.zfs.misc.arcstats.c` L2_SIZE=`$SYS kstat.zfs.misc.arcstats.l2_size` L2_HDR_SIZE=`$SYS kstat.zfs.misc.arcstats.l2_hdr_size` +<<<<<<< HEAD + +L2_HITS=`$SYS kstat.zfs.misc.arcstats.l2_hits` +L2_MISSES=`$SYS kstat.zfs.misc.arcstats.l2_misses` +======= +>>>>>>> 20cc0e049134bf8869a57163bd54672ea279b99f # # Calculation macros @@ -103,6 +111,9 @@ else MFU_SIZE=`echo "$TARGET_SIZE-$MRU_SIZE" | $BC` fi +L2_ACCESSES_TOTAL=`echo "$L2_HITS+$L2_MISSES" | $BC` +L2_HIT_RATIO_PERC=`echo "scale=2 ; (100*$L2_HITS/$L2_ACCESSES_TOTAL)" | $BC` +L2_MISS_RATIO_PERC=`echo "scale=2 ; (100*$L2_MISSES/$L2_ACCESSES_TOTAL)" | $BC` efficiency() { if [ "$1" = "config" ]; then @@ -111,8 +122,8 @@ efficiency() { echo 'graph_vlabel %' echo 'graph_info This graph shows the ARC Efficiency' - echo 'hits.label Cache Hit Ratio' - echo 'misses.label Cache Miss Ratio' + echo 'hits.label Hit Ratio' + echo 'misses.label Miss Ratio' echo 'actual_hits.label Actual Hit Ratio' echo 'data_demand_efficiency.label Data Demand Efficiency' echo 'data_prefetch_efficiency.label Data Prefetch Efficiency' @@ -186,8 +197,8 @@ dmuprefetch() { echo 'graph_vlabel %' echo 'graph_info This graph shows the DMU prefetch stats' - echo 'hits.label Hit percentage' - echo 'misses.label Miss percentage' + echo 'hits.label Hit Ratio' + echo 'misses.label Miss Ratio' exit 0 else @@ -246,6 +257,25 @@ l2utilization() { fi } +<<<<<<< HEAD +l2efficiency() { + if [ "$1" = "config" ]; then + echo 'graph_title ZFS L2ARC Efficiency' + echo 'graph_args -u 100' + echo 'graph_vlabel %' + echo 'graph_info This graph shows the L2ARC Efficiency' + + echo 'l2_hits.label Hit Ratio' + echo 'l2_misses.label Miss Ratio' + else + echo 'l2_hits.value ' $L2_HIT_RATIO_PERC + echo 'l2_misses.value ' $L2_MISS_RATIO_PERC + fi + +} + +======= +>>>>>>> 20cc0e049134bf8869a57163bd54672ea279b99f [ "$1" = "config" ] && echo "graph_category zfs" case "$FUNCTION" in @@ -267,4 +297,10 @@ case "$FUNCTION" in l2utilization) l2utilization $1 ;; +<<<<<<< HEAD + l2efficiency) + l2efficiency $1 + ;; +======= +>>>>>>> 20cc0e049134bf8869a57163bd54672ea279b99f esac From 16174878027ef15d92395c83e4640ab4153ee507 Mon Sep 17 00:00:00 2001 From: David Bjornsson Date: Fri, 24 Feb 2012 14:42:21 +0000 Subject: [PATCH 07/15] Revert "Added a L2ARC efficiency function, also some label consistency changes" This reverts commit 55ba113d2f40c570ec9c7b8b750f8d8e6a895815. --- plugins/zfs/zfs_stats_ | 44 ++++-------------------------------------- 1 file changed, 4 insertions(+), 40 deletions(-) diff --git a/plugins/zfs/zfs_stats_ b/plugins/zfs/zfs_stats_ index 64d5657a..81265ecd 100755 --- a/plugins/zfs/zfs_stats_ +++ b/plugins/zfs/zfs_stats_ @@ -18,8 +18,6 @@ # cachehitdtype - Cache hit by data type # dmuprefetch - DMU prefetch # utilization - ARC size breakdown -# l2utilization - L2ARC size breakdown -# l2efficiency - L2ARC efficiency # #%# family=auto @@ -63,12 +61,6 @@ TARGET_SIZE=`$SYS kstat.zfs.misc.arcstats.c` L2_SIZE=`$SYS kstat.zfs.misc.arcstats.l2_size` L2_HDR_SIZE=`$SYS kstat.zfs.misc.arcstats.l2_hdr_size` -<<<<<<< HEAD - -L2_HITS=`$SYS kstat.zfs.misc.arcstats.l2_hits` -L2_MISSES=`$SYS kstat.zfs.misc.arcstats.l2_misses` -======= ->>>>>>> 20cc0e049134bf8869a57163bd54672ea279b99f # # Calculation macros @@ -111,9 +103,6 @@ else MFU_SIZE=`echo "$TARGET_SIZE-$MRU_SIZE" | $BC` fi -L2_ACCESSES_TOTAL=`echo "$L2_HITS+$L2_MISSES" | $BC` -L2_HIT_RATIO_PERC=`echo "scale=2 ; (100*$L2_HITS/$L2_ACCESSES_TOTAL)" | $BC` -L2_MISS_RATIO_PERC=`echo "scale=2 ; (100*$L2_MISSES/$L2_ACCESSES_TOTAL)" | $BC` efficiency() { if [ "$1" = "config" ]; then @@ -122,8 +111,8 @@ efficiency() { echo 'graph_vlabel %' echo 'graph_info This graph shows the ARC Efficiency' - echo 'hits.label Hit Ratio' - echo 'misses.label Miss Ratio' + echo 'hits.label Cache Hit Ratio' + echo 'misses.label Cache Miss Ratio' echo 'actual_hits.label Actual Hit Ratio' echo 'data_demand_efficiency.label Data Demand Efficiency' echo 'data_prefetch_efficiency.label Data Prefetch Efficiency' @@ -197,8 +186,8 @@ dmuprefetch() { echo 'graph_vlabel %' echo 'graph_info This graph shows the DMU prefetch stats' - echo 'hits.label Hit Ratio' - echo 'misses.label Miss Ratio' + echo 'hits.label Hit percentage' + echo 'misses.label Miss percentage' exit 0 else @@ -257,25 +246,6 @@ l2utilization() { fi } -<<<<<<< HEAD -l2efficiency() { - if [ "$1" = "config" ]; then - echo 'graph_title ZFS L2ARC Efficiency' - echo 'graph_args -u 100' - echo 'graph_vlabel %' - echo 'graph_info This graph shows the L2ARC Efficiency' - - echo 'l2_hits.label Hit Ratio' - echo 'l2_misses.label Miss Ratio' - else - echo 'l2_hits.value ' $L2_HIT_RATIO_PERC - echo 'l2_misses.value ' $L2_MISS_RATIO_PERC - fi - -} - -======= ->>>>>>> 20cc0e049134bf8869a57163bd54672ea279b99f [ "$1" = "config" ] && echo "graph_category zfs" case "$FUNCTION" in @@ -297,10 +267,4 @@ case "$FUNCTION" in l2utilization) l2utilization $1 ;; -<<<<<<< HEAD - l2efficiency) - l2efficiency $1 - ;; -======= ->>>>>>> 20cc0e049134bf8869a57163bd54672ea279b99f esac From cbe45534113dcc742115bc8a68daaa2aeb18b79a Mon Sep 17 00:00:00 2001 From: David Bjornsson Date: Fri, 24 Feb 2012 14:45:26 +0000 Subject: [PATCH 08/15] Added a L2ARC efficiency function, also some label consistency changes --- plugins/zfs/zfs_stats_ | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/plugins/zfs/zfs_stats_ b/plugins/zfs/zfs_stats_ index 81265ecd..a9d9801e 100755 --- a/plugins/zfs/zfs_stats_ +++ b/plugins/zfs/zfs_stats_ @@ -18,6 +18,8 @@ # cachehitdtype - Cache hit by data type # dmuprefetch - DMU prefetch # utilization - ARC size breakdown +# l2utilization - L2ARC size breakdown +# l2efficiency - L2ARC efficiency # #%# family=auto @@ -62,6 +64,9 @@ TARGET_SIZE=`$SYS kstat.zfs.misc.arcstats.c` L2_SIZE=`$SYS kstat.zfs.misc.arcstats.l2_size` L2_HDR_SIZE=`$SYS kstat.zfs.misc.arcstats.l2_hdr_size` +L2_HITS=`$SYS kstat.zfs.misc.arcstats.l2_hits` +L2_MISSES=`$SYS kstat.zfs.misc.arcstats.l2_misses` + # # Calculation macros # @@ -103,6 +108,9 @@ else MFU_SIZE=`echo "$TARGET_SIZE-$MRU_SIZE" | $BC` fi +L2_ACCESSES_TOTAL=`echo "$L2_HITS+$L2_MISSES" | $BC` +L2_HIT_RATIO_PERC=`echo "scale=2 ; (100*$L2_HITS/$L2_ACCESSES_TOTAL)" | $BC` +L2_MISS_RATIO_PERC=`echo "scale=2 ; (100*$L2_MISSES/$L2_ACCESSES_TOTAL)" | $BC` efficiency() { if [ "$1" = "config" ]; then @@ -111,8 +119,8 @@ efficiency() { echo 'graph_vlabel %' echo 'graph_info This graph shows the ARC Efficiency' - echo 'hits.label Cache Hit Ratio' - echo 'misses.label Cache Miss Ratio' + echo 'hits.label Hit Ratio' + echo 'misses.label Miss Ratio' echo 'actual_hits.label Actual Hit Ratio' echo 'data_demand_efficiency.label Data Demand Efficiency' echo 'data_prefetch_efficiency.label Data Prefetch Efficiency' @@ -186,8 +194,8 @@ dmuprefetch() { echo 'graph_vlabel %' echo 'graph_info This graph shows the DMU prefetch stats' - echo 'hits.label Hit percentage' - echo 'misses.label Miss percentage' + echo 'hits.label Hit Ratio' + echo 'misses.label Miss Ratio' exit 0 else @@ -246,6 +254,22 @@ l2utilization() { fi } +l2efficiency() { + if [ "$1" = "config" ]; then + echo 'graph_title ZFS L2ARC Efficiency' + echo 'graph_args -u 100' + echo 'graph_vlabel %' + echo 'graph_info This graph shows the L2ARC Efficiency' + + echo 'l2_hits.label Hit Ratio' + echo 'l2_misses.label Miss Ratio' + else + echo 'l2_hits.value ' $L2_HIT_RATIO_PERC + echo 'l2_misses.value ' $L2_MISS_RATIO_PERC + fi + +} + [ "$1" = "config" ] && echo "graph_category zfs" case "$FUNCTION" in @@ -267,4 +291,7 @@ case "$FUNCTION" in l2utilization) l2utilization $1 ;; + l2efficiency) + l2efficiency $1 + ;; esac From f14628ad35d567fb1cc2ff2cdd0fd64f13348b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BE=D1=80=D0=BB=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D0=BC?= Date: Sat, 25 Feb 2012 12:22:25 +0400 Subject: [PATCH 09/15] Changed the location of their own plug-ins --- plugins/{other => network}/if | 0 plugins/{other => power}/batteries | 0 plugins/{other => squid}/squid | 0 plugins/{other => system}/cpu | 0 plugins/{other => system}/irq | 0 plugins/{other => system}/meminfo | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename plugins/{other => network}/if (100%) rename plugins/{other => power}/batteries (100%) rename plugins/{other => squid}/squid (100%) rename plugins/{other => system}/cpu (100%) rename plugins/{other => system}/irq (100%) rename plugins/{other => system}/meminfo (100%) diff --git a/plugins/other/if b/plugins/network/if similarity index 100% rename from plugins/other/if rename to plugins/network/if diff --git a/plugins/other/batteries b/plugins/power/batteries similarity index 100% rename from plugins/other/batteries rename to plugins/power/batteries diff --git a/plugins/other/squid b/plugins/squid/squid similarity index 100% rename from plugins/other/squid rename to plugins/squid/squid diff --git a/plugins/other/cpu b/plugins/system/cpu similarity index 100% rename from plugins/other/cpu rename to plugins/system/cpu diff --git a/plugins/other/irq b/plugins/system/irq similarity index 100% rename from plugins/other/irq rename to plugins/system/irq diff --git a/plugins/other/meminfo b/plugins/system/meminfo similarity index 100% rename from plugins/other/meminfo rename to plugins/system/meminfo From b354f28110a174c67084de0726673bd9ffe28467 Mon Sep 17 00:00:00 2001 From: Andrey Kozhokaru Date: Sat, 25 Feb 2012 19:13:56 +0200 Subject: [PATCH 10/15] Add RackSpace monitoring plugins --- plugins/rackspace/README | 8 +++ plugins/rackspace/rackspace_cdn_count.php | 70 +++++++++++++++++++++++ plugins/rackspace/rackspace_cdn_size.php | 67 ++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 plugins/rackspace/README create mode 100644 plugins/rackspace/rackspace_cdn_count.php create mode 100644 plugins/rackspace/rackspace_cdn_size.php diff --git a/plugins/rackspace/README b/plugins/rackspace/README new file mode 100644 index 00000000..9faf8c8d --- /dev/null +++ b/plugins/rackspace/README @@ -0,0 +1,8 @@ +====================================================================================== +These plugins are made to monitor RackSpace Cloudfiles storage usage and files +count. + +====================================================================================== + +Andrey Kozhokaru +andrey@kozhokaru.com diff --git a/plugins/rackspace/rackspace_cdn_count.php b/plugins/rackspace/rackspace_cdn_count.php new file mode 100644 index 00000000..71356e2d --- /dev/null +++ b/plugins/rackspace/rackspace_cdn_count.php @@ -0,0 +1,70 @@ +#!/usr/bin/php +# Author Andrey Kozhokaru +# Plugin to monitor Rackspace File count +# +# Parameters: +# +# config (required) +# +# +#%# family=manual + + + diff --git a/plugins/rackspace/rackspace_cdn_size.php b/plugins/rackspace/rackspace_cdn_size.php new file mode 100644 index 00000000..45fca542 --- /dev/null +++ b/plugins/rackspace/rackspace_cdn_size.php @@ -0,0 +1,67 @@ +#!/usr/bin/php +# Author Andrey Kozhokaru +# Plugin to monitor Rackspace CloudFile storage usage +# +# Parameters: +# +# config (required) +# +# +#%# family=manual + + From 0aa2b8d1f542149e8f0efce0f253014f3bf7bbe3 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sat, 25 Feb 2012 22:43:08 +0100 Subject: [PATCH 11/15] measure IMAP bandwidth based on mbsync/isync --- plugins/mail/imap_bandwidth | 212 ++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100755 plugins/mail/imap_bandwidth diff --git a/plugins/mail/imap_bandwidth b/plugins/mail/imap_bandwidth new file mode 100755 index 00000000..21fde171 --- /dev/null +++ b/plugins/mail/imap_bandwidth @@ -0,0 +1,212 @@ +#!/bin/sh + +: <<=cut +=head1 NAME + +imap_bandwidth - Munin plugin to measure the current bandwidth of one or more remote IMAP servers. + +=head1 APPLICABLE SYSTEMS + +Any Linux system with the package "isync" (or "mbsync") installed. + +=head1 CONFIGURATION + +This configuration section shows a usable example for two imap servers: + [imap_bandwidth] + env.imap_servers internal=imap-internal.example.org external=imap.example.org + env.cert_file /etc/munin-imap-cert.pem + env.username foo_user + env.password secret + env.transfer_volume_kbyte 100 + env.use_ssl yes + + +Both "use_ssl" and "transfer_volume_kbyte" are optional and default to the above +values. +All other parameters are required. + +Generate the certificate file by running "mbsync-get-cert imap.example.org". + +"imap_servers" is a space-separated list of key=value combinations. "key" is +used as a label in munin graphs. "value" is the full hostname or IP of the IMAP +server. All IMAP servers need to share the same authentication database (i.e. +accept the same username/password). + +Reduce the "transfer_volume_kbyte" parameter if you need to minimize traffic. + +Maybe you need to specify the "timeout" setting for this plugin if it takes +longer than munin's default timeout. + + +=head1 INTERPRETATION + +The plugin simply shows the average bandwidth during one IMAP upload and one +IMAP download of a file containg random bytes. + +You need to be aware that this measurement obviously increases the load on +your IMAP servers for the duration of the measurement. + +You also need to be aware of the safety implications imposed by storing +sensitive information (username and password combinations) on your monitoring +server in plaintext. + +=head1 VERSION + +Version 1.0 + +=head1 BUGS + +None known + +Set the environment variable DEBUG=1 if you need to investigate problems. + +=head1 AUTHOR + +Lars Kruse + +=head1 LICENSE + +GPLv3 or higher + +=cut + + +set -eu + +#%# family=auto +#%# capabilities=autoconf + +TRANSFER_SIZE=${transfer_volume_kbyte:-100} +USE_SSL=${use_ssl:-yes} +IMAP_USERNAME=${username} +IMAP_PASSWORD=${password} +CERT_FILE=${cert_file} + +# example value: +# internal=imap-internal.example.org external=imap.example.org +SERVERS="$imap_servers" + + +if test -n "${DEBUG:-}"; then + TRANSFER_SIZE=20 + set -x +fi + + +. $MUNIN_LIBDIR/plugins/plugin.sh + + +if [ "$1" = "autoconf" ]; then + if ( which mbsync >/dev/null 2>&1 ); then + echo yes + exit 0 + else + echo "no (could not run \"mbsync\")" + exit 0 + fi +fi + +if [ "$1" = "config" ]; then + echo 'graph_title IMAP speed' + echo 'graph_vlabel upload/download speed [bit/s]' + echo 'graph_category network' + for item in $SERVERS; do + key="$(echo "$item" | cut -f 1 -d =)" + clean_name="$(clean_fieldname "$key")" + echo "download_${clean_name}.graph no" + echo "upload_${clean_name}.label $key" + echo "upload_${clean_name}.negative download_${clean_name}" + done + exit 0 +fi + + +create_dummy_file() { + dd if=/dev/urandom "of=$DUMMY_FILENAME" bs=1K count=${TRANSFER_SIZE} 2>/dev/null +} + +is_dummy_file_missing() { + test ! -e "$DUMMY_FILENAME" +} + +remove_mail_files() { + get_mail_files | while read fname; do rm "$fname"; done +} + +get_mail_files() { + find "$MAILDIR" -type f | grep -v "/\." +} + +# run the synchronization +run_sync() { + if test -n "${DEBUG:-}"; then + echo yes | mbsync --config "$SYNCRC" sync || true + else + echo yes | mbsync --config "$SYNCRC" sync >/dev/null 2>/dev/null || true + fi +} + +# run the synchronization and determine the duration of this operation +speed_sync() { + start=$(date +%s%N) + run_sync + end=$(date +%s%N) + # did we wrap a minute? + test "$end" -lt "$start" && end=$((end + 60 * 1000000000)) + delay=$((end - start)) + # use "bit" multiplier + echo "$((8 * TRANSFER_SIZE * 1024 * 1000000000 / delay))" +} + +for item in $SERVERS; do + key="$(echo "$item" | cut -f 1 -d =)" + host="$(echo "$item" | cut -f 2- -d =)" + clean_name="$(clean_fieldname "$key")" + MAILDIR="$(mktemp -d)" + # this file needs to include a dot at the beginning - otherwise it gets cleaned up ... + SYNCRC="$MAILDIR/.mbsyncrc" + SYNC_STATE_FILE_PREFIX="$MAILDIR/.syncstate-" + + cat - >"$SYNCRC" <<- EOF + SyncState $SYNC_STATE_FILE_PREFIX + Expunge Both + + MaildirStore local + Path $MAILDIR + Inbox $MAILDIR + + IMAPStore remote + Host $host + UseIMAPS $USE_SSL + User $IMAP_USERNAME + Pass $IMAP_PASSWORD + CertificateFile $CERT_FILE + + Channel sync + Master :local: + Slave :remote: +EOF + + mkdir "$MAILDIR/new" "$MAILDIR/tmp" "$MAILDIR/cur" + DUMMY_FILENAME="$MAILDIR/new/$(date +%N)" + # download all existing files + run_sync + # remove all local files -> to be purged remotely later + remove_mail_files + # create dummy file for upload + create_dummy_file "$MAILDIR" + output="upload_${clean_name}.value $(speed_sync)" + is_dummy_file_missing && echo "$output" || echo >&2 "upload failed" + # remove local file + remove_mail_files "$MAILDIR" + # persuade mbsync that we have never seen the dummy file ... + rm "$SYNC_STATE_FILE_PREFIX"* + output="download_${clean_name}.value $(speed_sync)" + get_mail_files | grep -q . && echo "$output" || echo >&2 "download failed" + # remove the new file from the imap server + remove_mail_files + run_sync + # clean up + rm -r "$MAILDIR" + done + From ea382ede4ef194c11f982c3ca3bb85a791cbad79 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sun, 26 Feb 2012 03:45:47 +0100 Subject: [PATCH 12/15] improved graph labels added changelog --- plugins/mail/imap_bandwidth | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/mail/imap_bandwidth b/plugins/mail/imap_bandwidth index 21fde171..fc5cd894 100755 --- a/plugins/mail/imap_bandwidth +++ b/plugins/mail/imap_bandwidth @@ -1,4 +1,11 @@ #!/bin/sh +# +# Revision 1.1 2012/02/26 03:43:27 +# Improved labels +# +# Revision 1.0 2012/02/25 21:31:16 +# Initial release +# : <<=cut =head1 NAME @@ -107,13 +114,14 @@ if [ "$1" = "autoconf" ]; then fi if [ "$1" = "config" ]; then - echo 'graph_title IMAP speed' - echo 'graph_vlabel upload/download speed [bit/s]' + echo 'graph_title IMAP bandwidth' + echo 'graph_vlabel to (+) / from (-) server [bit/s]' echo 'graph_category network' for item in $SERVERS; do key="$(echo "$item" | cut -f 1 -d =)" clean_name="$(clean_fieldname "$key")" echo "download_${clean_name}.graph no" + echo "download_${clean_name}.label download" echo "upload_${clean_name}.label $key" echo "upload_${clean_name}.negative download_${clean_name}" done From 5a41f45571652e1235d65417ea3ef6ff6d15092e Mon Sep 17 00:00:00 2001 From: Kenyon Ralph Date: Mon, 27 Feb 2012 01:44:27 -0800 Subject: [PATCH 13/15] remove obsolete dovecot plugin and move the newer one to the mail directory --- plugins/correo/dovecot126 | 168 -------------------------------- plugins/{other => mail}/dovecot | 0 2 files changed, 168 deletions(-) delete mode 100755 plugins/correo/dovecot126 rename plugins/{other => mail}/dovecot (100%) diff --git a/plugins/correo/dovecot126 b/plugins/correo/dovecot126 deleted file mode 100755 index 3a5d65bc..00000000 --- a/plugins/correo/dovecot126 +++ /dev/null @@ -1,168 +0,0 @@ -#!/bin/sh -# -# Munin Plugin -# to count logins to your dovecot mailserver -# -# Created by Dominik Schulz -# http://developer.gauner.org/munin/ -# Contributions by: -# - Stephane Enten -# Modified by Fabián Sellés Rosa -# and Arturo Blanco Paramio -# cleaned up and adapted for dovecot 1.2.6 for Ubuntu 10.4 -# Parameters understood: -# -# config (required) -# autoconf (optional - used by munin-config) -# -# Config variables: -# -# logfile - Where to find the syslog file -# -# Add the following line to a file in /etc/munin/plugin-conf.d: -# env.logfile /var/log/your/logfile.log -# -# Magic markers (optional - used by munin-config and installation scripts): -# -#%# family=auto -#%# capabilities=autoconf - -###################### -# Configuration -###################### -STAT_FILE=/var/lib/munin/plugin-state/plugin-dovecot.state -EXPR_BIN=/usr/bin/expr -LOGFILE=${logfile:-/var/log/dovecot-info.log} -###################### - -if [ "$1" = "autoconf" ]; then - echo yes - exit 0 -fi - -if [ "$1" = "config" ]; then - echo 'graph_title Logins en Dovecot' - echo 'graph_args --base 1000 -l 0' - echo 'graph_vlabel Contadores de Login' - echo 'graph_total total' - echo 'graph_category Correo' - - echo 'login_total.label Total Logins' - echo 'login_total.min 1' - - echo 'login_tls.label TLS Logins' - echo 'login_tls.min 1' - echo 'login_ssl.label SSL Logins' - echo 'login_ssl.label SSL Logins' - echo 'login_imap.label IMAP Logins' - echo 'login_pop3.label POP3 Logins' - echo 'connected.label Connected Users' - exit 0 -fi - -############################# -# Initialization -############################# -if [ ! -r $STAT_FILE ]; then - echo "TOTAL=0" > $STAT_FILE - echo "TLS=0" >> $STAT_FILE - echo "SSL=0" >> $STAT_FILE - echo "IMAP=0" >> $STAT_FILE - echo "POP3=0" >> $STAT_FILE -fi -############################# - - -###################### -# Total Logins -###################### - -NEW_TOTAL=$(egrep '*Login' $LOGFILE | grep "`date '+%Y-%m-%d'`" | sort | wc -l) -OLD_TOTAL=$(grep TOTAL $STAT_FILE | cut -f2 -d '=') -TOTAL=$(($NEW_TOTAL - $OLD_TOTAL)) -LOGINVALUE=0 -if [ $TOTAL -gt 0 ]; then - LOGINVALUE=$TOTAL -fi - -###################### -# Connected Users -###################### -DISCONNECTS=$(egrep '*Disconnected' $LOGFILE | sort | wc -l) -CONNECTS=$(egrep '.*Login' $LOGFILE | sort | wc -l) -DISCON=$(($CONNECTS - $DISCONNECTS)) -if [ $DISCON -lt 0 ]; then - DISCON=0 -fi - -###################### -# TLS Logins -###################### - -NEW_TLS=$(egrep '.*Login.*TLS' $LOGFILE | grep "`date '+%Y-%m-%d'`" | sort | wc -l) -OLD_TLS=$(grep TLS $STAT_FILE | cut -f2 -d '=') -TLS=$(($NEW_TLS - $OLD_TLS)) -TLSVALUE=0 -if [ $TLS -gt 0 ]; then - TLSVALUE=$TLS -fi -echo -n -###################### -# SSL Logins -###################### - -NEW_SSL=$(egrep '.*Login.*SSL' $LOGFILE | grep "`date '+%Y-%m-%d'`" | sort | wc -l) -OLD_SSL=$(grep SSL $STAT_FILE | cut -f2 -d '=') -SSL=$(($NEW_SSL - $OLD_SSL)) -SSLVALUE=0 -if [ $SSL -gt 0 ]; then - SSLVALUE=$SSL -fi - -###################### -# IMAP Logins -###################### - -NEW_IMAP=$(egrep '.*imap.*Login' $LOGFILE | grep "`date '+%Y-%m-%d'`" | sort | wc -l) -OLD_IMAP=$(grep IMAP $STAT_FILE | cut -f2 -d '=') -IMAP=$(($NEW_IMAP - $OLD_IMAP)) -IMAPVALUE=0 -if [ $IMAP -gt 0 ]; then - IMAPVALUE=$IMAP -fi - -###################### -# POP3 Logins -###################### - -NEW_POP3=$(egrep '.*pop3.*Login' $LOGFILE | grep "`date '+%Y-%m-%d'`" | sort | wc -l) -OLD_POP3=$(grep POP3 $STAT_FILE | cut -f2 -d '=') -POP3=$(($NEW_POP3 - $OLD_POP3)) -POP3VALUE=0 -if [ $POP3 -gt 0 ]; then - POP3VALUE=$POP3 -fi - - -####################### -# echo the new values -###################### - -echo "login_total.value $LOGINVALUE" -echo "connected.value $DISCON" -echo "login_tls.value $TLSVALUE" -echo "login_ssl.value $SSLVALUE " -echo "login_imap.value $IMAPVALUE" -echo "login_pop3.value $POP3VALUE " - - - -###################### -# Save the new values -###################### -echo "TOTAL=$NEW_TOTAL" > $STAT_FILE -echo "TLS=$NEW_TLS" >> $STAT_FILE -echo "SSL=$NEW_SSL" >> $STAT_FILE -echo "IMAP=$NEW_IMAP" >> $STAT_FILE -echo "POP3=$NEW_POP3" >> $STAT_FILE - diff --git a/plugins/other/dovecot b/plugins/mail/dovecot similarity index 100% rename from plugins/other/dovecot rename to plugins/mail/dovecot From 2584caff7881d31cdb6f51fe1257f80360439bdb Mon Sep 17 00:00:00 2001 From: Dominik Schulz Date: Sun, 26 Feb 2012 20:16:43 +0800 Subject: [PATCH 14/15] Add djabberd plugin. This commit adds a plugin to monitor DJabberd servers using the AdminPort feature which offers a telnet admin interface. It is a multi-personality plugin written in perl. --- plugins/djabberd/djabberd_ | 285 +++++++++++++++++++++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100644 plugins/djabberd/djabberd_ diff --git a/plugins/djabberd/djabberd_ b/plugins/djabberd/djabberd_ new file mode 100644 index 00000000..247af90c --- /dev/null +++ b/plugins/djabberd/djabberd_ @@ -0,0 +1,285 @@ +#!/usr/bin/perl -w +# +# Copyright (C) 2012 Dominik Schulz +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; version 2 dated June, +# 1991. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# Script to monitor DJabberd servers. +# Mostly an adaptation of Guillaume Blairon's mogliefsd_activity script. +# +# Usage: +# ln -s /usr/share/munin/plugins/djabberd_ \ +# /etc/munin/plugins/djabberd_{connections,memory,latency,counters} +# +# Configuration variables: +# +# host (default: '127.0.0.1') +# port (default: '5200') +# +# Parameters: +# +# config (required) +# autoconf (optional - only used by munin-config) +# +#%# family=auto +#%# capabilities=autoconf + +use strict; +use warnings; +use IO::Socket; + +my $djabberd_host = $ENV{host} || "127.0.0.1"; +my $djabberd_port = $ENV{port} || 5200; +my $mode = undef; +my $mode_name = undef; + +# mapping mode to command from which we get the information +my $mode_ref = { + 'connections' => { + 'cmd' => 'stats', + 'title' => 'DJabberd Connections', + 'vlabel' => 'connections', + 'fields' => { + 'connections' => { + 'key' => 'connections', + 'label' => 'Connections', + 'description' => 'Number of current connections', + 'draw' => 'LINE1', + 'type' => 'GAUGE', + }, + 'users' => { + 'key' => 'users', + 'label' => 'Users', + 'description' => 'Number of connected users', + 'draw' => 'LINE1', + 'type' => 'GAUGE', + }, + }, + }, + 'memory' => { + 'cmd' => 'stats', + 'title' => 'DJabberd Memory Statistics', + 'vlabel' => 'Bytes', + 'fields' => { + 'mem_total' => { + 'key' => 'mem_total', + 'label' => '', + 'description' => 'Total memory used by DJabberd', + 'draw' => 'LINE1', + 'type' => 'GAUGE', + 'filter' => \&kb2bytes, + }, + 'mem_connections' => { + 'key' => 'mem_connections', + 'label' => '', + 'description' => 'Memory used for handling connections', + 'draw' => 'LINE1', + 'type' => 'GAUGE', + 'filter' => \&kb2bytes, + }, + 'mem_per_connection' => { + 'key' => 'mem_per_connection', + 'label' => '', + 'description' => 'Memory used per connection', + 'draw' => 'LINE1', + 'type' => 'GAUGE', + 'filter' => \&kb2bytes, + }, + } + }, + 'latency' => { + 'cmd' => 'latency', + 'title' => 'DJabberd Latency Statistics', + 'vlabel' => 'reqs.', + 'fields' => { + 'dotzerozerozerofive' => { + 'key' => '-0.0005', + 'label' => 'lt. 0.0005', + 'description' => 'Requests handled in lt. 0.0005s', + 'draw' => 'AREA', + 'type' => 'COUNTER', + }, + 'dotzerozeroone' => { + 'key' => '-0.001', + 'label' => 'lt. 0.001', + 'description' => 'Requests handled int lt. 0.001s', + 'draw' => 'STACK', + 'type' => 'COUNTER', + }, + 'dotzerozerotwo' => { + 'key' => '-0.002', + 'label' => 'lt. 0.002', + 'description' => 'Requests handled int lt. 0.002s', + 'draw' => 'STACK', + 'type' => 'COUNTER', + }, + 'dotzerozerofive' => { + 'key' => '-0.005', + 'label' => 'lt. 0.005', + 'description' => 'Requests handled int lt. 0.005s', + 'draw' => 'STACK', + 'type' => 'COUNTER', + }, + 'dotzeroone' => { + 'key' => '-0.01', + 'label' => 'lt. 0.01', + 'description' => 'Requests handled int lt. 0.01s', + 'draw' => 'STACK', + 'type' => 'COUNTER', + }, + 'dotzerotwo' => { + 'key' => '-0.02', + 'label' => 'lt. 0.02', + 'description' => 'Requests handled int lt. 0.02s', + 'draw' => 'STACK', + 'type' => 'COUNTER', + }, + } + }, + 'counters' => { + 'cmd' => 'counters', + 'title' => 'DJabberd Counters', + 'vlabel' => 'msgs.', + 'fields' => { + 'clientin_djabberd_iq' => { 'key' => 'ClientIn:DJabberd::IQ', 'type' => 'COUNTER', }, + 'clientin_djabberd_message' => { 'key' => 'ClientIn:DJabberd::Message', 'type' => 'COUNTER', }, + 'clientin_djabberd_presence' => { 'key' => 'ClientIn:DJabberd::Presence', 'type' => 'COUNTER', }, + 'clientin_djabberd_stanza_sasl' => { 'key' => 'ClientIn:DJabberd::Stanza::SASL', 'type' => 'COUNTER', }, + 'clientin_djabberd_stanza_starttls' => { 'key' => 'ClientIn:DJabberd::Stanza::StartTLS', 'type' => 'COUNTER', }, + 'iniq_get_info_query' => { 'key' => 'InIQ:get-{http://jabber.org/protocol/disco#info}query', 'type' => 'COUNTER', }, + 'iniq_get_items_query' => { 'key' => 'InIQ:get-{http://jabber.org/protocol/disco#items}query', 'type' => 'COUNTER', }, + 'iniq_get_roster_query' => { 'key' => 'InIQ:get-{jabber:iq:roster}query', 'type' => 'COUNTER', }, + 'iniq_get_bind' => { 'key' => 'InIQ:set-{urn:ietf:params:xml:ns:xmpp-bind}bind', 'type' => 'COUNTER', }, + 'iniq_get_session' => { 'key' => 'InIQ:set-{urn:ietf:params:xml:ns:xmpp-session}session', 'type' => 'COUNTER', }, + 'serverin_djabberd_stanza_dialback_result' => { 'key' => 'ServerIn:DJabberd::Stanza::DialbackResult', 'type' => 'COUNTER', }, + 'serverin_djabberd_stanza_dialback_verify' => { 'key' => 'ServerIn:DJabberd::Stanza::DialbackVerify', 'type' => 'COUNTER', }, + 'auth_success' => { 'key' => 'auth_success', 'type' => 'COUNTER', }, + 'c2s_message' => { 'key' => 'c2s-Message', 'type' => 'COUNTER', }, + 'c2s_presence' => { 'key' => 'c2s-Presence', 'type' => 'COUNTER', }, + 'connect' => { 'key' => 'connect', 'type' => 'COUNTER', }, + 'deliver_local' => { 'key' => 'deliver_local', 'type' => 'COUNTER', }, + 'deliver_s2s' => { 'key' => 'deliver_s2s', 'type' => 'COUNTER', }, + 'disconnect' => { 'key' => 'disconnect', 'type' => 'COUNTER', }, + }, + }, +}; + +if ( $0 =~ m/djabberd_(.*)$/ && $mode_ref->{$1} ) { + $mode_name = $1; + $mode = $mode_ref->{$mode_name}; +} +else { + print STDERR "ERROR: Unknown mode '$mode'. Exiting.\n"; + exit -1; +} + +if ( $ARGV[0] && $ARGV[0] eq 'suggest' ) { + print join( "\n", keys %$mode_ref ); + + exit 0; +} +elsif ( $ARGV[0] && $ARGV[0] eq "autoconf" ) { + my $result_ref = &query_djabberd( $djabberd_host, $djabberd_port, $mode ); + + if ($result_ref) { + print "yes\n"; + } + else { + print "no\n"; + } + + exit 0; +} +elsif ( $ARGV[0] and $ARGV[0] eq "config" ) { + print "graph_title " . $mode->{'title'} . "\n"; + print "graph_vlabel " . $mode->{'vlabel'} . "\n"; + print "graph_args -l 0\n"; + print "graph_category DJabberd\n"; + foreach my $field_name ( keys %{ $mode->{'fields'} } ) { + my $label = $mode->{'fields'}->{$field_name}->{'label'} || $field_name; + my $desc = $mode->{'fields'}->{$field_name}->{'description'} || $mode->{'fields'}->{$field_name}->{'key'}; + my $draw = $mode->{'fields'}->{$field_name}->{'draw'} || 'LINE1'; + my $type = $mode->{'fields'}->{$field_name}->{'type'} || 'COUNTER'; + + print $field_name. '.label ' . $label . "\n"; + print $field_name. '.description ' . $desc . "\n"; + print $field_name. '.draw ' . $draw . "\n"; + print $field_name. '.type ' . $type . "\n"; + } + + exit 0; +} +else { + my $result_ref = &query_djabberd( $djabberd_host, $djabberd_port, $mode ); + + foreach my $field_name ( keys %{ $mode->{'fields'} } ) { + my $key = $mode->{'fields'}->{$field_name}->{'key'}; + if ( defined( $result_ref->{$key} ) ) { # check for definedness, may well be zero (false for perl) + my $value = $result_ref->{$key}; + + # if there is a filter defined for this key apply it now + if ( exists( $mode->{'fields'}->{$field_name}->{'filter'} ) && ref( $mode->{'fields'}->{$field_name}->{'filter'} ) eq 'CODE' ) { + $value = &{ $mode->{'fields'}->{$field_name}->{'filter'} }($value); + } + print $field_name. ".value " . $value . "\n"; + } + } +} + +sub query_djabberd { + my ( $host, $port, $mode ) = @_; + + my $conn = IO::Socket::INET::->new( + PeerAddr => $host, + PeerPort => $port, + Proto => 'tcp', + Timeout => 5, + ) or die($!); + + my $request = $mode->{'cmd'} . "\n"; + + $conn->syswrite( $request, length($request) ); + + my @lines = (); + while ( my $line = $conn->getline() ) { + if ( $line =~ /^\./ ) { + last; + } + push( @lines, $line ); + } + close($conn); + + my $result_ref = {}; + foreach my $line (@lines) { + my ( $key, $value, $unit ) = split /\s+/, $line; + if ( $key && $value ) { + $result_ref->{$key} = $value; + } + } + + return $result_ref; +} + +# transform kb => bytes +sub kb2bytes { + + my $num = shift; + + if ( $num && $num =~ m/^\d+$/ ) { + $num *= 1024; + } + + return $num; +} From 4f432c597c8040a92a8e0a0a0951dc674fa8b633 Mon Sep 17 00:00:00 2001 From: Benjamin Ryzman Date: Thu, 23 Feb 2012 17:20:44 +0800 Subject: [PATCH 15/15] SNMP plugin to graph Brocade NetIron temperatures per module --- plugins/network/snmp__brocade_temp_module_ | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 plugins/network/snmp__brocade_temp_module_ diff --git a/plugins/network/snmp__brocade_temp_module_ b/plugins/network/snmp__brocade_temp_module_ new file mode 100755 index 00000000..9f2954e2 --- /dev/null +++ b/plugins/network/snmp__brocade_temp_module_ @@ -0,0 +1,88 @@ +#!/usr/bin/perl -w + +=head1 MAGIC MARKERS + + #%# family=snmpauto + #%# capabilities=snmpconf + +=cut + +use strict; +use Munin::Plugin; +use Munin::Plugin::SNMP; + +my $DEBUG=$ENV{'MUNIN_DEBUG'}; + +# This is the snmpwalk: +# snAgentTempSensorDescr.1.1 = STRING: "Line module 1, sensor 1 temperature" +# snAgentTempSensorDescr.1.2 = STRING: "Line module 1, sensor 2 temperature" +# snAgentTempSensorDescr.1.3 = STRING: "Line module 1, sensor 3 temperature" +# snAgentTempSensorDescr.1.4 = STRING: "Line module 1, sensor 4 temperature" +# snAgentTempSensorDescr.2.1 = STRING: "Line module 2, sensor 1 temperature" +# snAgentTempSensorDescr.2.2 = STRING: "Line module 2, sensor 2 temperature" +# snAgentTempSensorDescr.2.3 = STRING: "Line module 2, sensor 3 temperature" +# snAgentTempSensorDescr.2.4 = STRING: "Line module 2, sensor 4 temperature" +# snAgentTempSensorDescr.3.1 = STRING: "Active management module temperature" +# snAgentTempSensorDescr.3.2 = STRING: "Active management module temperature" +# snAgentTempValue.1.1 = INTEGER: 100 +# snAgentTempValue.1.2 = INTEGER: 106 +# snAgentTempValue.1.3 = INTEGER: 82 +# snAgentTempValue.1.4 = INTEGER: 72 +# snAgentTempValue.2.1 = INTEGER: 74 +# snAgentTempValue.2.2 = INTEGER: 102 +# snAgentTempValue.2.3 = INTEGER: 70 +# snAgentTempValue.2.4 = INTEGER: 74 +# snAgentTempValue.3.1 = INTEGER: 78 +# snAgentTempValue.3.2 = INTEGER: 84 + +my $brcdIp = '1.3.6.1.4.1.1991'; +my $snAgentTempTable = "$brcdIp.1.1.2.13.1"; +my $snAgentTempSensorDescr = "$snAgentTempTable.1.3"; +my $snAgentTempValue = "$snAgentTempTable.1.4"; + + +if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") { + print "index $snAgentTempTable.1.3.\n"; + print "require $snAgentTempSensorDescr. [1-9]\n"; + print "require $snAgentTempValue. [1-9]\n"; + exit 0; +} + +my $module = 0; + +if ($Munin::Plugin::me =~ /_module_(\d+)$/) { + $module = $1; +} else { + die "Could not determine module number from ".$Munin::Plugin::me."\n"; +} + +my ($session,$error); + +$session = Munin::Plugin::SNMP->session(-translate => [ -nosuchinstance => undef ]); + +my $sensor = 1; +if ($ARGV[0] and $ARGV[0] eq "config") { + my ($host,undef,$version) = Munin::Plugin::SNMP->config_session(); + + print "host_name $host\n" unless $host eq 'localhost'; + print "graph_title Module $module +graph_args --base 1000 --lower-limit 0 +graph_vlabel °C +graph_category system +graph_scale no\n"; + + my $descr = undef; + while (defined ($descr = $session->get_single("$snAgentTempSensorDescr.$module.$sensor"))) { + print "sensor$sensor.label $descr\n"; + $sensor ++; + } + exit 0; +} + +my $value = undef; +while (defined ($value = $session->get_single("$snAgentTempValue.$module.$sensor"))) { + $value /= 2; + print "sensor$sensor.value $value\n"; + $sensor++; +} +# vim:ft=perl