Skip to content

Instantly share code, notes, and snippets.

@maazanjum
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maazanjum/f9b080f44d48d9711caa to your computer and use it in GitHub Desktop.
Save maazanjum/f9b080f44d48d9711caa to your computer and use it in GitHub Desktop.
#
# Author(s): Maaz Anjum & Tucker Thompson
# Purpose: Monitor GoldenGate instances managed by Oracle XAG
#
#!/usr/bin/perl -w
use strict;
use warnings;
use Switch;
###################################################
# Change this variables as per your environment #
# Alternatively, this could just as well be a #
# parameter that is passed to this script. #
# #
# #
BEGIN {
$ENV{'GRID_BIN'}='/u01/app/11.2.0.3/grid/bin';
$ENV{'XAG_BIN'}='/u01/app/11.2.0.3/xag/bin';
}
# #
###################################################
#
# GoldenGate Status, Lag etc variables/arrays
#
my @GG_LIST = `agctl status goldengate | awk '{ print \$3 }' | sed "s/'//g"`;
my @NODES= `\$GRID_BIN/olsnodes`;
my $GG;
my $GG_LOC;
my $GG_DN;
my $MGR;
my $WHERE;
my $NODE;
my $AGCTL;
my $line;
# Variables to store the output
my $program;
my $status;
my $statusid;
my $group;
my $lagatchkpt;
my $timesincechkpt;
# Variables for formatting Lag Times
my $hours;
my $minutes;
my $seconds;
#
# The output of "# agctl status goldengate" will list all instances of GoldenGate,
# including their respective homes, and nodes.
#
foreach $GG (@GG_LIST) {
chomp($GG);
#
# Retrieve the GoldenGate instance home location
#
$GG_LOC=`\$XAG_BIN/agctl config goldengate "$GG" | grep "GoldenGate location" | cut -c 25-`;
#
# Retrieve the GoldenGate instance's Default Node
#
$GG_DN=`\$XAG_BIN/agctl config goldengate "$GG" | grep "Configured to run on Nodes" | awk '{ print \$6 }'`;
$AGCTL=`\$XAG_BIN/agctl status goldengate "$GG"`;
chomp($GG_LOC);
chomp($GG_DN);
chomp($AGCTL);
$WHERE="";
#
# This portion checks on which node (in the cluster)
# where the Manager process is actually running.
#
foreach $NODE (@NODES) {
chomp($NODE);
$MGR=`ssh "$NODE" ps -ef | grep -i mgr | grep -v grep | grep "$GG_LOC"`;
if ($MGR eq '') {}
else {$WHERE=$NODE}
}
if ($WHERE eq '') {$WHERE=$GG_DN}
#
# Execute GGSCI check
#
my @buf = `ssh "$WHERE" $GG_LOC/ggsci << EOF
info all
EOF`;
foreach $line (@buf)
{
chomp($line);
if($line =~ m/(MANAGER|EXTRACT|REPLICAT|PUMP)/)
{
no warnings 'uninitialized';
($program, $status, $group, $lagatchkpt, $timesincechkpt) = split(" ", $line);
if ($group eq "") {
$group = $program }
# Parse Lag @ CheckPoint
if ($lagatchkpt eq "") {
$lagatchkpt = "00:00:00" }
($hours, $minutes, $seconds) = split (/:/, $lagatchkpt);
$lagatchkpt = ($hours*60*60)+($minutes*60)+($seconds);
# Parse Time Since Last CheckPoint
if ($timesincechkpt eq "") {
$timesincechkpt = "00:00:00" }
($hours, $minutes, $seconds) = split (/:/, $timesincechkpt);
$timesincechkpt = ($hours*60*60)+($minutes*60)+($seconds);
switch ($status) {
case("RUNNING") { $statusid=0; }
case("STOPPED") { $statusid=1; }
case("ABENDED") { $statusid=2; }
}
#
# Print the output which is directly read by
# Enterprise Manager's Metric Extension framework
#
print "$GG|$group|$program|$status|$lagatchkpt|$timesincechkpt|$statusid|$WHERE|$AGCTL|$GG_LOC\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment