Moved to a new, package based installation method. Also added a few more support files.

This commit is contained in:
2020-07-17 06:01:19 +02:00
parent 7be58113d8
commit 6519037034
16 changed files with 897 additions and 423 deletions

View File

@ -0,0 +1,29 @@
Server=0.0.0.0/0
LogType=system
AllowRoot=1
StartAgents=1
DenyKey=system.run[*]
AllowKey=agent.*
AllowKey=net.if.*
AllowKey=net.if.*[*]
AllowKey=proc.*
AllowKey=proc.*[*]
AllowKey=sensor[*]
AllowKey=system.*
AllowKey=system.*[*]
AllowKey=vfs.dev.*
AllowKey=vfs.dev.*[*]
AllowKey=vfs.fs.*
AllowKey=vfs.fs.*[*]
AllowKey=vm.memory.size[*]
AllowKey=unraid.*
AllowKey=unraid.*[*]
DenyKey=*
UserParameter=unraid.disks.discovery,/usr/local/emhttp/plugins/zabbix_agent/scripts/disks.discovery.sh
UserParameter=unraid.disk[*],/usr/local/emhttp/plugins/zabbix_agent/scripts/disk.sh "$1"
UserParameter=unraid.disks.totals,/usr/local/emhttp/plugins/zabbix_agent/scripts/disks.totals.sh
UserParameter=unraid.qemu.discovery,/usr/local/emhttp/plugins/zabbix_agent/scripts/qemu.discovery.sh
UserParameter=unraid.qemu[*],/usr/local/emhttp/plugins/zabbix_agent/scripts/qemu.sh "$1"

48
files/etc/rc.d/rc.zabbix_agentd Executable file
View File

