#!/bin/bash
#
# Munin-plugin to monitor the processes priority on a Linux machine.
#
# Parameters understood:
#
#	config		(required)
#	autoconf	(optional - used by munin-config)
#
# GNU GPL, Lars Strand
#
# Magick markers (optional - used by munin-config and som installation
# scripts):
#
#%# family=auto
#%# capabilities=autoconf

if [ "$1" = "autoconf" ]; then
	echo yes
	exit 0
fi

if [ "$1" = "config" ]; then
    echo 'graph_title Processes priority'
    echo 'graph_order low high locked'
    echo 'graph_category processes'
    echo 'graph_info This graph shows the processes priority'
    echo 'graph_args --base 1000 -l 0'
    echo 'high.label high priority'
    echo 'high.draw STACK'
    echo 'high.info The number of high-priority processes (tasks)'
    echo 'low.label low priority'
    echo 'low.draw AREA'
    echo 'low.info The number of low-priority processes (tasks)'
    echo 'locked.label locked in memory'
    echo 'locked.draw STACK'
    echo 'locked.info The number of processes that have pages locked into memory (for real-time and custom IO)'
    exit 0
fi

echo -n "high.value "
ps --no-header -eo stat | grep \< | wc -l
echo -n "low.value "
ps --no-header -eo stat | grep N | wc -l
echo -n "locked.value "
ps --no-header -eo stat | grep L | wc -l
