root / plugins / lxc / lxc_ram @ aaee0699
Historique | Voir | Annoter | Télécharger (2,9 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# -*- sh -*- |
| 3 |
|
| 4 |
: << =cut |
| 5 |
|
| 6 |
=head1 NAME |
| 7 |
|
| 8 |
lxc_ram - Plugin to monitor LXC memory usage. |
| 9 |
|
| 10 |
=head1 CONFIGURATION |
| 11 |
|
| 12 |
[lxc_*] |
| 13 |
user root |
| 14 |
|
| 15 |
[lxc_ram] |
| 16 |
env.areastack true |
| 17 |
|
| 18 |
=head1 INTERPRETATION |
| 19 |
|
| 20 |
This plugin needs root privilege. |
| 21 |
|
| 22 |
If env.areastack is set to true, all memory usages of containers will be |
| 23 |
drawn as stacked area charts. |
| 24 |
This option changes graph order, all of 'Mem usage' comes first and then others. |
| 25 |
(default: false) |
| 26 |
|
| 27 |
=head1 AUTHOR |
| 28 |
|
| 29 |
vajtsz vajtsz@gmail.com |
| 30 |
mitty mitty@mitty.jp |
| 31 |
|
| 32 |
=head1 LICENSE |
| 33 |
|
| 34 |
Unknown license |
| 35 |
|
| 36 |
=head1 MAGIC MARKERS |
| 37 |
|
| 38 |
#%# family=auto |
| 39 |
#%# capabilities=autoconf |
| 40 |
|
| 41 |
=cut |
| 42 |
|
| 43 |
|
| 44 |
# configurable: true/false |
| 45 |
areastack=${areastack:-false}
|
| 46 |
|
| 47 |
|
| 48 |
# shellcheck disable=SC1090 |
| 49 |
. "$MUNIN_LIBDIR/plugins/plugin.sh" |
| 50 |
|
| 51 |
|
| 52 |
guest_names=$(lxc-ls | sort -u) |
| 53 |
for guest in $guest_names; do |
| 54 |
if lxc-info -n "$guest" 2>&1 | grep -qs RUNNING ; then |
| 55 |
active="$active $guest" |
| 56 |
fi |
| 57 |
done |
| 58 |
guest_names="$active" |
| 59 |
|
| 60 |
|
| 61 |
f_comm='lxc-cgroup ' |
| 62 |
|
| 63 |
if [ "$1" = "autoconf" ]; then |
| 64 |
if [ -r /proc/stat ]; then |
| 65 |
echo yes |
| 66 |
else |
| 67 |
echo "no (no /proc/stat)" |
| 68 |
fi |
| 69 |
exit 0 |
| 70 |
fi |
| 71 |
|
| 72 |
if [ "$1" = "config" ]; then |
| 73 |
|
| 74 |
echo 'graph_title Memory ' |
| 75 |
echo 'graph_args -l 0 --base 1024' |
| 76 |
echo 'graph_vlabel byte' |
| 77 |
echo 'graph_category memory' |
| 78 |
|
| 79 |
if [ "$areastack" = "true" ]; then |
| 80 |
for guest_name in $guest_names; do |
| 81 |
guest="$(clean_fieldname "$guest_name")" |
| 82 |
|
| 83 |
echo "mem_usage_$guest.label $guest_name: Mem usage" |
| 84 |
echo "mem_usage_$guest.type GAUGE" |
| 85 |
echo "mem_usage_$guest.draw AREASTACK" |
| 86 |
done |
| 87 |
|
| 88 |
for guest_name in $guest_names; do |
| 89 |
guest="$(clean_fieldname "$guest_name")" |
| 90 |
|
| 91 |
echo "mem_cache_$guest.label $guest_name: Cache" |
| 92 |
echo "mem_cache_$guest.type GAUGE" |
| 93 |
echo "mem_active_$guest.label $guest_name: Active" |
| 94 |
echo "mem_active_$guest.type GAUGE" |
| 95 |
echo "mem_inactive_$guest.label $guest_name: Inactive" |
| 96 |
echo "mem_inactive_$guest.type GAUGE" |
| 97 |
|
| 98 |
done |
| 99 |
else |
| 100 |
for guest_name in $guest_names; |
| 101 |
do |
| 102 |
guest="$(clean_fieldname "$guest_name")" |
| 103 |
|
| 104 |
echo "mem_usage_$guest.label $guest_name: Mem usage" |
| 105 |
echo "mem_usage_$guest.type GAUGE" |
| 106 |
echo "mem_cache_$guest.label $guest_name: Cache" |
| 107 |
echo "mem_cache_$guest.type GAUGE" |
| 108 |
echo "mem_active_$guest.label $guest_name: Active" |
| 109 |
echo "mem_active_$guest.type GAUGE" |
| 110 |
echo "mem_inactive_$guest.label $guest_name: Inactive" |
| 111 |
echo "mem_inactive_$guest.type GAUGE" |
| 112 |
|
| 113 |
done |
| 114 |
fi |
| 115 |
|
| 116 |
exit 0 |
| 117 |
fi |
| 118 |
|
| 119 |
|
| 120 |
for guest_name in $guest_names; do |
| 121 |
guest="$(clean_fieldname "$guest_name")" |
| 122 |
|
| 123 |
value=$($f_comm -n "$guest_name" memory.usage_in_bytes) |
| 124 |
echo "mem_usage_$guest.value $value" |
| 125 |
|
| 126 |
value=$($f_comm -n "$guest_name" memory.stat | grep total_cache | awk '{print($2)}')
|
| 127 |
echo "mem_cache_$guest.value $value" |
| 128 |
|
| 129 |
value=$($f_comm -n "$guest_name" memory.stat | grep total_active_anon | awk '{print($2)}')
|
| 130 |
echo "mem_active_$guest.value $value" |
| 131 |
|
| 132 |
value=$($f_comm -n "$guest_name" memory.stat | grep total_inactive_anon | awk '{print($2)}')
|
| 133 |
echo "mem_inactive_$guest.value $value" |
| 134 |
done |
