mirror of
https://github.com/unraid/webgui.git
synced 2026-03-20 20:02:44 -05:00
Disk read/write IO in background daemon
This commit is contained in:
2
plugins/dynamix/event/disks_mounted
Normal file
2
plugins/dynamix/event/disks_mounted
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
/usr/local/emhttp/webGui/scripts/rc.diskload start >/dev/null
|
||||
2
plugins/dynamix/event/stopping_svcs
Normal file
2
plugins/dynamix/event/stopping_svcs
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
/usr/local/emhttp/webGui/scripts/rc.diskload stop >/dev/null
|
||||
42
plugins/dynamix/scripts/diskload
Normal file
42
plugins/dynamix/scripts/diskload
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
# set offset values
|
||||
awk '/(sd[a-z]*|nvme[0-9]n1) /{print $4,$8}' /proc/diskstats >/var/tmp/reset
|
||||
|
||||
# reset counters and exit
|
||||
if [[ $1 == reset ]]; then
|
||||
echo -n >/var/local/emhttp/diskload.ini
|
||||
for dev in $(awk '/(sd[a-z]*|nvme[0-9]n1) /{print $3}' /proc/diskstats); do
|
||||
echo $dev=0 0 0 0 >>/var/local/emhttp/diskload.ini
|
||||
done
|
||||
exit
|
||||
fi
|
||||
|
||||
declare -a sector reads writes
|
||||
# t = poll interval in seconds
|
||||
t=6
|
||||
|
||||
# get sector size of each disk
|
||||
c=0
|
||||
for dev in $(awk '/(sd[a-z]*|nvme[0-9]n1) /{print $3}' /proc/diskstats); do
|
||||
sector[c]=$(cat /sys/block/$dev/queue/hw_sector_size 2>/dev/null)
|
||||
[[ -z ${sector[c]} ]] && sector[c]=512
|
||||
((c++))
|
||||
done
|
||||
|
||||
# start daemon
|
||||
while :; do
|
||||
stats=($(awk '/(sd[a-z]*|nvme[0-9]n1) /{print $3,$6,$10,$4,$8}' /proc/diskstats))
|
||||
reset=($(cat /var/tmp/reset))
|
||||
c=0; s=${#stats[@]}
|
||||
echo -n >/var/local/emhttp/diskload.ini
|
||||
for ((i=0;i<s;i+=5)); do
|
||||
reads[c]=$((stats[i+1]-reads[c]))
|
||||
writes[c]=$((stats[i+2]-writes[c]))
|
||||
echo ${stats[i]}=$((reads[c]*sector[c]/t)) $((writes[c]*sector[c]/t)) $((stats[i+3]-reset[c*2])) $((stats[i+4]-reset[c*2+1])) >>/var/local/emhttp/diskload.ini
|
||||
reads[c]=${stats[i+1]}
|
||||
writes[c]=${stats[i+2]}
|
||||
((c++))
|
||||
done
|
||||
sleep $t
|
||||
done &
|
||||
30
plugins/dynamix/scripts/rc.diskload
Normal file
30
plugins/dynamix/scripts/rc.diskload
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
|
||||
script="diskload"
|
||||
daemon="/usr/local/emhttp/webGui/scripts/$script"
|
||||
|
||||
case $1 in
|
||||
start)
|
||||
if [[ -z $(pgrep -f $daemon) ]]; then
|
||||
$daemon 1>/dev/null 2>&1
|
||||
echo "$script started"
|
||||
else
|
||||
echo "$script already running!"
|
||||
fi
|
||||
;;
|
||||
stop)
|
||||
if [[ -n $(pgrep -f $daemon) ]]; then
|
||||
pkill -f $daemon 1>/dev/null 2>&1
|
||||
timer=5
|
||||
until [[ -z $(pgrep -f $daemon) || $timer -eq 0 ]]; do
|
||||
((timer--))
|
||||
sleep 1
|
||||
done
|
||||
echo "$script stopped"
|
||||
else
|
||||
echo "$script not running!"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $(basename $0) start|stop"
|
||||
esac
|
||||
Reference in New Issue
Block a user