mistermanko
Guru
- Joined
- Jan 27, 2020
- Messages
- 577
Well, somehow the measurement of .df_complex.free for my main pool is excatly what the GUI is telling me is free of my main pool. So I can deduct used space via: total (I already know) - free = used.
I have the same results as you on the "free" space but, how do you calculate the "Total"? I mean, i know that 100% of the disk space is not usable so the (disk space) x (# of disks) is not equal to "Pool total space".Well, somehow the measurement of .df_complex.free for my main pool is excatly what the GUI is telling me is free of my main pool. So I can deduct used space via: total (I already know) - free = used.
You can calculate raw capacity easily. number of disks * disk space = total pool space. Of course there's deductibles with zfs.I have the same results as you on the "free" space but, how do you calculate the "Total"? I mean, i know that 100% of the disk space is not usable so the (disk space) x (# of disks) is not equal to "Pool total space".
Care to expand on how you did it?
I'm not criticizing i honestly want to know for my own education.
The reason for calculating the total is to use it to calculate the "used space" per your suggestion.
This is a great workaround.You can calculate raw capacity easily. number of disks * disk space = total pool space. Of course there's deductibles with zfs.
I used this calculator to calculate my pools total. https://wintelguy.com/zfs-calc.pl
For me a ZPool with Raid-Z2 of 6 disks each 4 TB, gives a raw total of 24 TB and as per the calculator a usable space of 15.94 (I rounded up to 16 TB for grafana total).
Sure, your script comes in handy, when multiple instances are at play. I'll give it a try soon.My dashboards are for multiple systems, some with multiple pools, so I want the reporting system to tell me in Influx what size/total, used and free are for each pool![]()
Putting a script file in a location on your storage pool - mine are atbut i really don't feel confortable adding or altering files to the truenas base system. That is why i like to experiment inside jails.
/mnt/hdd/scripts/* - is not considered altering the TrueNAS system. And cron jobs are an officially supported UI feature.Ok tried it out.Are you using the "reporting" function that is built in or a separate graphite installation? I use the former to push data into InfluxDB and visualize with Grafana. That's actually collectd running inside TN and using the graphite plain text API to deliver the data.
For pool space I have created this shell script that delivers all the data I need. The prefix is defined to match with what the built in collectd does.
Code:root@freenas[/mnt/hdd/scripts]# cat zpool-metrics.sh #! /bin/sh HOST="192.168.1.55" PORT="2003" PREFIX="servers" time=$(/bin/date +%s) hostname=$(/bin/hostname | /usr/bin/tr '.' '_') /usr/local/sbin/zpool list -Hp | while read pool size alloc free ignore do ralloc=$(echo "scale=8;${alloc}/${size}" | /usr/bin/bc) rfree=$(echo "scale=8;${free}/${size}" | /usr/bin/bc) echo "${PREFIX}.${hostname}.zpool.${pool}.size ${size} ${time}" echo "${PREFIX}.${hostname}.zpool.${pool}.alloc ${alloc} ${time}" echo "${PREFIX}.${hostname}.zpool.${pool}.alloc-ratio ${ralloc} ${time}" echo "${PREFIX}.${hostname}.zpool.${pool}.free ${free} ${time}" echo "${PREFIX}.${hostname}.zpool.${pool}.free-ratio ${rfree} ${time}" done | /usr/bin/nc "${HOST}" "${PORT}" -w2
upscmd instead of zpool command I know your heart is in the right place, and i know it is to my benefit to figure these things for myself, but my scripting skills are nothing to brag about.Write a script similar to mine usingupscmdinstead ofzpoolcommand![]()
# get current time in Unix timestamp format, save in $time
time=$(/bin/date +%s)
# get hostname, replace "." with "_", save in $hostname
hostname=$(/bin/hostname | /usr/bin/tr '.' '_')
# iterate over all ZFS pools as output by `zpool list`
# - read the values into the variables $pool $size $alloc $free
# - read the last column of the output into the variable $ignore - we don't use it
/usr/local/sbin/zpool list -Hp | while read pool size alloc free ignore
do
# calculate ratio from absolute values to 8 digits precision with the `bc` calculator
ralloc=$(echo "scale=8;${alloc}/${size}" | /usr/bin/bc)
rfree=$(echo "scale=8;${free}/${size}" | /usr/bin/bc)
# output all the values in graphite plain text format
echo "${PREFIX}.${hostname}.zpool.${pool}.size ${size} ${time}"
echo "${PREFIX}.${hostname}.zpool.${pool}.alloc ${alloc} ${time}"
echo "${PREFIX}.${hostname}.zpool.${pool}.alloc-ratio ${ralloc} ${time}"
echo "${PREFIX}.${hostname}.zpool.${pool}.free ${free} ${time}"
echo "${PREFIX}.${hostname}.zpool.${pool}.free-ratio ${rfree} ${time}"
# and pipe all the output for all pools and values into the `nc` program to send them over the network
done | /usr/bin/nc "${HOST}" "${PORT}" -w2
root@socrates[~]# upscmd -l Socrates-ups Instant commands supported on UPS [Socrates-ups]: beeper.disable - Description unavailable beeper.enable - Description unavailable beeper.mute - Description unavailable beeper.off - Description unavailable beeper.on - Description unavailable load.off - Description unavailable load.off.delay - Description unavailable load.on - Description unavailable load.on.delay - Description unavailable shutdown.return - Description unavailable shutdown.stayoff - Description unavailable shutdown.stop - Description unavailable
root@socrates[~]# upsc Socrates-ups | grep 'ups.status' ups.status: OL
#! /bin/sh
#script to obtain the UPS status and send it
#to InfluxDB and Grafana
#
#by Ragametal 07-21-2022
##################################################################
# modify the variables below to meet your needs
# change HOST to match the IP of the InfluxDB jail
HOST="10.0.0.24"
# change the PORT to match the InfluxDB port (default is shown)
PORT="2003"
# change PREFIX to match the InfluxDB items (default is shown)
PREFIX="servers"
# change the UPS to match the name of the UPS in Truenas
UPS="Socrates-ups"
# end of variables
# start of script
# DO NOT MODIFY BELOW THIS LINE unless you understand the code
#####################################################################
# get current time in Unix timestamp format, save in $time
time=$(/bin/date +%s)
# get hostname, replace "." with "_", save in $hostname
hostname=$(/bin/hostname | /usr/bin/tr '.' '_')
# - read the UPS Status value and save it to the variable $upsstatus
upsstatus=/usr/local/bin/upsc ${UPS} | grep 'ups.status'
# output UPS status values in graphite plain text format
echo "${PREFIX}.${hostname}.nut.${UPS}.ups.status ${upsstatus} ${time}"upsstatus line won't work that way. For once you have to enclose the command in $() so the OUTPUT ends up in the variable. Second you will probably want to strip the "ups.status:" in front.Thanks for the input on theTheupsstatusline won't work that way. For once you have to enclose the command in$()so the OUTPUT ends up in the variable. Second you will probably want to strip the "ups.status:" in front.
What are the possible values and what do they mean? I would need that info to make a complete suggestion.
upsstatus, i honestly didn't see it. | Value | Status |
|---|---|
| OL | On line (mains is present) |
| OB | On battery (mains is not present) |
| LB | Low battery |
| RB | The battery needs to be replaced |
| CHRG | The battery is charging |
| DISCHRG | The battery is discharging (inverter is providing load power) |
| BYPASS | UPS bypass circuit is active (no battery protection is available) |
| CAL | UPS is currently performing runtime calibration (on battery) |
| OFF | UPS is offline and is not supplying power to the load |
| OVER | UPS is overloaded |
| TRIM | UPS is trimming incoming voltage |
| BOOST | UPS is boosting incoming voltage |
| * | unknown state |
upsstatus=$(/usr/local/bin/upsc ${UPS} | /usr/bin/awk '/ups\.status:/ { print $2 }')case ${upsstatus} in
OL)
# online
numstatus=0
;;
OB)
# on battery
numstatus=1
;;
LB)
# low battery
numstatus=2
;;
[...]
*)
# unknown
numstatus=99
;;
esac#! /bin/sh
#script to obtain the UPS status and send it
#to InfluxDB and Grafana
#
#by Ragametal 07-21-2022
##################################################################
# modify the variables below to meet your needs
# change HOST to match the IP of the InfluxDB jail
HOST="10.0.0.24"
# change the PORT to match the InfluxDB port (default is shown)
PORT="2003"
# change PREFIX to match the InfluxDB items (default is shown)
PREFIX="servers"
# change the UPS to match the name of the UPS in Truenas
UPS="Socrates-ups"
# end of variables
# start of script
# DO NOT MODIFY BELOW THIS LINE unless you understand the code
#####################################################################
# get current time in Unix timestamp format, save in $time
time=$(/bin/date +%s)
# get hostname, replace "." with "_", save in $hostname
hostname=$(/bin/hostname | /usr/bin/tr '.' '_')
# - read the UPS Status value and save it to the variable $upsstatus
upsstatus=$(/usr/local/bin/upsc ${UPS} | /usr/bin/awk '/ups\.status:/ { print $2 }')
case ${upsstatus} in
OL)
# online
numstatus=0
;;
OB)
# on battery
numstatus=1
;;
LB)
# low battery
numstatus=2
;;
RB)
# replace battery
numstatus=3
;;
CHRB)
# charging battery
numstatus=4
;;
DISCHRB)
# discharging battery
numstatus=5
;;
BYPASS)
# bypass circuit is active
numstatus=6
;;
CAL)
# performing calibration
numstatus=7
;;
OFF)
# offline
numstatus=8
;;
OVER)
# overloaded
numstatus=9
;;
TRIM)
# trimming incoming voltage
numstatus=10
;;
BOOST)
# boosting incoming voltate
numstatus=11
;;
*)
# unknown
numstatus=12
;;
esac
# output UPS status values in graphite plain text format
echo "${PREFIX}.${hostname}.nut.${UPS}.ups.status ${upsstatus} ${time}" | /usr/bin/nc "${HOST}" "${PORT}" -w2echo "${PREFIX}.${hostname}.nut.${UPS}.ups.status ${upsstatus} ${time}" | /usr/bin/nc "${HOST}" "${PORT}" -w2echo "${PREFIX}.${hostname}.nut.${UPS}.ups.status ${numstatus} ${time}" | /usr/bin/nc "${HOST}" "${PORT}" -w2