mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
Plugin-Gallery: Get better 2nd level headings
Review of category processes, system, snmp
This commit is contained in:
parent
4b400a7320
commit
e777037d06
27 changed files with 15 additions and 15 deletions
105
plugins/user/cpubyuser
Executable file
105
plugins/user/cpubyuser
Executable file
|
@ -0,0 +1,105 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Plugin to monitor CPU usage, for a selected set of users
|
||||
#
|
||||
# Usage: Place in /etc/munin/node.d/ (or link it there using ln -s)
|
||||
# Add this to your /etc/munin/plugin-conf.d/munin-node:
|
||||
# [cpubyuser]
|
||||
# env.USERS root yann
|
||||
#
|
||||
# If env.USERS is set to ALL, count all logged in users.
|
||||
#
|
||||
# root and yann being a list of the users to monitor.
|
||||
# You need to also make sure that awk is installed
|
||||
#
|
||||
# 2008-12-08 v 1.3.1 Hanisch Elián:
|
||||
# - support for dots in user names.
|
||||
# - fix labels
|
||||
#
|
||||
# 2008-12-01 v 1.3 Hanisch Elián:
|
||||
# - fixes, refactoring and code cleanup
|
||||
# - Users that use cpu but aren't in the USERS env var
|
||||
# are plotted as "others", set others.graph to 'no' if
|
||||
# you don't want this.
|
||||
#
|
||||
# 2008-03-20 v 1.2 fireball: fixed minor screwup, works now ^^
|
||||
#
|
||||
# 2008-01-09 v 1.1 fireball: fixed "-" in usernames, those get replaced by "_" now.
|
||||
# set usernames in config accordingly (that is with _)
|
||||
#
|
||||
#
|
||||
# Parameters understood:
|
||||
#
|
||||
# config (required)
|
||||
# autoconf (optional - used by munin-config)
|
||||
#
|
||||
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
. "$MUNIN_LIBDIR/plugins/plugin.sh"
|
||||
|
||||
OTHER_FIELD="others"
|
||||
[ "$USERS" = "ALL" ] && USERS=$(w --no-header | awk '{ print $1 }' | sort | uniq)
|
||||
|
||||
|
||||
if [ "$1" = "autoconf" ]; then
|
||||
if [ -n "$USERS" ]; then
|
||||
echo "yes"
|
||||
else
|
||||
echo "no (USERS setting is missing)"
|
||||
fi
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
echo "graph_args --base 1000 -r --lower-limit 0"
|
||||
echo "graph_title CPU usage, by user"
|
||||
echo "graph_category cpu"
|
||||
echo "graph_info This graph shows CPU usage, for monitored users."
|
||||
echo "graph_vlabel %"
|
||||
echo "graph_scale no"
|
||||
echo "graph_period second"
|
||||
user_fields="$(for user in $USERS; do clean_fieldname "$user" | tr '\n' ' '; done)"
|
||||
echo "graph_order $user_fields $OTHER_FIELD"
|
||||
for user in $USERS "$OTHER_FIELD"; do
|
||||
user_field="$(clean_fieldname "$user")"
|
||||
echo "${user_field}.label $user"
|
||||
echo "${user_field}.info CPU used by user $user"
|
||||
echo "${user_field}.type GAUGE"
|
||||
echo "${user_field}.draw AREASTACK"
|
||||
done
|
||||
exit
|
||||
fi
|
||||
|
||||
top -b -n 1 | sed '1,/^ *PID /d' | \
|
||||
awk -v USERS="$USERS" '
|
||||
# Store the CPU usage of each process - the mapping to the
|
||||
# user happens later. We cannot use the second column
|
||||
# (username) directly, since it may be abbreviated (ending
|
||||
# with "+").
|
||||
{ CPU_PER_PID[$1]=$9 }
|
||||
END {
|
||||
split(USERS, user_array)
|
||||
for (user_index in user_array) {
|
||||
user = user_array[user_index]
|
||||
# retrieve all process IDs belonging to the user
|
||||
"ps -u "user" -o pid --no-headers 2>/dev/null | tr \"\n\" \" \"" | getline pids
|
||||
user_cpu = 0
|
||||
split(pids, pid_array)
|
||||
# summarize the cpu usage of this usage
|
||||
for (pid_index in pid_array) {
|
||||
pid = pid_array[pid_index]
|
||||
user_cpu += CPU_PER_PID[pid]
|
||||
delete CPU_PER_PID[pid]
|
||||
}
|
||||
print user, user_cpu
|
||||
}
|
||||
# add all remaining cpu usages into "others"
|
||||
others_sum = 0
|
||||
for (other_usage in CPU_PER_PID) others_sum+=CPU_PER_PID[other_usage]
|
||||
print "'"$OTHER_FIELD"'", others_sum;
|
||||
}' | while read -r user count; do
|
||||
# apply fieldname cleanup
|
||||
echo "$(clean_fieldname "$user").value $count"
|
||||
done
|
45
plugins/user/multipsu
Executable file
45
plugins/user/multipsu
Executable file
|
@ -0,0 +1,45 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Script to monitor number of processes by user. Programs are configured
|
||||
# in /etc/munin/plugin-conf.d/munin-node
|
||||
#
|
||||
# Parameters:
|
||||
#
|
||||
# config (required)
|
||||
# autoconf (optional - used by lrrd-config)
|
||||
#
|
||||
# Configuration example
|
||||
#
|
||||
# [multipsu]
|
||||
# env.multipsunames root exim ftp
|
||||
#
|
||||
#
|
||||
# Magic markers (optional):
|
||||
#%# family=manual
|
||||
#%# capabilities=autoconf
|
||||
|
||||
if [ "$1" = "autoconf" ]; then
|
||||
if [ -z "$multipsunames" ]; then
|
||||
echo "Configuration required $multipsunames"
|
||||
else
|
||||
echo yes
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
|
||||
echo graph_title Number of selected processes
|
||||
echo 'graph_category processes'
|
||||
echo 'graph_args --base 1000 --vertical-label processes -l 0'
|
||||
for name in $multipsunames; do
|
||||
echo "$name.label $name"
|
||||
echo "$name.draw LINE2"
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for name in $multipsunames; do
|
||||
printf "$name.value "
|
||||
(pgrep -u "$name"; pgrep -U "$name") | sort -u | wc -l
|
||||
done
|
66
plugins/user/proc_mem_by_user
Executable file
66
plugins/user/proc_mem_by_user
Executable file
|
@ -0,0 +1,66 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# (c) 2015, Raphaël Droz <raphael.droz@gmail.com>
|
||||
# (c) 2014, Gilles Fauvie <gfauvie@opendbteam.com>
|
||||
# Based on the 'du_multidirs' plugin, written by Christian Kujau <lists@nerdbynature.de>
|
||||
#
|
||||
# Configure it by using the processes env var, i.e.:
|
||||
#
|
||||
# WARNING: SELINUX can block this plugin
|
||||
#
|
||||
# [proc_mem_by_user]
|
||||
# env.users munin-node jprod
|
||||
#
|
||||
# see bug:
|
||||
# http://munin-monitoring.org/ticket/921
|
||||
# /usr/share/munin/plugins/plugin.sh (clean_fieldname())
|
||||
|
||||
. "$MUNIN_LIBDIR/plugins/plugin.sh"
|
||||
users=${users:-munin-node}
|
||||
|
||||
|
||||
if [ "$1" = autoconf ]; then
|
||||
ok=1
|
||||
[ -z "$users" ] && ok=0
|
||||
|
||||
for user in $users; do
|
||||
ps u -U "$user" 1> /dev/null 2>&1 || ok=0
|
||||
done
|
||||
|
||||
if [ $ok = 1 ]; then echo yes
|
||||
else echo no; fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" = config ]; then
|
||||
cat <<EOF
|
||||
graph_title Memory usage by process by user
|
||||
graph_args --base 1024 -l 0
|
||||
graph_vlabel Bytes
|
||||
graph_category memory
|
||||
graph_info This graph shows the memory usage of several processes of one user
|
||||
graph_order $(echo "$users"|sed 's/\broot\b/__root/g')
|
||||
EOF
|
||||
|
||||
for user in $users; do
|
||||
munin_safe_name=$(clean_fieldname "$user")
|
||||
cat<<EOF
|
||||
$munin_safe_name.label $user
|
||||
$munin_safe_name.info $user
|
||||
$munin_safe_name.min 0
|
||||
$munin_safe_name.draw LINESTACK2
|
||||
$munin_safe_name.type GAUGE
|
||||
EOF
|
||||
done
|
||||
|
||||
# echo "$u".warning 0
|
||||
# echo "$u".critical 0
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for user in $users; do
|
||||
munin_safe_name=$(clean_fieldname "$user")
|
||||
sum=$(ps u -U "$user" | awk 'BEGIN { sum = 0 } NR > 1 { sum += $6 }; END { print sum * 1024 }')
|
||||
echo "$munin_safe_name.value ${sum:-U}"
|
||||
done
|
Loading…
Add table
Add a link
Reference in a new issue