root / plugins / lxc / lxc_ram @ aaee0699
Historique | Voir | Annoter | Télécharger (2,9 ko)
| 1 | e3c40a04 | Bjoern Boschman | #!/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 | 5dc3787f | Ken-ichi Mito | [lxc_ram] |
| 16 | 58e5b2f3 | Ken-ichi Mito | env.areastack true |
| 17 | 5dc3787f | Ken-ichi Mito | |
| 18 | e3c40a04 | Bjoern Boschman | =head1 INTERPRETATION |
| 19 | |||
| 20 | This plugin needs root privilege. |
||
| 21 | |||
| 22 | 58e5b2f3 | Ken-ichi Mito | If env.areastack is set to true, all memory usages of containers will be |
| 23 | 5dc3787f | Ken-ichi Mito | drawn as stacked area charts. |
| 24 | This option changes graph order, all of 'Mem usage' comes first and then others. |
||
| 25 | 58e5b2f3 | Ken-ichi Mito | (default: false) |
| 26 | 5dc3787f | Ken-ichi Mito | |
| 27 | e3c40a04 | Bjoern Boschman | =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 | aaee0699 | Lars Kruse | # 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 | e3c40a04 | Bjoern Boschman | for guest in $guest_names; do |
| 54 | aaee0699 | Lars Kruse | if lxc-info -n "$guest" 2>&1 | grep -qs RUNNING ; then |
| 55 | e3c40a04 | Bjoern Boschman | 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 | aaee0699 | Lars Kruse | exit 0 |
| 70 | e3c40a04 | Bjoern Boschman | 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 | ff883dee | dipohl | echo 'graph_category memory' |
| 78 | e3c40a04 | Bjoern Boschman | |
| 79 | 58e5b2f3 | Ken-ichi Mito | if [ "$areastack" = "true" ]; then |
| 80 | 5dc3787f | Ken-ichi Mito | for guest_name in $guest_names; do |
| 81 | aaee0699 | Lars Kruse | guest="$(clean_fieldname "$guest_name")" |
| 82 | 5dc3787f | Ken-ichi Mito | |
| 83 | 8a5b34c9 | Lars Kruse | echo "mem_usage_$guest.label $guest_name: Mem usage" |
| 84 | echo "mem_usage_$guest.type GAUGE" |
||
| 85 | echo "mem_usage_$guest.draw AREASTACK" |
||
| 86 | 5dc3787f | Ken-ichi Mito | done |
| 87 | 1c412d19 | Ken-ichi Mito | |
| 88 | for guest_name in $guest_names; do |
||
| 89 | aaee0699 | Lars Kruse | guest="$(clean_fieldname "$guest_name")" |
| 90 | e3c40a04 | Bjoern Boschman | |
| 91 | 8a5b34c9 | Lars Kruse | 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 | e3c40a04 | Bjoern Boschman | |
| 98 | done |
||
| 99 | 1c412d19 | Ken-ichi Mito | else |
| 100 | for guest_name in $guest_names; |
||
| 101 | do |
||
| 102 | aaee0699 | Lars Kruse | guest="$(clean_fieldname "$guest_name")" |
| 103 | 1c412d19 | Ken-ichi Mito | |
| 104 | 8a5b34c9 | Lars Kruse | 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 | 1c412d19 | Ken-ichi Mito | |
| 113 | done |
||
| 114 | fi |
||
| 115 | e3c40a04 | Bjoern Boschman | |
| 116 | exit 0 |
||
| 117 | fi |
||
| 118 | |||
| 119 | |||
| 120 | aaee0699 | Lars Kruse | for guest_name in $guest_names; do |
| 121 | guest="$(clean_fieldname "$guest_name")" |
||
| 122 | e3c40a04 | Bjoern Boschman | |
| 123 | aaee0699 | Lars Kruse | value=$($f_comm -n "$guest_name" memory.usage_in_bytes) |
| 124 | echo "mem_usage_$guest.value $value" |
||
| 125 | e3c40a04 | Bjoern Boschman | |
| 126 | aaee0699 | Lars Kruse | value=$($f_comm -n "$guest_name" memory.stat | grep total_cache | awk '{print($2)}')
|
| 127 | echo "mem_cache_$guest.value $value" |
||
| 128 | e3c40a04 | Bjoern Boschman | |
| 129 | aaee0699 | Lars Kruse | value=$($f_comm -n "$guest_name" memory.stat | grep total_active_anon | awk '{print($2)}')
|
| 130 | echo "mem_active_$guest.value $value" |
||
| 131 | e3c40a04 | Bjoern Boschman | |
| 132 | aaee0699 | Lars Kruse | value=$($f_comm -n "$guest_name" memory.stat | grep total_inactive_anon | awk '{print($2)}')
|
| 133 | echo "mem_inactive_$guest.value $value" |
||
| 134 | done |
