root / plugins / ups / nut @ ef960abc
Historique | Voir | Annoter | Télécharger (2,76 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# This script is intended for use with Munin to monitor |
| 3 |
# UPS Load, Battery Charge, Input and Output Voltages |
| 4 |
# querying data from NUT (www.networkupstools.org), tested under Ubuntu Linux |
| 5 |
# v. 1.1, 12/16/2007 |
| 6 |
# (c) Alex Yanchenko (yanchenko{at}gmail.com), 2007
|
| 7 |
# Distributed under GPL v.3 (http://www.gnu.org/licenses/gpl-3.0.txt) |
| 8 |
# |
| 9 |
# The plugin can utilize automatic configuration, |
| 10 |
# here are the basic steps (require root privileges): |
| 11 |
# 1. Copy it as /usr/share/munin/plugins/nut_ |
| 12 |
# 2. Make executable: "chmod 755 /usr/share/munin/plugins/nut_" |
| 13 |
# 3. Run "munin-node-configure --shell", you should see smth like |
| 14 |
# "ln -s /usr/share/munin/plugins/nut_ /etc/munin/plugins/nut_apc_AT_localhost" |
| 15 |
# with "apc@localhost" been UPS configured in upsmon.conf (see NUT docs). |
| 16 |
# Note that "@" is replaced with "_AT_". |
| 17 |
# Multiple UPS monitoring is supported as well. |
| 18 |
# 4. Run the proposed command to create a link. |
| 19 |
# 5. To verify, run "munin-node-configure", you should notice the "nut_" record |
| 20 |
# |
| 21 |
# Plugin | Used | Suggestions |
| 22 |
# ------ | ---- | ----------- |
| 23 |
# nut_ | yes | apc_AT_localhost |
| 24 |
# |
| 25 |
# 6. Restart munin: "/etc/init.d/munin-node restart" |
| 26 |
# 7. Hold on for 5 minutes at most and watch the graph appear. |
| 27 |
# 8. Customize voltage warning that are commented out for now. |
| 28 |
# |
| 29 |
#%# family=contrib |
| 30 |
#%# capabilities=autoconf suggest |
| 31 |
|
| 32 |
function FETCH_DATA() {
|
| 33 |
# UPS address, fetched from file name |
| 34 |
UPS=$(basename $0 | sed 's|^nut_||g' | sed 's|_AT_|@|g') |
| 35 |
|
| 36 |
# Save data into variables |
| 37 |
model=$(upsc $UPS | grep ups.model: | cut -d" " -f2) |
| 38 |
in=$(upsc $UPS | grep input.voltage: | cut -d" " -f2) |
| 39 |
out=$(upsc $UPS | grep output.voltage: | cut -d" " -f2) |
| 40 |
load=$(upsc $UPS | grep ups.load: | cut -d" " -f2) |
| 41 |
charge=$(upsc $UPS | grep battery.charge: | cut -d" " -f2) |
| 42 |
} |
| 43 |
|
| 44 |
# Munin routines |
| 45 |
case "$1" in |
| 46 |
autoconf) |
| 47 |
grep ^MONITOR < /etc/nut/upsmon.conf &> /dev/null |
| 48 |
if [[ "$?" = "0" ]]; then |
| 49 |
echo yes |
| 50 |
exit 0 |
| 51 |
else |
| 52 |
echo "no (NUT not installed or no UPS info available in /etc/nut/upsmon.conf)" |
| 53 |
exit 1 |
| 54 |
fi |
| 55 |
;; |
| 56 |
config) |
| 57 |
FETCH_DATA |
| 58 |
cat << EOM |
| 59 |
graph_title UPS: $model - $UPS |
| 60 |
graph_category sensors |
| 61 |
graph_info The graph shows UPS info monitored by NUT. |
| 62 |
graph_args --base 1000 --lower-limit 0 |
| 63 |
in.label Input Voltage (v) |
| 64 |
in.warning 190:260 |
| 65 |
out.label Output Voltage (v) |
| 66 |
out.critical 208:253 |
| 67 |
charge.label Battery Charge (%) |
| 68 |
charge.draw AREA |
| 69 |
charge.colour 00aaaa |
| 70 |
charge.warning 30: |
| 71 |
load.label UPS Load (%) |
| 72 |
load.colour ff0000 |
| 73 |
load.warning :80 |
| 74 |
EOM |
| 75 |
exit 0 |
| 76 |
;; |
| 77 |
suggest) |
| 78 |
grep ^MONITOR < /etc/nut/upsmon.conf | cut -d" " -f2 | sed 's|@|_AT_|g' |
| 79 |
exit 0 |
| 80 |
;; |
| 81 |
*) |
| 82 |
|
| 83 |
FETCH_DATA |
| 84 |
# Print data for Munin |
| 85 |
cat << EOM |
| 86 |
in.value $in |
| 87 |
out.value $out |
| 88 |
charge.value $charge |
| 89 |
load.value $load |
| 90 |
EOM |
| 91 |
exit 0 |
| 92 |
;; |
| 93 |
esac |
