473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

mysql health check script

Hi,

I am coding a mysql health check script. The logic is to execute the commands (only once)show status,show slave status,show variables and fetch the variable name and value in a hash refer or any other fetch machanism and dynamically use the values to do calculation like the following

Expand|Select|Wrap|Line Numbers
  1. threhold values($uptime > 10800) && (Handler_read_rnd_next > 4000) && ((100-(((Handler_read_rnd_next + Handler_read_rnd) / (##Handler_read_rnd_next + Handler_read_rnd + Handler_read_first + Handler_read_next + Handler_read_key + Handler_read_prev))*100))
  2.  
if any one can code using hash reference and use cloumn name to do calculation..
Show variables would result the following output.There are other 189 variables which will be used to do the above calculation.
mysql> show variables;
Variable_name | Value
-------------------------------------------------------
back_log 50
basedir /
binlog_cache_size 32768
bulk_insert_buffer_size 8388608
character_set_client latin1
character_set_connection latin1
character_set_database latin1
character_set_results latin1
character_set_server latin1
character_set_system utf8

my current code is

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. # Check the health of a mysql server.
  3. #
  4. use Getopt::Long;
  5. use DBI;
  6. #use strict;
  7. #use warning;
  8.  
  9. my $Variable_name = '';
  10. my $status = '';
  11. # --
  12. # Print out the usage message
  13. # --
  14. sub usage {
  15.     print "usage: check_mysqlhealth.pl -H <host> -u <user> -p <password> \n";
  16.     print "       Optional parameters:\n";
  17.     print "       --port <port> \n";
  18. }
  19.  
  20. $|=1;
  21.  
  22. # --
  23. # Parse arguments and read Configuration
  24. # --
  25. my ($host, $user, $password, $port);
  26. GetOptions (
  27.     'host=s' => \$host,
  28.     'H=s' => \$host,
  29.     'user=s' => \$user,
  30.     'u=s' => \$user,
  31.     'password=s' => \$password,
  32.     'p:s' => \$password,
  33.     'port=i' => \$port,
  34. );
  35.  
  36. if (!$host || !$user) {
  37.     usage();
  38.     exit(1);
  39. }
  40.  
  41. if (!$port) {
  42.     $port = 3306;
  43. }
  44.  
  45. my $totalTime = time();
  46.  
  47. # --
  48. # Establish connection
  49. # --
  50. my $state = "OK";
  51. my $dbh;
  52. eval {
  53.     $dbh = DBI->connect("DBI:mysql:host=$host;port=$port", $user, $password, {'RaiseError' => 1});
  54. print "connected\n";
  55. };
  56.  
  57. if ($@) {
  58.     my $status = $@;
  59.     print 'CRITICAL: Connect failed with reason ' . $status . "\n";
  60.     exit 2;
  61. }
  62.  
  63. &shvar;
  64.  
  65. sub shvar
  66.  {
  67.     my $sgv = $dbh->prepare("show variables");
  68.     $sgv->execute();
  69.    %MySQL_Variables = ();
  70.     while (my ($name,$value) = $sgv->fetchrow_array())
  71. {
  72.       print "$MySQL_Variables{lc($name)} = $value\n";
  73.  
  74.     }
  75. }
  76.  
This code is listing the variables, now how can i fetch a particular variable to do computation..

Need help desperately...
Nov 17 '07 #1
1 6812
eWish
971 Expert 512MB
Instead of using "Show Variable" just do a "Select" statement.

Expand|Select|Wrap|Line Numbers
  1. my (@rows);
  2.  
  3. my $select = $dbh->prepare('SELECT column1, column2, column3 FROM table_name WHERE column1 = ?');
  4.    $select->execute($value_for_column_criteria);
  5.  
  6.    while (@rows = $select->fetchrow_array) {
  7.        print join("\n", @rows);
  8.        }       
--Kevin
Dec 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Randell D. | last post by:
Folks, I've heard of buffer overflows being used/abused by hackers and believe one method to reduce this from happening is to check the length of my form data before writing it to my MySQL...
10
by: Bob Hollness | last post by:
OK. The below text is from the MySQL website. "When you connect to a MySQL server, you should use a password. The password is not transmitted in clear text over the connection. Password handling...
1
by: StevePBurgess | last post by:
I am using a script (see below) to check if cookies are enabled on my website. The script seems to work but I get an Object Expected error. The error repor says it is at the line incidated by the...
0
by: Maddy | last post by:
Hi all, I am new to DB2 database.I just have the basic knowledge abt this database.I in a serious situation of handling 5 large databases.Can some one help me how to prepare the health check...
10
by: Jerim | last post by:
I am attempting to put together one script that pulls data from one database on its own server, and data from another database on its own server, which is off-site. Server 1 - Only allows shared...
1
by: Ernest | last post by:
Trying to launch my flash videos by passing their URL listed in a field on MYSQL via PHP script. Any help is greatly appreciated. 1) I am able to launch the video referenced directly in main...
4
by: meeanji | last post by:
php codes goes like this<? $fcontents = file ('./spreadsheet.xls'); # expects the csv file to be in the same dir as this script for($i=0; $i<sizeof($fcontents); $i++) { $line =...
3
by: alandiit | last post by:
Hi every body I would like connect three combo box (CascadingDropDown with a Database) MYSQL by asp classic or Java Script . But I have a problem with this example , when I will change City ,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.