]> git.uio.no Git - uio-zabbix.git/commitdiff
Added script for calculating percent used of an LVM volume group
authorØyvind Hagberg <oyvind.hagberg@usit.uio.no>
Mon, 21 Nov 2016 10:41:08 +0000 (11:41 +0100)
committerØyvind Hagberg <oyvind.hagberg@usit.uio.no>
Mon, 21 Nov 2016 10:41:08 +0000 (11:41 +0100)
zabbix_get_vg_usedpercent.pl [new file with mode: 0755]

diff --git a/zabbix_get_vg_usedpercent.pl b/zabbix_get_vg_usedpercent.pl
new file mode 100755 (executable)
index 0000000..5644536
--- /dev/null
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+use strict;
+
+if (getpwuid($<) ne 'root') {
+       print "This script must be run by root.\n";
+       exit 1;
+}
+if ($#ARGV != 0) {
+       print "Usage: $0 <name-of-volume-group>\n";
+       exit 1;
+}
+my $vg = $ARGV[0];
+my $allvgs = `/usr/sbin/vgs --noheadings -o vg_name`;
+unless (grep { $_ eq $vg } split /\s+/,$allvgs) {
+       print "Unknown volume group.\n";
+       exit;
+}
+
+my $free = `/usr/sbin/vgs --noheadings -o vg_free_count $vg`;
+my $total = `/usr/sbin/vgs --noheadings -o vg_extent_count $vg`;
+printf "%.3f\n", 100-(($free/$total)*100);
\ No newline at end of file