[Date Prev]   [Date Next] [Thread Prev]   [Thread Next] [Date Index]   [Thread Index]

 

     Re: [nocol-users] MySQL monitor?

On Thu, Jan 13, 2000 at 10:37:37PM -0500, Velocet wrote:
> then TTSG's all..
> > Hi,
> > 
> > 	Has anyone written a MySQL monitor?
> 
>   [MySQL PHP-based Web Page stuff, deleted]

Myself, I just monitor the MySQL port (port 3306 by default)... you can
also use something like Perl DBI to do some basic connections and check
stuff out (this is very basic skeleton pseudo-code (off the top of my
head), though, and not really intended to be 100% useable -- filling out
everything else (like the interaction with NOCOL) left as an exercise):


-- begin
#!/usr/local/bin/perl


# The DBD...
$dbd = 'mysql';

# The database name and table name...
$database = "DB_name";
$db_table = "DB_table_name";

# The username and password for the database...
$db_user = "USER_nobody";
$db_password = "USER_Nobody's Password";

# The server name and port on which the database lives...
$db_server = "localhost";
$db_port = "3306";

  [...]

# Connect to the database (get database handle)...
my( $dbh ) = DBI->connect( "DBI:${dbd}:${database}:${db_server}:${db_port}",
                     $db_user, $db_password );
if ( ! dbh ){
  # No DB Handle... something failed...
  print STDERR "Error connecting to database: $DBI::errstr\n";

  # Talk to NOCOL...

  exit( 1 );
}

# Dump the DB...

# Prepare a command for execution (get statement handle)...
my( $sth ) = $dbh->prepare( "SELECT * FROM ${db_table}" );
if ( ! sth ){
  # No session handle, something failed...
  print STDERR "Problem with DBH->prepare: $DBI::errstr\n";

  # Talk to NOCOL...

  exit( 1 );
}

# Execute the command...
$sth->execute;

while( my( $row ) = $sth->fetchrow ){
  # Do something interesting, like count rows...
}

# We're done...
$sth->finish;

# Disconnect from the database...
$dbh->disconnect;

-- end



-- 
Russell M. Van Tassell
russell@cscorp.com

    "I am not part of the problem. I am a Republican."  -- VP Dan Quayle