[zfs-discuss] Nagios monitor

Angel Docampo docampo.work at gmail.com
Thu Sep 5 11:17:53 EDT 2013


As far as I can see, it does not cound the space taken from snapshots,
didn't it?
It would be great!

Regards,

Angel Docampo


2013/9/5 Eri Ramos Bastos <bastos.eri at gmail.com>

> Using this one. Thanks, Brian.
>
> I modified it a little adding the command line options.
>
>
> On Wed, Sep 4, 2013 at 8:00 PM, Brian Menges <bmenges at gogrid.com> wrote:
>
>>  Here’s something that we use… very rough but if you added some command
>> line parsing (which I have in my TODO list) using like optarg, then it
>> would be very pretty!
>>
>>
>>
>> ----
>>
>> #!/usr/bin/env python
>>
>> #
>>
>> # This is a nagios plugin for monitoring
>>
>> # ZFS disk space. -russ 7/9/2013
>>
>> # Modified by brian 8/29/2013 to improve runtime
>>
>> #
>>
>> # Changelog:
>>
>> #  2013-07-09   Russ    Original script
>>
>> #  2013-08-29   Brian   Converted over to subprocess from os.popen which
>> is deprecated
>>
>> #                       Performance improvement (runtime down from
>> 0m0.153s to 0m0.049s)
>>
>> #                       Using one normalize function to pretty print the
>> large numbers in meaningful units
>>
>> #                       Printing floats to the second decimal place
>>
>> #                       Some comments added to the file
>>
>> #                       Aligned to 2-space formatting
>>
>> #
>>
>> from __future__ import division
>>
>> import sys
>>
>> import subprocess
>>
>>
>>
>> def normalize(vol_size):
>>
>>   # Print human readable byte units
>>
>>   # Bytes      < (2 ** 10) or 1024
>>
>>   # Kilobytes  < (2 ** 20) or 1024*1024
>>
>>   # Megabytes  < (2 ** 30) or 1024*1024*1024
>>
>>   # Gigabytes  < (2 ** 40) or 1024*1024*1024*1024
>>
>>   # Terrabytes < (2 ** 50) or 1024*1024*1024*1024*1024
>>
>>   # Petabytes  < (2 ** 60) or 1024*1024*1024*1024*1024*1024
>>
>>   # Exabytes   < (2 ** 70) or 1024*1024*1024*1024*1024*1024*1024
>>
>>   # Zettabytes < (2 ** 80) or 1024*1024*1024*1024*1024*1024*1024*1024
>>
>>   # Yottabytes < (2 ** 90) or 1024*1024*1024*1024*1024*1024*1024*1024*1024
>>
>>   # Bigger = NaN (this function's version of an error... cause we can't
>> stuff Brontobytes in)
>>
>>
>>
>>   if vol_size < (2 ** 10):
>>
>>     value = vol_size
>>
>>     unit  = ''
>>
>>   elif vol_size < (2 ** 20):
>>
>>     value = vol_size / (2 ** 10)
>>
>>     unit  = 'K'
>>
>>   elif vol_size < (2 ** 30):
>>
>>     value = vol_size / (2 ** 20)
>>
>>     unit  = 'M'
>>
>>   elif vol_size < (2 ** 40):
>>
>>     value = vol_size / (2 ** 30)
>>
>>     unit  = 'G'
>>
>>   elif vol_size < (2 ** 50):
>>
>>     value = vol_size / (2 ** 40)
>>
>>     unit  = 'T'
>>
>>   elif vol_size < (2 ** 60):
>>
>>     value = vol_size / (2 ** 50)
>>
>>     unit  = 'P'
>>
>>   elif vol_size < (2 ** 70):
>>
>>     value = vol_size / (2 ** 60)
>>
>>     unit  = 'E'
>>
>>   elif vol_size < (2 ** 80):
>>
>>     value = vol_size / (2 ** 70)
>>
>>     unit  = 'Z'
>>
>>   elif vol_size >= (2 ** 80):
>>
>>     value = vol_size / (2 ** 80)
>>
>>     unit  = 'Y'
>>
>>   else:
>>
>>     value = vol_size
>>
>>     unit  = 'NaN'
>>
>>
>>
>>   unit = unit + 'B'
>>
>>   return (value, unit)
>>
>>
>>
>> # percent values to warn / crit at
>>
>> # TODO: might want to make this a command line option such as -w <warn>
>> -c <crit>
>>
>> warn_at = 70
>>
>> crit_at = 80
>>
>>
>>
>> if len (sys.argv) < 2:
>>
>>   print 'CRITICAL: You must provide a Zhast volume name!'
>>
>>   sys.exit(2)
>>
>>
>>
>> # TODO: Remove harvest of sys.argv and instead use an arguement parser,
>> and require zvol arguement and others
>>
>> zfs_vol = sys.argv[1]
>>
>>
>>
>> # "zfs get -Hp used <zfs_vol>" is a better command to get the used space
>> in bytes
>>
>> zfs_cmd = 'zfs get -Hp used \'%s\'' % zfs_vol
>>
>> p = subprocess.check_output(zfs_cmd, shell=True)
>>
>> zfs_used = p.rstrip().split()
>>
>> zfs_used = int(zfs_used[2])
>>
>>
>>
>> # "zfs get -Hp availalble <zfs_vol>" is a better command to get the
>> available space in bytes
>>
>> zfs_cmd = 'zfs get -Hp available \'%s\'' % zfs_vol
>>
>> p = subprocess.check_output(zfs_cmd, shell=True)
>>
>> zfs_avail = p.rstrip().split()
>>
>> zfs_avail = int(zfs_avail[2])
>>
>>
>>
>> # Lets do a bit of math, and get normalized output strings
>>
>> zfs_total = zfs_avail + zfs_used
>>
>> zfs_percent = float((zfs_used/zfs_total)*100)
>>
>> zfs_used = "%.2f %s" % normalize(zfs_used)
>>
>> zfs_total = "%.2f %s" % normalize(zfs_total)
>>
>>
>>
>> msg = 'Usage on ' +  '%s is %.2f%% (%s / %s)' % (zfs_vol, zfs_percent,
>> zfs_used, zfs_total)
>>
>>
>>
>> if zfs_percent >= crit_at:
>>
>>   print 'CRITICAL: %s' % msg
>>
>>   sys.exit(2)
>>
>> elif zfs_percent >= warn_at:
>>
>>   print 'WARNING: %s' % msg
>>
>>   sys.exit(1)
>>
>> else:
>>
>>   print 'OK: %s' % msg
>>
>>   sys.exit(0)
>>
>> ----
>>
>>
>>
>>
>>
>> - Brian Menges
>>
>> Principal Engineer, DevOps
>>
>> GoGrid | ServePath | ColoServe | UpStream Networks
>>
>>
>>
>> *From:* Eri Ramos Bastos [mailto:bastos.eri at gmail.com]
>> *Sent:* Wednesday, September 04, 2013 13:00
>> *To:* zfs-discuss at zfsonlinux.org
>> *Subject:* [zfs-discuss] Nagios monitor
>>
>>
>>
>> Hi, all
>>
>> Does anyone have a nagios monitoring your zpools of zfs filesystems?
>>
>> We are looking to implement space utilization monitoring but could not
>> find anything useful, but before start re-inventing the wheel I thought I
>> should ask here.
>>
>> Thanks!
>>
>>
>> Eri Ramos Bastos
>>
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to zfs-discuss+unsubscribe at zfsonlinux.org.
>>
>> ------------------------------
>>
>> The information contained in this message, and any attachments, may
>> contain confidential and legally privileged material. It is solely for the
>> use of the person or entity to which it is addressed. Any review,
>> retransmission, dissemination, or action taken in reliance upon this
>> information by persons or entities other than the intended recipient is
>> prohibited. If you receive this in error, please contact the sender and
>> delete the material from any computer.
>>
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to zfs-discuss+unsubscribe at zfsonlinux.org.
>>
>
>  To unsubscribe from this group and stop receiving emails from it, send an
> email to zfs-discuss+unsubscribe at zfsonlinux.org.
>

To unsubscribe from this group and stop receiving emails from it, send an email to zfs-discuss+unsubscribe at zfsonlinux.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.zfsonlinux.org/pipermail/zfs-discuss/attachments/20130905/dda41636/attachment.html>


More information about the zfs-discuss mailing list