--- pmdaoracle1.pl 2016-01-19 14:19:10.934455190 +1100 +++ pmdaoracle.pl 2016-01-19 16:46:34.474085967 +1100 @@ -32,11 +32,12 @@ for my $file ( '/etc/pcpdbi.conf', # sys eval `cat $file` unless ! -f $file; } -use vars qw( $pmda %sid_instances ); +use vars qw( $pmda %sid_instances %sysstat_instances ); use vars qw( %latch_instances %file_instances %rollback_instances ); use vars qw( %reqdist_instances %rowcache_instances %session_instances ); use vars qw( %object_cache_instances %system_event_instances ); use vars qw( %librarycache_instances %waitstat_instances ); +use vars qw( %sysstat_map ); my $latch_indom = 0; my $file_indom = 1; @@ -48,7 +49,10 @@ my $object_cache_indom = 6; my $system_event_indom = 7; my $librarycache_indom = 8; my $waitstat_indom = 9; -my $sid_indom = 10; +my $sid_indom = 10; # (may need to be replaced?) +my $license_indom = 11; +my $version_indom = 12; +my $sysstat_indom = 13; my @novalues = (); my %object_cache_instances = ( @@ -64,14 +68,14 @@ my %object_cache_instances = ( 'OTHER' => \@novalues ); #has 136 statictic#. Commented the metrics that I could not find those in my oracle and rewrote the $item numbers. #my $sysstat_statistics = "(2,3,4,5,6,7,8,9,10,14,17,18,19,29,30,31,32,33,34,35,37,38,40,41,42,43,44,45,128,132,141,152,172,147,192,148,314,306,193,194,195,198,181,182,247,248,249,257,258,262,263,264,275,294,299,300,301,381,382,490,491,492,493,686,687,692,695,696,697,698,699,1082,1083,1084,1089,1100,1101,1102,1032,1059,149,207,208,688,690,209,210,495,496,497,498,499,500,501,506,507,508,509,510,691,1033,205,206,199,202,203,204,200,201,173,178,179,180,251,489,516,517,1085,1091,1090,1092,1094,1093,1095,1060,1061,1062,1070,1071,1072,1073,1074,1075,1076,1162,1163)"; +# [ http://onlinelibrary.wiley.com/doi/10.1002/9781118135532.app5/pdf ] my %sids_by_name; my %tables_by_name = ( 'sysstat' => { insts_handle => undef, fetch_handle => undef, values => {}, - # insts => SID indom is a static array - fetch => 'SELECT statistic#, value FROM v$sysstat' }, - #fetch => "select * from (select STATISTIC#, value from v\$sysstat) pivot (max(value) for STATISTIC# in $sysstat_statistics)" }, + insts => 'SELECT sid FROM v$session', + fetch => 'SELECT statistic#, name, value FROM v$sysstat' }, 'license' => { insts_handle => undef, fetch_handle => undef, values => {}, fetch => 'SELECT SESSIONS_MAX, SESSIONS_CURRENT, SESSIONS_WARNING,' . @@ -145,7 +149,7 @@ my %tables_by_cluster = ( '0' => { name => 'sysstat', setup => \&setup_sysstat, - indom => $sid_indom, + indom => $sysstat_indom, values => \&sysstat_values }, '1' => { name => 'license', @@ -274,7 +278,7 @@ sub oracle_refresh my $refresh = $tables_by_cluster{"$cluster"}{values}; &$refresh($db, $sid, $tables_by_name{$name}{fetch_handle}); } - } +} sub oracle_fetch_callback { @@ -375,16 +379,16 @@ sub version_values my ( $dbh, $sid, $handle ) = @_; my $result = refresh_results($dbh, $handle); - %sid_instances = (); + %version_instances = (); if (defined($result)) { for my $i (0 .. $#{$result}) { my $banner = $result->[$i][0]; my $instname = "$sid/$banner"; my $values = $result->[$i]; - $sid_instances{$instname} = $values; + $version_instances{$instname} = $values; } } - $pmda->replace_indom($sid_indom, \%sid_instances); + $pmda->replace_indom($version_indom, \%version_instances); } @@ -433,26 +437,24 @@ sub latch_values $pmda->replace_indom($latch_indom, \%latch_instances); } - - -sub license_values { - +sub license_values +{ my ( $dbh, $sid, $handle ) = @_; my $result = refresh_results($dbh, $handle); - %sid_instances = (); + %license_instances = (); if (defined($result)) { for my $i (0 .. $#{$result}) { my $instname = "$sid/license"; my $values = $result->[$i]; - $sid_instances{$instname} = $values; + $license_instances{$instname} = $values; } } - $pmda->replace_indom($sid_indom, \%sid_instances); + $pmda->replace_indom($license_indom, \%license_instances); } -sub filestat_values { - +sub filestat_values +{ my ( $dbh, $sid, $handle ) = @_; my $result = refresh_results($dbh, $handle); @@ -469,8 +471,8 @@ sub filestat_values { $pmda->replace_indom($file_indom, \%file_instances); } -sub rollstat_values { - +sub rollstat_values +{ my ( $dbh, $sid, $handle ) = @_; my $result = refresh_results($dbh, $handle); @@ -580,26 +582,32 @@ sub reqdist_values { $pmda->replace_indom($reqdist_indom, \%librarycache_instances); } - -sub sysstat_values { - - my ( $dbh, $sid, $handle) = @_; +sub sysstat_values +{ + my ( $dbh, $sid, $handle ) = @_; my $result = refresh_results($dbh, $handle); - %sid_instances = (); - my $item=1; - my @sysstat_stats=(90, 510, 666, 111); + %sysstat_instances = (); if (defined($result)) { for my $i (0 .. $#{$result}) { - my $static_num = $result->[$i][0]; - if ($static_num==$sysstat_stats[$item]){ - my $instname = "$sid/statistic# $static_num"; - my $values = $result->[$i]; - $sid_instances{$instname} = $values; + my $statistic_num = $result->[$i][0]; + my $statistic_name = $result->[$i][1]; + my $pmid_item_num = $sysstat_map{$statistic_name}; + + if (defined($pmid_item_num)) { + # + # pull out the current array of values, and insert this value + # at the offset specific for the found PMID item number, such + # that a subsequent fetch callback can quickly look it up. + # + my $values = $sysstat_instances{$sid}; + my @varray = @{$values}; + $varray[$pmid_item_num] = $result->[$i][2]; + $sysstat_instances{$sid} = \@varray; } } } - $pmda->replace_indom($sid_indom, \%sid_instances); + $pmda->replace_indom($sysstat_indom, \%sysstat_instances); } @@ -710,7 +718,7 @@ from the TIME column of the V$WAITSTAT v sub setup_version # version data from the v$version view { - $pmda->add_metric(pmda_pmid(11,0), PM_TYPE_STRING, $sid_indom, + $pmda->add_metric(pmda_pmid(11,0), PM_TYPE_STRING, $version_indom, PM_SEM_DISCRETE, pmda_units(0,0,0,0,0,0), 'oracle.version', 'Oracle component name and version number', ''); @@ -754,31 +762,36 @@ and converted to units of milliseconds.' sub setup_sysstat ## statistics from v$sysstat { - $pmda->add_metric(pmda_pmid(0,0), PM_TYPE_U32, $sid_indom, + $sysstat_map{'logons cumulative'} = 0; + $pmda->add_metric(pmda_pmid(0,0), PM_TYPE_U32, $sysstat_indom, PM_SEM_COUNTER, pmda_units(0,0,1,0,0,PM_COUNT_ONE), 'oracle.sysstat.logons', 'Total cumulative logons', 'The "logons cumulative" statistic from the V$SYSSTAT view. This is the total number of logons since the instance started.'); - $pmda->add_metric(pmda_pmid(0,1), PM_TYPE_U32, $sid_indom, + $sysstat_map{'logons current'} = 1; + $pmda->add_metric(pmda_pmid(0,1), PM_TYPE_U32, $sysstat_indom, PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), 'oracle.sysstat.curlogons', 'Total current logons', 'The "logons current" statistic from the V$SYSSTAT view. This is the total number of current logons.'); - $pmda->add_metric(pmda_pmid(0,2), PM_TYPE_U32, $sid_indom, + $sysstat_map{'opened cursors cumulative'} = 2; + $pmda->add_metric(pmda_pmid(0,2), PM_TYPE_U32, $sysstat_indom, PM_SEM_COUNTER, pmda_units(0,0,1,0,0,PM_COUNT_ONE), 'oracle.sysstat.opencursors', 'Total cumulative opened cursors', 'The "opened cursors cumulative" statistic from the V$SYSSTAT view. This is the total number of cursors opened since the instance started.'); - $pmda->add_metric(pmda_pmid(0,3), PM_TYPE_U32, $sid_indom, + $sysstat_map{'opened cursors current'} = 3; + $pmda->add_metric(pmda_pmid(0,3), PM_TYPE_U32, $sysstat_indom, PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), 'oracle.sysstat.current_cursors', 'Total current open cursors', 'The "opened cursors current" statistic from the V$SYSSTAT view. This is the total number of current open cursors.'); - $pmda->add_metric(pmda_pmid(0,4), PM_TYPE_U32, $sid_indom, + $sysstat_map{'user commits'} = 4; + $pmda->add_metric(pmda_pmid(0,4), PM_TYPE_U32, $sysstat_indom, PM_SEM_COUNTER, pmda_units(0,0,1,0,0,PM_COUNT_ONE), 'oracle.sysstat.user_commits', 'Total user commits', 'The "user commits" statistic from the V$SYSSTAT view. When a user @@ -786,14 +799,16 @@ commits a transaction, the redo generate made to database blocks must be written to disk. Commits often represent the closest thing to a user transaction rate.'); - $pmda->add_metric(pmda_pmid(0,5), PM_TYPE_U32, $sid_indom, + $sysstat_map{'user rollbacks'} = 5; + $pmda->add_metric(pmda_pmid(0,5), PM_TYPE_U32, $sysstat_indom, PM_SEM_COUNTER, pmda_units(0,0,1,0,0,PM_COUNT_ONE), 'oracle.sysstat.user_rollbacks', 'Total user rollbacks', 'The "user rollbacks" statistic from the V$SYSSTAT view. This statistic stores the number of times users manually issue the ROLLBACK statement or an error occurs during users\' transactions.'); - $pmda->add_metric(pmda_pmid(0,6), PM_TYPE_U32, $sid_indom, + $sysstat_map{'user calls'} = 6; + $pmda->add_metric(pmda_pmid(0,6), PM_TYPE_U32, $sysstat_indom, PM_SEM_COUNTER, pmda_units(0,0,1,0,0,PM_COUNT_ONE), 'oracle.sysstat.user_calls', 'Total user calls', 'The "user calls" statistic from the V$SYSSTAT view. Oracle allocates @@ -2305,7 +2320,7 @@ obtained from the PINS column of the V$D sub setup_license ## licence data from v$license { - $pmda->add_metric(pmda_pmid(1,0), PM_TYPE_U32, $sid_indom, + $pmda->add_metric(pmda_pmid(1,0), PM_TYPE_U32, $license_indom, PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), 'oracle.license.maxsess', 'Maximum number of concurrent user sessions', @@ -2314,7 +2329,7 @@ instance. This value is obtained from t the V$LICENSE view.'); $pmda->add_metric( - pmda_pmid(1,1), PM_TYPE_U32, $sid_indom, + pmda_pmid(1,1), PM_TYPE_U32, $license_indom, PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), 'oracle.license.cursess', 'Current number of concurrent user sessions', @@ -2323,7 +2338,7 @@ This value is obtained from the SESSIONS V$LICENSE view.'); $pmda->add_metric( - pmda_pmid(1,2), PM_TYPE_U32, $sid_indom, + pmda_pmid(1,2), PM_TYPE_U32, $license_indom, PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), 'oracle.license.warnsess', 'Warning limit for concurrent user sessions', @@ -2332,7 +2347,7 @@ This value is obtained from the SESSIONS V$LICENSE view.'); $pmda->add_metric( - pmda_pmid(1,3), PM_TYPE_U32, $sid_indom, + pmda_pmid(1,3), PM_TYPE_U32, $license_indom, PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), 'oracle.license.highsess', 'Highest number of concurrent user sessions since instance started', @@ -2340,7 +2355,7 @@ V$LICENSE view.'); started. This value is obtained from the SESSIONS_HIGHWATER column of the V$LICENSE view.'); - $pmda->add_metric(pmda_pmid(1,4), PM_TYPE_U32, $sid_indom, + $pmda->add_metric(pmda_pmid(1,4), PM_TYPE_U32, $license_indom, PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), 'oracle.license.maxusers', 'Maximum number of named users permitted',