1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00
This commit is contained in:
Nye Liu 2016-11-05 14:15:25 -07:00
commit 43f5345747
7 changed files with 418 additions and 60 deletions

View file

@ -1,52 +1,135 @@
#!/bin/sh
#
# Plugin to show Postfix statistics - needs pflogsumm
#
# Contributed by David Obando (david@cryptix.de) - 16.04.2007
#
#
# Magic markers - optional - used by installation scripts and
# munin-config:
#
#%# family=manual
#%# capabilities=autoconf
# -*- sh -*-
: <<=cut
=head1 NAME
postfix_stats - Munin plugin to monitor postfix statistics.
=head1 APPLICABLE SYSTEMS
Any system where pflogsumm script can be executed.
=head1 CONFIGURATION
There is no default configuration. This is an example config for Ubuntu:
[postfix_stats]
env.logfiles /var/log/syslog /var/log/syslog.1
env.pflogsumm pflogsumm
env.logfiles contains space separated syslog logfiles, usually current log
and previous log. You can add more log files if you want, but this may
increase the time required for analysis.
env.pflogsumm The "pflogsumm" script, can be pflogsumm.pl if it was manually
downloaded and installed, or "pflogsumm" if it was installed by a package
manager (like apt-get).
=head1 INTERPRETATION
This plugin displays the messages: received, delivered, rejected...
Average per minute is made and it shows the total message count.
It is useful to know the load and messages being processed.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 VERSION
0.2 plugin completely rewritten
0.1 first release.
=head1 BUGS
None known
=head1 AUTHOR
Originally: David Obando (david@cryptix.de)
Modified by: github.com/cristiandeluxe
Thanks to: sumpfralle
=head1 LICENSE
GPLv2
=cut
#set -xv
SYS_LOG="${logfiles:-/var/log/syslog /var/log/syslog.0}"
case $1 in
config)
cat <<'EOF'
system.type COUNTER
graph_title Postfix statistics
graph_vlabel Postfix statistics
graph_category Mail
graph_total Total
received.label received
delivered.label delivered
forwarded.label forwarded
deferred.label deferred
bounced.label bounced
rejected.label rejected
held.label held
discarded.label discarded
EOF
exit 0;;
esac
# shellcheck disable=SC2154
PFLOGSUMM="${pflogsum}"
[ -z "$PFLOGSUMM" ] && PFLOGSUMM="$(which pflogsumm pflogsumm.pl | head -1)"
# Fields (Array to avoid code duplication) must be space separated
FIELDS_ARR="received delivered forwarded deferred bounced rejected held discarded"
TMP=`mktemp /tmp/tmp.XXXXXXXX`
pflogsumm.pl --smtpd_stats -d today /var/log/syslog /var/log/syslog.0 | head -n 15 > $TMP
#
# Autoconf Section
#
if [ "$1" = 'autoconf' ]; then
# Check if pflogsumm exist
if [ -z "${PFLOGSUMM}" ]
then
echo 'no (pflogsum not found in your system)'
else
echo 'yes'
fi
exit 0
fi
cat <<EOF
#
# Config Section
#
if [ "$1" = 'config' ]; then
echo 'graph_title Postfix statistics'
echo 'graph_vlabel Postfix statistics'
echo 'graph_category mail'
echo 'graph_scale no'
echo 'graph_period minute'
echo 'graph_total Total'
received.value `grep 'received' $TMP | awk '{print $1}'`
delivered.value `grep 'delivered' $TMP | awk '{print $1}'`
forwarded.value `grep 'forwarded' $TMP | awk '{print $1}'`
deferred.value `grep 'deferred' $TMP | awk '{print $1}'`
bounced.value `grep 'bounced' $TMP | awk '{print $1}'`
rejected.value `grep 'rejected' $TMP | awk '{print $1}'`
held.value `grep 'held' $TMP | awk '{print $1}'`
discarded.value `grep 'discarded' $TMP | awk '{print $1}'`
EOF
# Generate config for each field
for i in $FIELDS_ARR; do
echo "${i}.label ${i}"
echo "${i}.type DERIVE"
echo "${i}.min 0"
echo "${i}.draw AREASTACK"
done
rm $TMP
exit 0
fi
#
# Plugin Script
#
# Variable to store the pflogsumm result.
# shellcheck disable=SC2086
TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill ${SYS_LOG})
# Parse value from Raw result
#
# Return digit if regex are parsed correctly
#
# Return U (undefined) if any error occurs
#
parseValue() {
# shellcheck disable=SC2155
local TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei "^[[:space:]]+[[:digit:]]+[[:space:]]+${1}.*$" | grep -oEi '[[:digit:]]+[[:space:]]+' | head -n 1 | sed 's: ::g')
if [ -z "${TMP_RETURN}" ]; then
echo 'U'
else
echo "${TMP_RETURN}"
fi
}
# Print results
for i in $FIELDS_ARR; do
printf "%s.value " "${i}"
parseValue "${i}"
done

