Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Friday, December 26, 2014

Server Monitoring with Monit Tutorial

As you sit down for a lovely Christmas dinner with family and friends, your phone rings. The frantic client is on the line shouting that the server just went down. Don't you wish you had a helpful program that automatically monitors and restarts the servers automatically.

Monit is an open source process supervision program that monitoring your server processes and restarts failed services. It is easy to setup and relatively painless to use.

Here is a quick tutorial to configure Monit to monitor Apache and MySQL servers.


$ sudo apt-get install monit 

# Monit Configuration settings
$ sudo nano /etc/monit/monitrc 
  set daemon 60 
  set logfile /var/log/monit.log
  set idfile /var/lib/monit/id
  set statefile /var/lib/monit/state
  set eventqueue
  set httpd port 2812 and
   use address localhost
   allow localhost
   include /etc/monit/conf.d/*

# Create Apache2 monitoring file 
$ sudo nano /etc/monit/conf.d/apache2 
check process apache with pidfile /run/apache2.pid
    start program = "/etc/init.d/apache2 start" 
    stop program  = "/etc/init.d/apache2 stop"


# Create  MySQL monitoring file
$ sudo nano /etc/monit/conf.d/mysql 
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
    start program = "/etc/init.d/mysql start"
    stop program = "/etc/init.d/mysql stop"

# Check monit configuration for syntax errors 
$ sudo monit -t 


# Start Monit daemon
sudo service monit start 

# Check Monit status 
$ sudo monit status
The Monit daemon 5.3.2 uptime: 4m 

Process 'mysqld'
  status                            Running
  monitoring status                 Monitored
  pid                               2676
  parent pid                        1
  uptime                            4d 8h 1m 
  children                          0
  memory kilobytes                  256380
  memory kilobytes total            256380
  memory percent                    12.5%
  memory percent total              12.5%
  cpu percent                       0.0%
  cpu percent total                 0.0%
  data collected                    Wed, 10 Dec 2014 08:43:13

Process 'apache'
  status                            Running
  monitoring status                 Monitored
  pid                               4230
  parent pid                        1
  uptime                            4d 8h 1m 
  children                          27
  memory kilobytes                  11556
  memory kilobytes total            391484
  memory percent                    0.5%
  memory percent total              19.1%
  cpu percent                       0.0%
  cpu percent total                 0.0%
  data collected                    Wed, 10 Dec 2014 08:43:13

System 'system_foobar.org'
  status                            Running
  monitoring status                 Monitored
  load average                      [0.00] [0.01] [0.05]
  cpu                               0.0%us 0.0%sy 0.0%wa
  memory usage                      666736 kB [32.6%]
  swap usage                        140 kB [0.0%]
  data collected                    Wed, 10 Dec 2014 08:43:1

That's all folks! Now you have a wonderful Christmas!

Sunday, October 2, 2011

Mytop MySQL Monitoring Tool

If you are a developer or systems administrator who know the MySQL server performance in real time. MyTop tool is just for you. Designed like the traditional 'top' unix program Mytop displays MySQL server information, current mysql processes. It also lets you view complete query information and allows you to kill any MySQL processes. You can get mytop program using systems package installer or download it from mytop project website.

Usage:
You can launch the mytop in the system terminal using the following command line options.
$ mytop -u username -p password -d database

Press f to view full description of selected MySQL query and k to kill the the MySQL process.

You press ? anytime to view more keyboard commands.



 $  mytop -u username -p password -d database

MySQL on localhost (5.1.54-1ubuntu4)                    up 0+06:01:44 [16:26:50]
 Queries: 91.0    qps:    0 Slow:     0.0         Se/In/Up/De(%):    21/00/00/00
              qps now:    0 Slow qps: 0.0  Threads:    4 (   2/   0) 00/00/00/00
 Cache Hits: 17.0  Hits/s:  0.0 Hits now:   0.0  Ratio: 89.5% Ratio now:  0.0%
 Key Efficiency: 100.0%  Bps in/out:   0.2/ 19.0   Now in/out:   8.3/ 2.1k

        Id      User         Host/IP         DB      Time    Cmd Query or State 
        --      ----         -------         --      ----    --- -------------- 
        50      root       localhost      narro         0  Query show full proce
        53     narro       localhost      narro        24  Sleep                
        54     narro       localhost      narro        24  Query SELECT DISTINCT
        45      root       localhost                  543  Sleep                


Thursday, January 31, 2008

Logging PHPnuke Database Connection Failures

Find the db/db.php file in your PHPnuke installation and insert the error_log line.

if(!$db->db_connect_id) { die(”<br><br><center><img src=images/logo.gif><br><br><b>There seems to be a problem with the $dbtype server, sorry for the inconvenience.<br><br>We should be back shortly.</center></b>”);
}

Now the last lines of the db/db.php file should look like this. The error_log simply logs the errors into /home/foo-joe/logs/db_log, you should change this to reflect your directory structure.

if(!$db->db_connect_id) {
error_log(”[”.date(“D M d Y h:iA”).”] Failed to serve request for page ‘”. $_SERVER[‘REQUEST_URI’].”’ from ‘”.$_SERVER[‘REMOTE_ADDR’].”’ using browser ‘”. $_SERVER[‘HTTP_USER_AGENT’].”’\n”,3,”/home/foo-joe/logs/db_log”); die(”“<br><br><center><img src=images/logo.gif><br><br><b>There seems to be a problem with the $dbtype server, sorry for the inconvenience.<br><br>We should be back shortly.</center></b>”);
}

Refer to error_log PHP manual page for more information and PHPnuke documentation on error logging and database calls, Please note this is for debugging purpose only.

Monday, December 17, 2007

MySQL Server Gotcha

Sorry folks been busy for a while but I am back now!!

The mysql server had been absent on my desktop Debian box for long time now as I haven't been doing any web app development. A little time I took to set things the way I liked ( my standard development setup is disable mysql from listening on public TCP port and serve local database requests via sockets and use lighter start-when-you-need webserver instead of apache2 with all its crowning glory) I see that the skip-networking is not default for mysql-server package on debian (unstable/sid) anymore .

A look at the /etc/mysql/my.cnf from the package revealed the new defaults have indeed changed.

 # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address            = 127.0.0.1 

Popular Posts