473,761 Members | 7,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mysql health check script

4 New Member
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_si ze 32768
bulk_insert_buf fer_size 8388608
character_set_c lient latin1
character_set_c onnection latin1
character_set_d atabase latin1
character_set_r esults latin1
character_set_s erver latin1
character_set_s ystem 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 6850
eWish
971 Recognized Expert Contributor
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
7408
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 database. Is my understanding correct? At the moment, I pass all my data through htmlentities() before writing to my database. Is this enough? Should I check each individual columns length
10
1499
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 during the client connection sequence was upgraded in MySQL 4.1.1 to be very secure" Has anyone actually tested this by "sniffing" their packets during use? Also, does anybody know if this applies when using VB to connect using the connection...
1
2282
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 *** below. Any ideas? <script type="text/javascript"> Set_Cookie( 'test', 'none', '', '/', '', '' ); if ( Get_Cookie( 'test' ) )
0
1565
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 report for the databases. Also suggest me gud books for learning DB2. Thanks in advance,
10
1822
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 memory access to the database. Also disallows http:// includes. This is where the database of names is stored. This is our internal MySQL server. Server 2 - Only allows shared memory access to the database. So anything that calls the...
1
1971
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 page...for example: launch_video.php printf("Movie %s: <a href='http://.../embedded_flash_video.html'>%s</a> and 2) I can print the URL as output from server via PHP script...for example: launch_video.php printf("Movie %s: <a...
4
10679
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 = trim($fcontents); $arr = explode("\t", $line); $sql = "insert into TABLENAME values ('". implode("','", $arr) ."')"; mysql_query($sql); echo $sql ."<br>\n";
3
5513
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 , returen the curser to the old select -City . Can you Solve this problem for me. Thanks Const cServer="localhost"
0
9531
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.