View file

@ -1,4 +1,4 @@
#!/usr/bin/env /usr/local/bin/python2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: set sts=4 sw=4 encoding=utf-8
@ -33,11 +33,13 @@
#%# capabilities=suggest autoconf
from pymongo import Connection
import pymongo
from operator import itemgetter
settings_host = '127.0.0.1'
settings_port = 27017
# mongodb_uri will override host and port
settings_mongodb_uri = ''
settings_db = 'mydb'
settings_user = ''
settings_password = ''
@ -50,6 +52,7 @@ typeIndex['collcount']['title'] = 'per collection document count'
typeIndex['collcount']['yaxis'] = 'documents'
typeIndex['collcount']['base'] = '1000'
typeIndex['collcount']['scale'] = '--logarithmic -l1'
typeIndex['collcount']['category'] = 'MongoDB'
typeIndex['collsize'] = {}
typeIndex['collsize']['index'] = 'size'
@ -57,6 +60,7 @@ typeIndex['collsize']['title'] = 'per collection data size'
typeIndex['collsize']['yaxis'] = 'Byte'
typeIndex['collsize']['base'] = '1024'
typeIndex['collsize']['scale'] = '--logarithmic -l1 --units=si'
typeIndex['collsize']['category'] = 'MongoDB'
typeIndex['avgsize'] = {}
typeIndex['avgsize']['index'] = 'avgObjSize'
@ -64,6 +68,7 @@ typeIndex['avgsize']['title'] = 'average object size'
typeIndex['avgsize']['yaxis'] = 'Byte'
typeIndex['avgsize']['base'] = '1024'
typeIndex['avgsize']['scale'] = '--logarithmic --units=si'
typeIndex['avgsize']['category'] = 'MongoDB'
typeIndex['storage'] = {}
typeIndex['storage']['index'] = 'storageSize'
@ -71,6 +76,7 @@ typeIndex['storage']['title'] = 'per collection storage size'
typeIndex['storage']['yaxis'] = 'Byte'
typeIndex['storage']['base'] = '1024'
typeIndex['storage']['scale'] = '--logarithmic -l1 --units=si'
typeIndex['storage']['category'] = 'MongoDB'
typeIndex['indexsize'] = {}
typeIndex['indexsize']['index'] = 'totalIndexSize'
@ -78,11 +84,14 @@ typeIndex['indexsize']['title'] = 'per collection index size'
typeIndex['indexsize']['yaxis'] = 'Byte'
typeIndex['indexsize']['base'] = '1024'
typeIndex['indexsize']['scale'] = '--logarithmic -l 1 --units=si'
typeIndex['indexsize']['category'] = 'MongoDB'
def getCollstats(graphtype):
con = Connection(settings_host, int(settings_port), slave_okay=True)
if settings_mongodb_uri:
con = pymongo.MongoClient(settings_mongodb_uri)
else:
con = pymongo.MongoClient(settings_host, int(settings_port))
if settings_user:
db = con['admin']
@ -106,7 +115,7 @@ def getCollstats(graphtype):
stats_tmp[collname]['value'] += long(stats[typeIndex[graphtype]['index']])
con.disconnect()
con.close()
for collname, item in sorted(stats_tmp.items()):
yield ("%s" % collname, item['value'], item['dbname'])

View file

