Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / vserver / vserver_jiffies @ 17f78427

Historique | Voir | Annoter | Télécharger (2,68 ko)

1
#!/bin/zsh
2
#
3
# Created by Jan Rękorajski <baggins@pld-linux.org> based on vserver_cpu_ plugin.
4
#
5
# Obtained from https://github.com/munin-monitoring/contrib.git
6
#
7
# Changes by Andras Korn, 2015:
8
#
9
#  * Convert to zsh
10
#  * Fix to remove dots from vserver names (replace them with _)
11
#  * Drop support for old (pre 2.6.19) kernels
12
#  * Replace cat | grep | cut pipelines with a single sed
13
#  * Add env.stripdomain (a domain name to strip from the
14
#    end of vserver names when generating labels; be sure
15
#    to include the leading dot)
16
#
17
# Graph Vserver cumulative cpu usage stats
18
#
19
# Configuration variables
20
#   vservers - specify the vservers to include in the graph (default: all)
21
#
22
# NOTE: If no configuration variable is set, the default will be used
23
#
24
# see vserver_resources for example uses of configuration files
25

    
26
VSERVERS=(${=vservers})
27
STRIPDOMAIN="$stripdomain"
28

    
29
INFO=($(sed 's/.*:\t//' /proc/virtual/info 2>/dev/null || echo '<none>'))
30

    
31
NAMELOC="nsproxy"
32

    
33
if [[ -z "$VSERVERS" ]] ; then
34
    cd /proc/virtual
35
    XIDS=($(echo *(/)))
36
else
37
    # it's really more performant to specify vservers by ids or by linking but not in the configuration-file by name
38
    XIDS=""
39
    for i in $VSERVERS[@] ; do
40
	if [[ -d /proc/virtual/$i ]] ; then
41
	    XIDS=($XIDS[@] $i)
42
	else
43
	    for j in /proc/virtual/*(/) -type d; do
44
	    	if [[ "$i" = $(sed -n '/NodeName/s/^NodeName:[[:space:]]*//p' $j/$NAMELOC) ]]; then
45
		    XIDS=($XIDS[@] ${j:t})
46
		fi
47
	    done
48
	fi
49
    done
50
fi
51

    
52
if [[ "$1" = "config" ]]; then
53
	echo 'graph_category virtualization'
54
	echo 'graph_args --base 1000'
55
	echo 'graph_title Vserver cpu usage'
56
	echo 'graph_vlabel jiffies used per ${graph_period}'
57
	echo 'graph_info Shows jiffies used on each vserver.'
58

    
59
	for i in $XIDS[@]; do
60
		LABEL=$(sed -n '/NodeName/s/^NodeName:[[:space:]]*//p' /proc/virtual/$i/$NAMELOC)
61
		LABEL=${LABEL%$STRIPDOMAIN}
62
		NAME=${LABEL//./_}
63
		NAME=${NAME//-/_}
64
		echo "${NAME}_hold.label on hold for cpu on $LABEL"
65
		echo "${NAME}_hold.info on hold for cpu on $LABEL."
66
		echo "${NAME}_hold.type COUNTER"
67
		echo "${NAME}_scpu.label system cpu usage for $LABEL"
68
		echo "${NAME}_scpu.info system cpu usage for $LABEL."
69
		echo "${NAME}_scpu.type COUNTER"
70
		echo "${NAME}_ucpu.label user cpu usage for $LABEL"
71
		echo "${NAME}_ucpu.info user cpu usage for $LABEL."
72
		echo "${NAME}_ucpu.type COUNTER"
73
	done
74
	exit 0
75
fi
76

    
77
for i in $XIDS[@]; do
78
	LABEL=$(sed -n '/NodeName/s/^NodeName:[[:space:]]*//p' /proc/virtual/$i/$NAMELOC)
79
	LABEL=${LABEL%$STRIPDOMAIN}
80
	NAME=${LABEL//./_}
81
	NAME=${NAME//-/_}
82
	awk -v name=$NAME -v u=0 -v s=0 -v h=0 '
83
		/^cpu [0-9]+:/ { u+=$3; s+=$4; h+=$5}
84
		END {
85
			print name "_hold.value " h
86
			print name "_scpu.value " s
87
			print name "_ucpu.value " u
88
		}' /proc/virtual/$i/sched
89
done