I just installed the Everything engine on my own site, and I noticed that it was putting quite a bit of stress on MySQL. I kept checking `mysqladmin -p status` every few minutes to see how bad the damage was.

But then I figured that I might as well make something in Perl to do this for me, and make it accessible through a browser. So I came up with this.
Simply put the following two files in $WWWROOT/mysqlstatus or something. The .pl file can be named whatever, but the second file needs to be named "mysqltable.html" and placed in the same directory.

So, here's the code.


mysqlstatus.pl
#!/usr/bin/perl use DBI; use CGI; my $q = new CGI; select(STDERR); $|++; select(STDOUT); ############## my %desc; my $data; { local $/ = undef; open(DATA, "mysqltable.html"); $data = <DATA>; } $data =~ s/<(?:TR|TD|\/TD|\/TR|TABLE|TBODY|\/TABLE|\/TBODY)>//g; my @lines = split "\n\n", $data; my $key; foreach my $val (@lines) { $val =~ s/<CODE>(.*)<\/CODE>/$key=$1;"";/e; $desc{$key} = $val if $key; } ############### my $rootpwd = $q->param('rootpwd'); if($rootpwd) { status(); } else { login(); } sub login { my $wasproblem = shift; my $html = "<html><head><title>MySQLStatus</title></head><body><h1 +>MySQLStatus</h1>"; $html .= "<font color=red><b>$wasproblem</b></font><br>" if $waspr +oblem; $html .= "In order to view the status of your MySQL server, please + enter the MySQL root password.<br>" . "<form action='mysqlstatus.pl' method=post><b>MySQL root p +assword:</b> <input type=text name=rootpwd>" . "<br><input type=submit value='Log in'></form></body></htm +l>\n"; print $html; exit; } sub status { my $dbh = DBI->connect('dbi:mysql:mysql:localhost:3306', 'root', $ +rootpwd) or login($DBI::errstr); my $sth = $dbh->prepare("SHOW STATUS;"); $sth->execute(); my($key, $val, $bgcolor); my $color = 0; print "<html><head><title>MySQLStatus</title><base href=\"http://w +ww.mysql.com/doc/\"></head><body><h1>MySQL Server on localhost:3306</ +h1><table>"; while(($key, $val) = $sth->fetchrow_array()) { $bgcolor = ($color++ % 2? "#BECDDA" : "#DEE6ED"); print "<tr bgcolor='$bgcolor'><td>$key</td><td>$val</td><td>$d +esc{$key}</td></tr>"; } print "</table></body></html>"; }


mysqltable.html
Please download this file from http://aboutpcs.com/mysqlstatus/mysqltable.html and place it in the same folder as the script above, named "mysqltable.html" Because this HTML file has <code> tags in it, I can't post it here. :(

The code is by me, and the docs for each statistic (mysqltable.html) were ripped from mysql.com.

This has worked perfectly for me, so far. I would be interested in hearing if any of you have any issues with it.

Enjoy!

Quinn Slack
perl -e 's ssfhjok qupyrqs&&tr sfjkohpyuqrspitnrapj"hs&&eval&&s&&&'

In reply to MySQL Status Tool by qslack

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.