Skip to content

Commit

Permalink
add mode container-tablespace-free
Browse files Browse the repository at this point in the history
  • Loading branch information
lausser committed Oct 10, 2016
1 parent 5bcbd76 commit 9277f06
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 6 deletions.
46 changes: 45 additions & 1 deletion .gitignore
@@ -1,7 +1,51 @@
.gitignore
Makefile
Makefile.in
aclocal.m4
autom4te.cache/
check_*_health-*.tar.gz
check_logfiles-*.tar.gz
check_*_health-*.tar.gz.1
check_*_health-*.zip
check_*_health-*/
Monitoring-GLPlugin-*.tar.gz
config.*
configure
plugins-scripts/Makefile
plugins-scripts/Makefile.in
plugins-scripts/check_*_health
plugins-scripts/subst
contrib/
*.cfg
t/etc
t/this_is_random.*
t/bin/*.bat
t/*.ptkdb
scenarios
plugins-scripts/*.exe
plugins-scripts/*.zip
MIBS
t/Makefile.in

t/var
t/tmp
tests/var
tests/tmp
build
dist
*.egg-info
_build
archive
typescript
doc/
a/
b/
x
y
x.pl
y.pl
smidump.exe.stackdump
rfc*.trc
dev_rfc
dev_rfc.trc
*.pm
plugins-scripts/check_*_health.ptkdb
2 changes: 2 additions & 0 deletions ChangeLog
@@ -1,3 +1,5 @@
* 3.0 - 2016-10-10
add mode container-tablespace-free
* 2.1.3.5 - 2016-05-11
sysdba fix (Thanks c0xc). This patch was to satisfy a customer's need. Think about a support contract. If you have one, we do everything you want.
* 2.1.3.4 - 2016-03-30
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT(check_oracle_health,2.1.3.5)
AC_INIT(check_oracle_health,2.0)
AM_INIT_AUTOMAKE([1.9 tar-pax])
AM_MAINTAINER_MODE([disable])
AC_CANONICAL_HOST
Expand Down
159 changes: 155 additions & 4 deletions plugins-scripts/Nagios/DBD/Oracle/Server/Database/Tablespace.pm
Expand Up @@ -269,6 +269,157 @@ my %ERRORCODES=( 0 => 'OK', 1 => 'WARNING', 2 => 'CRITICAL', 3 => 'UNKNOWN' );
$initerrors = 1;
return undef;
}
} elsif (($params{mode} =~ /server::cdatabase::tablespace::usage/) ||
($params{mode} =~ /server::cdatabase::tablespace::free/) ||
($params{mode} =~ /server::cdatabase::tablespace::listtablespaces/)) {
my @tablespaceresult = ();
if (DBD::Oracle::Server::return_first_server()->version_is_minimum("9.x")) {
my $tbs_sql_undo = q{
-- freier platz durch expired extents
-- speziell fuer undo tablespaces
-- => bytes_expired
SELECT
tablespace_name, bytes_expired, con_id
FROM
(
SELECT
tablespace_name,
SUM (bytes) bytes_expired,
status,
con_id
FROM
cdb_undo_extents
GROUP BY
con_id, tablespace_name, status
)
WHERE
status = 'EXPIRED'
};
my $tbs_sql_undo_empty = q{
SELECT NULL AS tablespace_name, NULL AS bytes_expired, NULL AS con_id FROM DUAL
};
my $tbs_sql_temp = q{
UNION
SELECT
e.name||'_'||b.tablespace_name "Tablespace",
b.status "Status",
b.contents "Type",
b.extent_management "Extent Mgmt",
sum(a.bytes_free + a.bytes_used) bytes, -- allocated
SUM(DECODE(d.autoextensible, 'YES', d.maxbytes, 'NO', d.bytes)) bytes_max,
SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free
FROM
sys.v_$TEMP_SPACE_HEADER a, -- has con_id
sys.cdb_tablespaces b, -- has con_id
sys.v_$Temp_extent_pool c,
cdb_temp_files d, -- has con_id
v$containers e
WHERE
a.file_id = c.file_id(+)
AND a.file_id = d.file_id
AND a.tablespace_name = c.tablespace_name(+)
AND a.tablespace_name = d.tablespace_name
AND a.tablespace_name = b.tablespace_name
AND a.con_id = c.con_id(+)
AND a.con_id = d.con_id
AND a.con_id = b.con_id
AND a.con_id = e.con_id
GROUP BY
e.name,
b.con_id,
b.status,
b.contents,
b.extent_management,
b.tablespace_name
ORDER BY
1
};
my $tbs_sql = sprintf q{
SELECT /*+ opt_param('optimizer_adaptive_features','false') */
e.name||'_'||a.tablespace_name "Tablespace",
b.status "Status",
b.contents "Type",
b.extent_management "Extent Mgmt",
a.bytes bytes,
a.maxbytes bytes_max,
c.bytes_free + NVL(d.bytes_expired,0) bytes_free
FROM
(
-- belegter und maximal verfuegbarer platz pro datafile
-- nach tablespacenamen zusammengefasst
-- => bytes
-- => maxbytes
SELECT
a.con_id,
a.tablespace_name,
SUM(a.bytes) bytes,
SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes)) maxbytes
FROM
cdb_data_files a
GROUP BY
con_id, tablespace_name
) a,
sys.cdb_tablespaces b,
(
-- freier platz pro tablespace
-- => bytes_free
SELECT
a.con_id,
a.tablespace_name,
SUM(a.bytes) bytes_free
FROM
cdb_free_space a
GROUP BY
con_id, tablespace_name
) c,
(
%s
) d,
v$containers e
WHERE
a.tablespace_name = c.tablespace_name (+)
AND a.tablespace_name = b.tablespace_name
AND a.tablespace_name = d.tablespace_name (+)
AND a.con_id = c.con_id(+)
AND a.con_id = b.con_id
AND a.con_id = d.con_id(+)
AND a.con_id = e.con_id
%s
%s
}, $params{notemp} ? $tbs_sql_undo_empty : $tbs_sql_undo,
$params{notemp} ? "AND (b.contents != 'TEMPORARY' AND b.contents != 'UNDO')" : "",
$params{notemp} ? "" : $tbs_sql_temp;
$tbs_sql = join "\n", grep !/^\s*$/, split(/\n/, $tbs_sql);
@tablespaceresult = $params{handle}->fetchall_array($tbs_sql);
}
foreach (@tablespaceresult) {
my ($name, $status, $type, $extentmgmt, $bytes, $bytes_max, $bytes_free) = @{$_};
next if $params{notemp} && ($type eq "UNDO" || $type eq "TEMPORARY");
next if $params{noreadonly} && ($status eq "READ ONLY");
next if $params{container} && ($name !~ /^$params{container}_/i);
if ($params{regexp}) {
next if $params{selectname} && $name !~ /$params{selectname}/;
} else {
next if $params{selectname} && lc $params{selectname} ne lc $name;
}
# host_filesys_pctAvailable
my %thisparams = %params;
$thisparams{name} = $name;
$thisparams{bytes} = $bytes;
$thisparams{bytes_max} = $bytes_max;
$thisparams{bytes_free} = $bytes_free;
$thisparams{status} = lc $status;
$thisparams{type} = lc $type;
$thisparams{extent_management} = lc $extentmgmt;
my $tablespace = DBD::Oracle::Server::Database::Tablespace->new(
%thisparams);
add_tablespace($tablespace);
$num_tablespaces++;
}
if (! $num_tablespaces) {
$initerrors = 1;
return undef;
}
} elsif ($params{mode} =~ /server::database::tablespace::fragmentation/) {
my @tablespaceresult = $params{handle}->fetchall_array(q{
SELECT
Expand Down Expand Up @@ -407,7 +558,7 @@ sub init {
my %params = @_;
$self->init_nagios();
$self->set_local_db_thresholds(%params);
if ($params{mode} =~ /server::database::tablespace::(usage|free)/) {
if ($params{mode} =~ /server::[c]*database::tablespace::(usage|free)/) {
if (! defined $self->{bytes_max} || $self->{bytes_max} eq '') {
# eq '' kommt z.b. vor, wenn ein datafile online_status recover hat
# in dba_data_files sind dann bytes und maxbytes nicht belegt (Null)
Expand Down Expand Up @@ -450,7 +601,7 @@ sub init {
}
$self->{percent_free} = 100 - $self->{percent_used};
my $tlen = 20;
my $len = int((($params{mode} =~ /server::database::tablespace::usage/) ?
my $len = int((($params{mode} =~ /server::[c]*database::tablespace::usage/) ?
$self->{percent_used} : $self->{percent_free} / 100 * $tlen) + 0.5);
$self->{percent_as_bar} = '=' x $len . '_' x ($tlen - $len);
} elsif ($params{mode} =~ /server::database::tablespace::fragmentation/) {
Expand Down Expand Up @@ -524,7 +675,7 @@ sub nagios {
my $self = shift;
my %params = @_;
if (! $self->{nagios_level}) {
if ($params{mode} =~ /server::database::tablespace::usage/) {
if ($params{mode} =~ /server::[c]*database::tablespace::usage/) {
if (! $self->{bytes_max}) {
$self->check_thresholds($self->{percent_used}, "90", "98");
if ($self->{status} eq 'offline') {
Expand Down Expand Up @@ -571,7 +722,7 @@ sub nagios {
lc $self->{name},
$self->{fsfi},
$self->{warningrange}, $self->{criticalrange});
} elsif ($params{mode} =~ /server::database::tablespace::free/) {
} elsif ($params{mode} =~ /server::[c]*database::tablespace::free/) {
# ->percent_free
# ->real_bytes_max
#
Expand Down
6 changes: 6 additions & 0 deletions plugins-scripts/check_oracle_health.pl
Expand Up @@ -93,6 +93,9 @@ package main;
['server::database::tablespace::free',
'tablespace-free', undef,
'Free space in tablespaces' ],
['server::cdatabase::tablespace::free',
'container-tablespace-free', undef,
'Free space in tablespaces of container databases' ],
['server::database::tablespace::remainingfreetime',
'tablespace-remaining-time', undef,
'Remaining time until a tablespace is full' ],
Expand Down Expand Up @@ -201,6 +204,9 @@ package main;
['server::database::tablespace::listtablespaces',
'list-tablespaces', undef,
'convenience function which lists all tablespaces' ],
['server::cdatabase::tablespace::listtablespaces',
'container-list-tablespaces', undef,
'convenience function which lists all tablespaces of all container databases' ],
['server::database::tablespace::datafile::listdatafiles',
'list-datafiles', undef,
'convenience function which lists all datafiles' ],
Expand Down

0 comments on commit 9277f06

Please sign in to comment.