@ -0,0 +1,48 @@
#!/bin/sh
#
# rc.zabbix_agentd This shell script takes care of starting and stopping
# the Zabbix agent
OPTIONS="-c /boot/config/plugins/zabbix_agent/zabbix_agentd.conf"
start() {
if [ -x /usr/sbin/zabbix_agentd ]; then
echo -n "Starting zabbix_agentd: "
/usr/sbin/zabbix_agentd $OPTIONS
echo " /usr/sbin/zabbix_agentd $OPTIONS"
fi
}
stop() {
# Stop daemons.
COUNT=0
echo -n "Shutting down zabbix_agentd: "
while `killall zabbix_agentd 2>/dev/null`; do
echo -n "."
sleep 1
COUNT=$((COUNT+1))
if [ $COUNT -ge 30 ]; then
killall -9 zabbix_agentd
sleep 1
break
fi
done
echo " DONE"
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
;;
esac

View File

@ -0,0 +1,5 @@
**zabbix_agent**
This plugin installs and configures zabbix_agentd which can be used to monitor this Unraid server using a central Zabbix server.
You can download a matching zabbix template at https://git.schle.nz/fabian/unraid-zabbix_agent/raw/branch/main/zabbix_template.xml

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 B

View File

@ -0,0 +1,54 @@
#!/bin/bash
id="$1"
found=0
device=""
while read line; do
if [[ $line == "["* ]]; then
if [ $found = 1 ]; then
[ $fsFree -ge 0 ] && [ $fsSize -ge 0 ] && fsUsed=$(( $fsSize - $fsFree ))
echo -n '{"device":"'$device'", "name":"'$name'", "status":"'$status'", "temp":'$temp', "size":'$size', "num_reads":'$num_reads', '
echo -n '"num_writes":'$num_writes', "num_errors":'$num_errors', "type":"'$type'", "fs_size":'$fsSize', "fs_free":'$fsFree', "fs_used":'$fsUsed', '
break
else
device=''
name=''
status=''
temp=-1
size=-1
num_reads=-1
num_writes=-1
num_errors=-1
type=""
fsSize=-1
fsFree=-1
fsUsed=-1
fi
else
while IFS="=" read key value; do
value="${value%\"}"
value="${value#\"}"
[ $key = "id" ] && [ "$value" = "$id" ] && found=1
[ $key = "device" ] && device="$value"
[ $key = "name" ] && name="$value"
[ $key = "status" ] && status="$value"
[ $key = "temp" ] && [ "$value" != "*" ] && temp="$value"
[ $key = "size" ] && size=$(( $value * 1024 ))
[ $key = "numReads" ] && num_reads="$value"
[ $key = "numWrites" ] && num_writes="$value"
[ $key = "numErrors" ] && num_errors="$value"
[ $key = "type" ] && type="$value"
[ $key = "fsSize" ] && fsSize=$(( $value * 1024 ))
[ $key = "fsFree" ] && fsFree=$(( $value * 1024 ))
done <<< "$line"
fi
done < <(cat /var/local/emhttp/disks.ini ; echo "[empty]")
if [ $found = 0 ]; then
echo "UNSUPPORTED"
exit 1
fi
read bytes_read bytes_written _ < <(grep $device"=" /var/local/emhttp/diskload.ini | cut -d"=" -f2)
echo '"bytes_reading":'$bytes_read', "bytes_writing":'$bytes_written'}'

View File

@ -0,0 +1,16 @@
#!/bin/bash
id='""'
device='""'
first=1
echo -n '['
while IFS="=" read key value; do
if [ "$key" = "id" ] && [ -n "$value" ] && [ "$value" != '""' ]; then
[ $first = 0 ] && echo -n ","
first=0
echo -n '{"{#ID}":'$value'}'
fi
done < /var/local/emhttp/disks.ini
echo ']'

View File

@ -0,0 +1,38 @@
#!/bin/bash
id="$1"
found=0
device=""
data_size=0
data_free=0
data_used=0
cache_size=0
cache_free=0
cache_used=0
while read line; do
if [[ $line == "["* ]]; then
if [ "$type" = "Cache" ]; then
cache_size=$(( $cache_size + $size ))
cache_free=$(( $cache_free + $free ))
elif [ "$type" = "Data" ]; then
data_size=$(( $data_size + $size ))
data_free=$(( $data_free + $free ))
fi
type=""
size=0
free=0
else
IFS="=" read key value <<< "$line"
value="${value%\"}"
value="${value#\"}"
[ $key = "type" ] && type="$value"
[ $key = "fsSize" ] && size=$(( $value * 1024 ))
[ $key = "fsFree" ] && free=$(( $value * 1024 ))
fi
done < <(cat /var/local/emhttp/disks.ini ; echo "[empty]")
echo -n '{"data": {"size":'$data_size ', "free":'$data_free ', "used":'$(( $data_size - $data_free ))'},'
echo ' "cache":{"size":'$cache_size', "free":'$cache_free', "used":'$(( $cache_size - $cache_free ))'}}'

View File

@ -0,0 +1,11 @@
#!/bin/bash
first=1
echo -n "["
while read name; do
[ "$name" = "" ] && continue
[ $first = 0 ] && echo -n ","
first=0
echo -n '{"{#VM}":"'$name'"}'
done < <(virsh list --name --all)
echo "]"

View File

@ -0,0 +1,24 @@
#!/bin/bash
VM="$1"
echo -n '{'
state=`virsh domstate "$VM"`
echo -n '"state":"'$state'"'
if [ "$state" != "running" ]; then
echo -n '}'
exit
fi
while IFS=":" read key value; do
[ "$key" = "CPU(s)" ] && echo -n ', "cpus":'$value
[ "$key" = "CPU time" ] && echo -n ', "cpu_time":'${value%s}
[ "$key" = "Max memory" ] && echo -n ', "memory_max":'$((${value%KiB} * 1024))
[ "$key" = "Used memory" ] && echo -n ', "memory_used":'$((${value%KiB} * 1024))
done < <(virsh dominfo "$VM")
while read if key value; do
[ "$key" = "rx_bytes" ] && echo -n ', "network_bytes_in":'$value
[ "$key" = "tx_bytes" ] && echo -n ', "network_bytes_out":'$value
done < <(virsh domifstat "$VM" vnet0)
echo "}"

BIN
files/usr/sbin/zabbix_agentd Executable file

Binary file not shown.