@ -25,7 +25,7 @@ import pymongo
def _get_members():
host = os.environ.get('host', '127.0.0.1')
port = os.environ.get('port', 27017)
conn = pymongo.Connection(host,port)
conn = pymongo.MongoClient(host,port)
repl_status = conn.admin.command("replSetGetStatus")
members = {}

View file

@ -16,25 +16,50 @@ graph_title UDP Statistics
graph_args --base 1000 -l 0
graph_vlabel Packets/\${graph_period}
graph_category network
received.label Received
received.draw AREA
received.type DERIVE
received.min 0
errors.label Errors
errors.draw LINE1
errors.type DERIVE
errors.min 0
sent.label Sent
sent.draw LINE1
sent.type DERIVE
sent.min 0
received.label Received
received.draw AREA
received.type DERIVE
received.min 0
unknown_ports.label In Unknown Port
unknown_ports.draw LINE1
unknown_ports.type DERIVE
unknown_ports.min 0
receive_buffer_errors.label Receive Buffer Errors
receive_buffer_errors.draw LINE1
receive_buffer_errors.type DERIVE
receive_buffer_errors.min 0
send_buffer_errors.label Send Buffer Errors
send_buffer_errors.draw LINE1
send_buffer_errors.type DERIVE
send_buffer_errors.min 0
in_csum_errors.label In CSUM Errors
in_csum_errors.draw LINE1
in_csum_errors.type DERIVE
in_csum_errors.min 0
ignored_multis.label In Ignored Multis
ignored_multis.draw LINE1
ignored_multis.type DERIVE
ignored_multis.min 0
receive_errors.label Receive Errors
receive_errors.draw LINE1
receive_errors.type DERIVE
receive_errors.min 0
EOM
exit 0;
}
}
@netstat = qx{/bin/netstat -us | awk '/packets sent/ \{ print "sent.value " \$1 \}
@netstat = qx{/bin/netstat -us | grep -A8 '^Udp:' | awk '/packets sent/ \{ print "sent.value " \$1 \}
/packets received/ \{ print "received.value " \$1 \}
/packet receive errors/ \{ print "errors.value " \$1 \}'};
/packets to unknown port received/ \{ print "unknown_ports.value " \$1 \}
/receive buffer errors/ \{ print "receive_buffer_errors.value " \$1 \}
/send buffer errors/ \{ print "send_buffer_errors.value " \$1 \}
/InCsumErrors/ \{ print "in_csum_errors.value " \$2 \}
/IgnoredMulti/ \{ print "ignored_multis.value " \$2 \}
/packet receive errors/ \{ print "receive_errors.value " \$1 \}'};
print @netstat;
print @netstat;

83
plugins/system/deborphan Executable file
View file

@ -0,0 +1,83 @@
#!/bin/sh
: << =cut
=head1 NAME
deborphan - Monitor orphaned Debian packages
=head1 APPLICABLE SYSTEMS
Debian-ish systems with deborphan installed.
=head1 CONFIGURATION
None needed.
=head1 AUTHOR
Olivier Mehani <shtrom+munin@ssji.net>
Based on the debsecan plugin by Nicolas Bouthors. 2016-09-02
=head1 LICENSE
GPLv2
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
# shellcheck disable=SC1090
. "$MUNIN_LIBDIR/plugins/plugin.sh"
# Auto enable if we have deborphan only
if [ "$1" = "autoconf" ] ; then
if which deborphan >/dev/null; then
echo yes
else
echo "no (deborphan is missing)"
fi
exit 0
fi
# Fail if we don't have deborphan
if ! which deborphan >/dev/null; then
echo "deborphan is missing" >&2
exit 1
fi
OUT=$(deborphan --show-section --guess-all | sort)
CATEGORIES="$(echo "${OUT}" | awk '{print $1}' | uniq)"
if [ "$1" = "config" ]; then
cat <<EOF
graph_title Orphaned packages
graph_args -l 0 --base 1000
graph_vlabel number of packages
graph_category system
graph_period second
graph_info This graph show the number of orphaned packages on your system. Use deborphan to see details.
EOF
for CAT in ${CATEGORIES}; do
CATFIELD=$(clean_fieldname "${CAT}")
cat <<EOF
${CATFIELD}.label ${CAT}
${CATFIELD}.type GAUGE
${CATFIELD}.draw AREASTACK
${CATFIELD}.min 0
${CATFIELD}.info The number of orphaned packages in ${CAT}
EOF
done
else
for CAT in ${CATEGORIES}; do
CATFIELD=$(clean_fieldname "${CAT}")
CATDATA=$(echo "${OUT}" | sed -n "s#${CAT} \+##p")
echo "${CATFIELD}.value $(echo "${CATDATA}" | wc -l)"
echo "${CATFIELD}.extinfo $(echo "${CATDATA}" | tr '\n' ' ')"
done
fi

74
plugins/system/file_length_ Executable file
View file

@ -0,0 +1,74 @@
#!/bin/sh
: << =cut
=head1 NAME
file_length_ - Plugin to monitor the length of specified files
Useful for things such as lists (white, black, user, ...).
=head1 CONFIGURATION
[file_length_IDENTIFIER]
env.files FILEPATHGLOB1 FILEPATHGLOB2 ...
env.category DEFAULTS_TO_system
env.title OPTIONAL_TITLE
env.logarithmic 1
=head1 AUTHOR
Olivier Mehani <shtrom+munin@ssji.net> (based on disk/log_sizes)
=head1 LICENSE
GPLv2
=head1 MAGIC MARKERS
#%# family=manual
=cut
# needs shellcheck -x /usr/share/munin/plugins/plugin.sh
# shellcheck source=/usr/share/munin/plugins/plugin.sh
. "$MUNIN_LIBDIR/plugins/plugin.sh"
NAME=$(echo "$0" | sed 's/.*_//')
TITLE=${title:-File lengths for $NAME}
CATEGORY=${category:-system}
FILES=${files:-/var/log/messages}
# we want globbing to happen here
# shellcheck disable=SC2116 disable=SC2086
FILES=$(echo $FILES)
if [ "$1" = "config" ] ; then
# shellcheck disable=SC2154
if [ "${logarithmic}" = "1" ]; then
graph_args="-o"
else
graph_args="-l 0"
fi
cat <<EOF
graph_title ${TITLE}
graph_args ${graph_args} --base 1000
graph_category ${CATEGORY}
graph_info This graph shows the length of ${FILES}
graph_vlabel length (lines)
EOF
for F in $FILES; do
MF=$(clean_fieldname "$F")
BF=$(basename "$F")
echo "$MF.label ${BF}"
done
else
for F in $FILES; do
MF=$(echo "$F" | sed 's/[-\/\.]/_/g')
echo "$MF.value $(wc -l < "$F")"
echo "$MF.extinfo $(stat --printf="%sB\n" "$F")"
done
fi

84
plugins/system/systemd_units Executable file
View file

@ -0,0 +1,84 @@
#!/bin/sh
# -*- sh -*-
: << =cut
=head1 NAME
systemd - Plugin to monitor systemd units state
=head1 APPLICABLE SYSTEMS
Linux systems with systemd installed.
=head1 CONFIGURATION
None needed.
=head1 AUTHOR
Olivier Mehani <shtrom+munin@ssji.net>
=head1 LICENSE
GPLv2
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
states="active \
reloading \
inactive \
failed \
activating \
deactivating"
autoconf() {
which systemctl >/dev/null && \
systemctl --state=failed --no-pager --no-legend >/dev/null 2>&1 && echo yes || echo "no (No systemctl or error running it)"
}
config () {
cat << EOF
graph_title Systemd units state
graph_args -l 0
graph_category system
graph_scale no
graph_vlabel units
EOF
for state in $states; do
echo "$state.label $state"
echo "$state.draw AREASTACK"
if [ "$state" = "failed" ]; then
echo "$state.warning 0"
echo "$state.critical 10"
fi
done
}
fetch () {
tmp=$(systemctl --no-pager --no-legend --all | awk '{print $1, $3}')
for state in $states ; do
count=$(echo "$tmp" | grep -c "$state$")
echo "$state.value $count"
extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1 | tr '\n' ' ')
if [ -n "$extinfo" ]; then
echo "$state.extinfo" "$extinfo"
fi
done
}
case $1 in
"autoconf")
autoconf
;;
"config")
config
;;
*)
fetch
;;
esac