You are not logged in.

#1 2018-07-22 03:36:31

abiostudent3
New Member
Registered: 2018-07-22
Posts: 4

Monitor ZFS Status with Conky?

Hey there!

So, I recently had some software issues with Storage Spaces on Windows 10 that took down my server. (and because I was dumb and too trusting, I didn't have a backup. Ouch.) After a lot of research and help from the folks on Reddit, I decided to try Ubuntu, because my server also doubles as an HTPC.

Turns out, with ECC ram, there's a fairly common issue where Ubuntu won't reboot. That issue is fixable, but since I was playing around trying to make everything work on a different drive, so I could keep my cobbled-together work that was at least serving Plex, I got tired of having to tell the computer how to reboot every time I reinstalled the OS.

Now, I've played around with Linux a very little bit before, and remembered trying a distro on an ancient netbook that had a right click menu, which I absolutely loved, but I couldn't remember what distro it was. Eventually I realized that it was Crunchbang - which is why I hadn't noticed it in any recent posts - and found my way here to bunsenlabs.

I love it.

I can't say enough good about bunsenlabs. It's extremely lightweight but I can still customize it to look good. (Gotta keep up that cred as a computer guy when someone visits, you know.) I currently have 99% of everything I want set up - though it took a lot of false starts. Samba sharing to Windows 10 gave me nightmares until I realized I didn't need an outside application; all I had to do was uncomment 2 lines.

However, I have one last bugbear to tackle: monitoring the status of my ZFS pool. I originally was going to do this through email (but I'm skittish about that; command-line mail agents in Ubuntu were the cause of most of my problems), but then I realized that I had Conky. I had planned on just removing Conky, but after a bit of editing, I really like it.

I just need to figure out how to monitor my ZFS pool. I've done some research, and I think what I need is a script that autoruns on startup that runs 'sudo zpool status' (possibly with -x appended, but I don't know how thorough that is) and writes its output to a file, which conky then prints the results of at a much slower rate than everything else updates...

But I haven't the slightest idea how to achieve that. Help?

Many thanks, guys.

EDIT: I'm making a bit of progress. Slowly. I can now make Conky launch a script, and I can make that script run a sudo-only command thanks to visudo.

Oh, and I now have two conky files, because it annoyed me that I couldn't set update speeds for each command individually, so I have one file with the lines that need to update quickly, and one that just updates every hour. Both have real transparency and sit on top of one another, so they look exactly like one conky. It works great, except that it broke the functionality to reload when I save the conky file. Oh well.

Last edited by abiostudent3 (2018-07-22 05:49:07)

Offline

#2 2018-07-22 11:47:17

abiostudent3
New Member
Registered: 2018-07-22
Posts: 4

Re: Monitor ZFS Status with Conky?

So, I guess I thought it would be fun to not sleep tonight.

However, I have what I believe will now work: the following script in /<user>/.config/conky/scripts, which writes a zfs.log file to /<user>. Conky then runs the script once an hour with ${exec}, and prints the status with the line

ZFS Status:$alignr${exec cat /home/<user>/zfs.log}

The bash script itself isn't too much more complicated, and is adapted from Peter van der Does's work here.

#!/bin/bash

rm /home/nasadmin/zfs.log
problems=0
x="Healthy"

condition=$(/sbin/zpool status | egrep -i '(DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED|corrupt|cannot|unrecover)')
if [ "${condition}" ]; then
  x="${color1} Fault"
fi

maxCapacity=92

if [ ${problems} -eq 0 ]; then
  capacity=$(/sbin/zpool list -H -o capacity)
  for line in ${capacity//%/}
  do
    if [ $line -ge $maxCapacity ]; then
      x="Nearing Capacity"
    fi
  done
fi

if [ ${problems} -eq 0 ]; then
  errors=$(/sbin/zpool status | grep ONLINE | grep -v state | awk '{print $3 $4 $5}' | grep -v 000)
  if [ "${errors}" ]; then
    x="${color1} Drive Errors"
  fi
fi

if [ $x = "Healthy" ]; then
    notify-send -u normal "ZFS Error, Please Attend"
fi

echo "$x" >>/home/nasadmin/zfs.log

So... anybody care to come along and tell me what I'm doing wrong, or why this won't work, or why I should suck it up and figure out email notifications anyways, because this won't save me? I'll take any constructive criticism you've got.

Offline

#3 2018-07-22 16:24:37

tynman
Member
Registered: 2015-10-13
Posts: 93

Re: Monitor ZFS Status with Conky?

You left out the line

problems=1

(line 30 in the original script).
Otherwise it looks reasonable to me.

Offline

#4 2018-07-24 03:14:16

abiostudent3
New Member
Registered: 2018-07-22
Posts: 4

Re: Monitor ZFS Status with Conky?

tynman wrote:

You left out the line

problems=1

(line 30 in the original script).
Otherwise it looks reasonable to me.

Ooh, good catch, thanks!

Offline

Board footer

Powered by FluxBB