diff --git a/Ceph/Config/userparameter_ceph.conf b/Ceph/Config/userparameter_ceph.conf index 655378e2b196a3ea826abfdc537a376d05fda783..77c51bd46d2571d66cf094d5118facd2a0bf4947 100644 --- a/Ceph/Config/userparameter_ceph.conf +++ b/Ceph/Config/userparameter_ceph.conf @@ -19,6 +19,28 @@ UserParameter=ceph.poolgrp.discovery[*],/etc/zabbix/scripts/queryCephPools.pl $1 UserParameter=ceph.poolgrp.objs[*],/etc/zabbix/scripts/cephUsage.pl $1 -g -p $2 -o UserParameter=ceph.poolgrp.size[*],/etc/zabbix/scripts/cephUsage.pl $1 -g -p $2 UserParameter=ceph.poolgrp.frac[*],/etc/zabbix/scripts/cephUsage.pl $1 -g -p $2 -f +# PGs +# tot=total, acc=active+clean, act=active, bck=backfilling, cln=clean, dee=deep +# deg=degraded, dow=down, ncm=incomplete, ncs=inconsistent, oth=other, pee=peering/peered +# rec=recovery, rem=remapped, rep=repair, scr=scrubbing, sta=stale, und=undersized +UserParameter=ceph.pgstat.tot[*],/etc/zabbix/scripts/cephUsage.pl $1 -f tot +UserParameter=ceph.pgstat.acc[*],/etc/zabbix/scripts/cephUsage.pl $1 -f acc +UserParameter=ceph.pgstat.act[*],/etc/zabbix/scripts/cephUsage.pl $1 -f act +UserParameter=ceph.pgstat.bck[*],/etc/zabbix/scripts/cephUsage.pl $1 -f bck +UserParameter=ceph.pgstat.cln[*],/etc/zabbix/scripts/cephUsage.pl $1 -f cln +UserParameter=ceph.pgstat.dee[*],/etc/zabbix/scripts/cephUsage.pl $1 -f dee +UserParameter=ceph.pgstat.deg[*],/etc/zabbix/scripts/cephUsage.pl $1 -f deg +UserParameter=ceph.pgstat.dow[*],/etc/zabbix/scripts/cephUsage.pl $1 -f dow +UserParameter=ceph.pgstat.ncm[*],/etc/zabbix/scripts/cephUsage.pl $1 -f ncm +UserParameter=ceph.pgstat.ncs[*],/etc/zabbix/scripts/cephUsage.pl $1 -f ncs +UserParameter=ceph.pgstat.oth[*],/etc/zabbix/scripts/cephUsage.pl $1 -f oth +UserParameter=ceph.pgstat.pee[*],/etc/zabbix/scripts/cephUsage.pl $1 -f pee +UserParameter=ceph.pgstat.rec[*],/etc/zabbix/scripts/cephUsage.pl $1 -f rec +UserParameter=ceph.pgstat.rem[*],/etc/zabbix/scripts/cephUsage.pl $1 -f rem +UserParameter=ceph.pgstat.rep[*],/etc/zabbix/scripts/cephUsage.pl $1 -f rep +UserParameter=ceph.pgstat.scr[*],/etc/zabbix/scripts/cephUsage.pl $1 -f scr +UserParameter=ceph.pgstat.sta[*],/etc/zabbix/scripts/cephUsage.pl $1 -f sta +UserParameter=ceph.pgstat.und[*],/etc/zabbix/scripts/cephUsage.pl $1 -f und # Disks UserParameter=ceph.osdsize.all.discovery[*],/etc/zabbix/scripts/queryCephDisks.pl $1 $2 -j UserParameter=ceph.osdsize.all.count[*],/etc/zabbix/scripts/queryCephDisks.pl $1 $2 -s $3 diff --git a/Ceph/Script/cephPg.pl b/Ceph/Script/cephPg.pl new file mode 100755 index 0000000000000000000000000000000000000000..ee4fd2a0dcc00153070d1c8bdbaeb70163d60c1e --- /dev/null +++ b/Ceph/Script/cephPg.pl @@ -0,0 +1,177 @@ +#!/usr/bin/perl +################################################################################ +# cephPg.pl - Return disk space occupied, global or by a pool (group) +################################################################################ +# +# This script executes 'ceph pg stat' and returns number of PG groups in +# some state. The desired state is selected as the 3-letter argument of +# option -f, like this: +# cephPg.pl -f acc # return number of PGs in active+clean state +# cephPg.pl -f all # return blank-tabbed list of all possible states/numbers (for debug purposes only) +# +# Hash %specialRegex contains a couple of special cases: +# - active+clean is substituted with a new string 'activeclean' +# - scrubbing+deep is substituted with string 'scrubbing' +# +# Originator: +# 2017-11-07: Fulvio Galeazzi (Consortium GARR) +# Contributors: +# +################################################################################ +use strict; +use warnings; +use Getopt::Long; + +sub fail_usage +{ + my ($msg)=@_; + print STDERR $msg."\n" if $msg; + print STDERR "Please use '-h' for usage.\n"; + exit 1; +} + +my $_sudo = `which sudo`; +chomp $_sudo; + +### Options +our($opt_exec, $opt_become, $opt_cluster, $opt_user, $opt_keyring, $opt_monhost, + $opt_filter, $opt_debug, $opt_h); +if (@ARGV > 0) { + GetOptions("e=s"=>\$opt_exec, + "b" =>\$opt_become, + "c=s"=>\$opt_cluster, + "u=s"=>\$opt_user, + "k=s"=>\$opt_keyring, + "m=s"=>\$opt_monhost, + "f=s"=>\$opt_filter, + "d" =>\$opt_debug, + "h" =>\$opt_h) || fail_usage; +} fail_usage "Unknown parameter." if (@ARGV > 0); + +my $cephCmd = ""; +if (defined $opt_exec) { + $cephCmd = "$opt_exec"; +} else { + $cephCmd = "/usr/bin/ceph"; +} +if ( ! -e $cephCmd) { + die "Executable $cephCmd not found!"; +} +if (defined $opt_become) { + $cephCmd = "$_sudo $cephCmd"; +} +# +if (defined $opt_cluster) { + $cephCmd .= " --cluster $opt_cluster"; +} +if (defined $opt_user) { + $cephCmd .= " --user $opt_user"; +} +if (defined $opt_keyring) { + $cephCmd .= " --keyring $opt_keyring"; +} +if (defined $opt_monhost) { + $cephCmd .= " -m $opt_monhost"; +} +# +my $wantAll = 0; +my @wantKeys = (); +if (defined $opt_filter) { + if ($opt_filter =~ m/all/) { + $wantAll = 1; + } + @wantKeys = split(/,/, $opt_filter); +} +# +my %specialRegex = ( + 'active+clean' => 'activeclean', +# 'scrubbing+deep' => 'scrubbing', + ); +# statesHash keys: +# tot=total, acc=active+clean, act=active, bck=backfilling, cln=clean, dee=deep +# deg=degraded, dow=down, ncm=incomplete, ncs=inconsistent, oth=other, pee=peering/peered +# rec=recovery, rem=remapped, rep=repair, scr=scrubbing, sta=stale, und=undersized +my %statesHash = ( + 'activeclean' => 'acc', + 'active' => 'act', + 'backfill' => 'bck', + 'wait-backfill' => 'bck', + 'backfill-toofull' => 'bck', + 'clean' => 'cln', + 'deep' => 'dee', + 'degraded' => 'deg', + 'down' => 'dow', + 'incomplete' => 'ncm', + 'inconsistent' => 'ncs', + 'creating' => 'oth', + 'replay' => 'oth', + 'splitting' => 'oth', + 'peered' => 'pee', + 'peering' => 'pee', + 'recovering' => 'rec', + 'recovery_wait' => 'rec', + 'remapped' => 'rem', + 'repair' => 'rep', + 'scrubbing' => 'scr', + 'stale' => 'sta', + 'undersized' => 'und', + ); +my %pgHash = ( + 'tot' => 0, + ); +foreach my $aSt (keys %statesHash) { + $pgHash{$statesHash{$aSt}} = 0; +} + +# Fetch the data and put it in an array +my @_data = `$cephCmd pg stat`; +chomp @_data; + +my $skipNext = 0; +# Read the array and print the wanted data +foreach my $_line (@_data) +{ + if ($skipNext) { + next; + } + if ($_line =~ m/^v\S+:\s+(\d+)\s+pgs:([^;]*)/) { + $skipNext = 1; + $pgHash{'tot'} = $1; + my $linePart = $2; + foreach my $aReg (keys %specialRegex) { + my $subst = $specialRegex{$aReg}; + $linePart =~ s/\Q$aReg\E/$subst/g; + } + my @fields = split(/,/, $linePart); + foreach my $aField (@fields) { + if ($aField =~ m/\s+(\d+)\s+(\S+)/) { + my $aPgNum = $1; + my $stateString = $2; + my @states = split(/\+/, $stateString); + foreach my $aState (@states) { + if (exists $statesHash{$aState}) { + $pgHash{$statesHash{$aState}} = $pgHash{$statesHash{$aState}} + $aPgNum; + } + } + } + } + } +} + +if ($wantAll) { + my $line = "tot:".$pgHash{'tot'}; + foreach my $akey (sort keys %pgHash) { + next if ($akey =~ m/tot/); + $line .= " ".$akey.":".$pgHash{$akey}; + } + print $line."\n"; +} else { + my $totPg = 0; + foreach my $akey (@wantKeys) { + $totPg += $pgHash{$akey}; + } + print $totPg."\n"; +} +exit 0; + +