               Using MySQLadmin status with MRTG
		 by Luuk de Boer <luuk@pi.net>
------------------------------------------------------------------------------
First release:	1997-01-09
	- initial release ...
Update:		1997-01-12
	- let's call it version 1.0 :-)
	- updated this README file
	Changed in mysqlstatus:
	- changed the number of questions to the not-buggy version of mysqld.
	  patch for the good number of questions is mailed on the mailinglist.
	- changed number of threads to 'not relative' ... so you can see now
	  how many threads are running. 
	- added the possibility for arguments (hostname and portnumber) so
	  you can use one mysqlstatus script for several hosts where a mysql 
	  db server is running
	- set default values (all 0) so mrtg won't fail if mysql is down and
	  uptime is set to Server is down when mysql is down.
	- current number of questions is used when current number of questions
	  is lower as the old number of questions (for example when you 
	  shutdown and start the mysql server)
	- added some comment so everybody can read what is done where ....
	Changed in mysql.cfg:
	- played with the configuration a bit and added some options.
	- changed the legend text.
	- added some comment for use of mysqlstatus
------------------------------------------------------------------------------

After one e-mail in the mailinglist I thought ... that's a nice
idea. That can't be that hard so let's try it.
It's developed at linux redhat 4.2 and 5.0 with mysql 3.21.19.
But mysql 3.21.19 has a little bug in the status value of the 
number of questions asked since the uptime so for real bullit
proof version we have to wait till that bug is fixed (that 
won't take long with Monty programming mysql ... only a couple 
of days)(bug is fixed by Monty ... Thanks offcourse Monty).

What did I do to make it as easy for me as possible .....
Just tried the mailstats in the contrib dir of mrtg and 
did some little changes to it so it would work for mysql.
Added some nice things such as using one script for several hosts
and some default values if the mysql server is down. 

When the mysql db server isn't running on your server where mrtg is
running then you have to make some changes in the inetd.conf and
/etc/services file. Take care that it isn't that secure to do it, so
restrict for full security set some wrappers around it and be sure
only the mrtg server can connect to that port.

You don't need some extra things to get this running ...
Only the things mrtg uses also ....

#############
Here goes:

1:  Ensure you have "/usr/local/bin/mysqladmin" on your system.
or  Ensure you have "/usr/local/mysql/bin/mysqladmin" on your system.

not -> then add in mysqlstatus the path of mysqladmin to @mysqladminpaths.

2:  if you are running the mysqld server on a different server as you run
    mrtg then create the following shell-script:
    (in the contrib dir you will find the shell-script)

	#!/bin/sh
	# mysql-stats:  exec mysqladmin status
	#
	if [ -x "/usr/local/bin/mysqladmin" ]
	then
	exec /usr/local/bin/mysqladmin status 
	fi
	
I run this out of /usr/local/bin, and call it "mysql-stats"

4:  Now add the following to /etc/services:

	# /etc/services
	#
	mysql-stats      7257/tcp                        # mysql-stats

You might like to select something else. But this portnumber is default
for mysql-stats

5:  Add the following to /etc/inetd.conf:

	# /etc/inetd.conf
	#
	mysql-stats      stream  tcp     nowait root \
	/usr/local/bin/mysql-stats mysql-stats


***Ensure that the above is all on *one* line.  The sample above
is broken on 2 lines for legibility!!


6:  Restart inetd


7:  Test the port.  you should see the following:
    (change localhost to the servername where mysql db server is running)
# telnet localhost 7257
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Uptime: 13397  Running threads: 1  Questions: 177921  Reloads: 1  Open tables: 0
Connection closed by foreign host.

OK!!

we get Uptime: threads: and Questions: and make some nice gifs out of it 

####################################
Stage 2:  MRTG

Here is a perl script I wrote to parse that line 
and message them into something mrtg understands.

A file called "mysqlstatus.old" is written to /tmp
to have the diff of the last value.

see the contrib dir of mrtg for the perl script (mysqlstatus)
mysqlstatus can have some extra arguments.
Defaults for mysqlstatus are:
hostname = localhost and portnumber = 7257
if hostname is 'localhost' then it won't connect to the portnumber but
will run directly 'mysqladmin status'
but you can do:
	mysqlstatus servername
and it will connect to servername + portnumber 7257
and:
	mysqlstatus servername 3208
will connect to servername + portnumber 3208

##########################

Now,  the Configuration of the mysql stats in mrtg.
You can find my configuration settings in the file mrtg.cfg. But you are
offcourse free to change it.

I run mrtg from cron on my Linux box every 5 minutes to plot the stats.

That's it!!

You should have no problems running this stuff if you follow my
instructions.

Any comments, advice or interesting suggestions 
would be much appreciated.

have fun...

Luuk de Boer <luuk@pi.net> 1998-01-09
-------------------------------------------------------------------------------
