*New 12.1 series Release:
2019-11-08: XigmaNAS 12.1.0.4.7091 - released!

*New 11.3 series Release:
2019-10-19: XigmaNAS 11.3.0.4.7014 - released


We really need "Your" help on XigmaNAS https://translations.launchpad.net/xigmanas translations. Please help today!

Producing and hosting XigmaNAS costs money. Please consider donating for our project so that we can continue to offer you the best.
We need your support! eg: PAYPAL

[tutorial] How to display free space left on LCD

Stats via an mini LCD displays.
Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
mstef
NewUser
NewUser
Posts: 1
Joined: 09 Dec 2013 21:51
Status: Offline

[tutorial] How to display free space left on LCD

#1

Post by mstef » 09 Dec 2013 22:04

Hi. I have a 16x2 VFD display HD44780 compatible with LCD2USB adapter. I want to simple show free space on ZFS zpool but regular LCDproc client is not good enough for me because it can't be customized, it shows all mounted points. So I wrote simple script in bash. I can't use python tools because they are not included in embedded version of NAS4free. So...

This is how it looks:

Image

Install guide:

1. Be sure your LCD is connected and it works with standard LCDproc client.

2. Check that LCDproc server is enabled, check LCD size (16x2) and connection type (lcd2usb).

Services > LCDproc

Image


In Auxiliary put this two lines:

Code: Select all

Heartbeat=off
ServerScreen=blank
[*]LCDproc client should be disabled

[*]Save and restart

3. Put lcdfree.sh script somewhere, for example on your ZFS pool dataset; in my case the path is /Storage/Media/nasfree.sh

ZPOOL constant means ZFS pool name. Main pool is "Storage".

Code: Select all

#!/bin/bash

SERVER="localhost"
PORT=13666
ZPOOL="Storage"
VBAR_CHARS=16
VBAR_HEADER="FREE:"

exec 3<>/dev/tcp/${SERVER}/${PORT}

echo "hello" >&3
echo "screen_add s1" >&3
echo "widget_add s1 w1 string" >&3

i=0
while [ $i -lt $VBAR_CHARS ]; do
	let i=i+1
	echo "widget_add s1 vb$i vbar" >&3
done

while [ true ]; do
	
	read used avail <<< $(zfs get -Ho value -p used,avail "$ZPOOL" | awk '{ print $1; print $2 }')

	sum=$((used+avail))

	read vused <<< $(echo "" | awk "{printf(\"%.0f\",$used * $VBAR_CHARS / $sum) }")
	let vfree=$VBAR_CHARS-$vused

	read usedh <<< $(awk -v x=$used 'BEGIN {
		split("B KB MB GB TB PB", type)
		for (i=5;y<1;i--)
			y = x / (2^(10*i))
		printf("%.1f%s", y, type[i+2])
	}')
	read availh <<< $(awk -v x=$avail 'BEGIN {
	        split("B KB MB GB TB PB", type)
	        for (i=5;y<1;i--)
	                y = x / (2^(10*i))
	        printf("%.1f%s",y, type[i+2])
	}')
	
	let padlen=VBAR_CHARS-${#VBAR_HEADER}-${#availh}

	msg="$VBAR_HEADER"
	i=0
	while [ $i -lt $padlen ]; do
		msg="$msg\\ "
		let i=i+1
	done
	msg="$msg$availh"

	echo "widget_set s1 w1 1 1 $msg" >&3

	i=0
	while [ $i -lt $VBAR_CHARS ]; do
		let i=i+1
		if [ $i -le $vfree ]; then
			h=8
		else
			h=1
		fi
		echo "widget_set s1 vb$i $i 2 $h" >&3
	done

	sleep 10

done

cat <&3
exit $?
Download: http://stef.pl/lcdfree/lcdfree.sh

4. Set execute byte:

Code: Select all

chmod +x lcdfree.sh
5. Run this script every start on this page:

System > Adanced > Command scripts

Type full path and set PostInit type

Image

Now restart the NAS. That's it. The script doesn't have any data validation or connection check. This script is the one of the first script I wrote in bash so please forgive me any faults I done. Feel free to modify it for your needs.

Post Reply

Return to “LCDproc”