Projet

Général

Profil

Révision 9859adc7

ID9859adc79e81fd675b59afc9470a39b083dc0fea
Parent c9bc1c1d
Enfant f6ae9cd7

Ajouté par Sergey Urushkin il y a presque 14 ans

Initial version

Voir les différences:

plugins/other/services
1
#!/bin/sh
2
# -*- sh -*-
3

  
4
: << =cut
5

  
6
=head1 NAME
7

  
8
services - Plugin to monitor number of processes of different services
9

  
10
=head1 CONFIGURATION
11

  
12
This plugin uses the following configuration variables
13

  
14
 [services]
15
   env.datafile		- Path to file which contains list of services (default: /root/munin/services.list)
16

  
17
Datafile should contain lines which are used to detect number of running processes (ps ax | grep "LINE FROM FILE").
18
If a number of processes of some service is below 1 (e.g. 0) critical event happens (configure your munin.conf about "contact.NAME.command" to send mail or something else;
19
also nice line is 'contact.NAME.always_send critical' - not to stop sending alerts after critical event appears the first time).
20

  
21
Datafile may contain comment lines (begin with "#"), empty lines and even regular expressions (WARNING - not tested, use carefully)
22
Example of datafile:
23
#############################
24
# This line is a comment and next lines are names of some services
25
sshd
26
smbd
27
nmbd
28
lighttpd
29
# Next line is an empty line
30

  
31
named
32
# Next line is a name of service with a path
33
/usr/local/sbin/upsd
34
# Next line is a line with spaces
35
BackupPC -d
36
#############################
37

  
38
This plugin does not draw any graphs. It is only written to send alerts via mail or something else.
39

  
40
=head1 AUTHOR
41

  
42
Copyright (C) 2010, Sergey Urushkin
43

  
44
=head1 LICENSE
45

  
46
GPLv3
47

  
48
=head1 MAGIC MARKERS
49

  
50
 #%# family=contrib
51
 #%# capabilities=autoconf
52

  
53
=cut
54

  
55
DATAFILE=${datafile:-/root/munin/services.list}
56

  
57
SERVICES=`[ -r "$DATAFILE" ] && grep -v '^[[:space:]]*\(#.*\|\)$' "$DATAFILE" | sed 's/[[:space:]]/___/g'`
58

  
59
[ -z "$SERVICES" ] && echo "Datafile is empty or not readable" 2>&1 && exit 1
60

  
61
if [ "$1" = "autoconf" ]
62
then
63
    echo "yes"
64
    exit 0
65
fi
66

  
67
if [ "$1" = "config" ]
68
then
69
    echo "graph_title Running services"
70
    echo "graph no"
71
    for SERV in ${SERVICES}
72
    do
73
	SERVW=`echo "$SERV" | sed 's/___/ /g'`
74
	echo "$SERV.label $SERVW"
75
	echo "$SERV.critical 1:"
76
    done
77
    exit 0
78
fi
79

  
80
for SERV in ${SERVICES}
81
do
82
    SERVW=`echo "$SERV" | sed 's/___/[[:space:]]*/g'`
83
    VALUE=`ps ax | grep "$SERVW" | grep -v grep | wc -l | tr -d '[[:space:]]'`
84
    echo "$SERV.value $VALUE"
85
done

Formats disponibles : Unified diff