Linux Nagios pnp4nagios graphics monitor MySQL

Source: Internet
Author: User
Tags file permissions install perl

Nagios graphical interface is still a bit cumbersome, let's take MySQL for example. Monitoring MySQL plug-ins more, here to understand the method, rather than dead to move hard sets.

One, install Pnp4nagios

[Root@localhost objects]# yum install Pnp4nagios RRDtool
If you can not find the replacement Epel source, blog inside a search. For Nagios installation, please refer to: Nagios installation configuration Detailed

Second, configure Nagios

1, modify Nagios.cfg

[Root@localhost objects]# vim/etc/nagios/nagios.cfg//Modify the following content
Process_performance_data=1//changed from 0 to 1
Host_perfdata_command=process-host-perfdata//Front note take off
Service_perfdata_command=process-service-perfdata//Note take off
Enable_environment_macros=1//If a note is taken away

2, modify Commands.cfg

Comment out the original pair of Process-host-perfdata and Process-service-perfdata, redefine
[Root@localhost objects]# Vim/etc/nagios/objects/commands.cfg

Define Command {
Command_name Process-service-perfdata
command_line/usr/bin/perl/usr/libexec/pnp4nagios/process_perfdata.pl
}

Define Command {
Command_name Process-host-perfdata
Command_line/usr/bin/perl/usr/libexec/pnp4nagios/process_perfdata.pl-d Hostperfdata
}

4, modify the configuration file Templates.cfg

Add the following content

[Root@localhost objects]# Vim/etc/nagios/objects/templates.cfg

Define host {
Name Hosts-pnp
Register 0
action_url/pnp4nagios/index.php/graph?host= $HOSTNAME $&srv=_host_
Process_perf_data 1
}
Define Service {
Name Srv-pnp
Register 0
action_url/pnp4nagios/index.php/graph?host= $HOSTNAME $&srv= $SERVICEDESC $
Process_perf_data 1
}

5, modify the server configuration file localhost.cfg

[Root@localhost objects]# Vim/etc/nagios/objects/localhost.cfg

Define Host{
Use Linux-server,hosts-pnp
HOST_NAME localhost
Alias localhost
Address 127.0.0.1
}

Define Service{
Use Local-service,srv-pnp
HOST_NAME localhost
Service_description PING
Check_command check_ping!100.0,20%!500.0,60%
}
It's just an example of one, you can add it all.

Third, Pnp4nagios configuration

A lot of articles on the internet about Pnp4nagios, are to put the MV Misccommands.cfg-sample misccommands.cfg generate configuration files, I was installed yum, installation directory There is no such thing as a sample
[Root@localhost objects]# tree/etc/pnp4nagios/
/etc/pnp4nagios/
├──background.pdf
├──check_commands
│├──check_all_local_disks.cfg
│├──check_nrpe.cfg
│└──check_nwstat.cfg
├──config.php
├──misccommands.cfg
├──nagios.cfg
├──npcd.cfg
├──pages
│└──web_traffic.cfg
├──pnp4nagios_release
├──process_perfdata.cfg
└──rra.cfg
Where I don't have anything to configure.

Four, restart Nagios, start NPCD

[Root@localhost pnp4nagios]#/etc/init.d/npcd start
[Root@localhost pnp4nagios]#/etc/init.d/nagios Restart

Five, Nginx configuration

Configure Nginx, configuration is very headache, Nagios root directory is PHP, Pnp4nagios is placed under the Nagios root directory, Pnp4nagios is also PHP, configuration is not easy to disorder.

Server
{
Listen 80;
server_name nagios.xxxx.com;
Index index.php;
root/usr/share/nagios/html;

Location ~ *\. (PHP|PHP5)? $ {//nagios root directory of PHP
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Include fastcgi.conf;
}

Location ~ *\. (gif|jpg|jpeg|png|bmp|swf) $ {//nagios picture rewrite
Rewrite ^/nagios/images/(. *)/images/$1 break;
Rewrite ^/pnp4nagios/index.php/(. *)/pnp4nagios/$1 break;
Expires 30d;
}

Location ~ *\. (js|css)? $ {//nagios js,css rewrite
Rewrite ^/nagios/stylesheets/(. *)/stylesheets/$1 break;
Rewrite ^/nagios/js/(. *)/js/$1 break;
Rewrite ^/pnp4nagios/index.php/(. *)/pnp4nagios/$1 break;
Expires 1h;
}

Location ~. *\.cgi$ {//nagios's main program is Perl, Perl's CGI rewrite
Root/usr/lib64/nagios/cgi-bin;
Rewrite ^/nagios/cgi-bin/(. *) \.cgi/$1.cgi break;
Fastcgi_pass 127.0.0.1:9001;
Fastcgi_index index.cgi;
Include fastcgi.conf;
}
Location ~ ^ (/pnp4nagios.*\.php) (. *) $ {//pnp4nagios php rewrite
Rewrite ^/pnp4nagios/index.php/index.php/(. *) $/pnp4nagios/index.php/$1; Break
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Include fastcgi.conf;
}

}
One of the problems here is http://nagios.xxxx.com/pnp4nagios/index.php/index.php/graph?host=localhost&srv=. Ping here has two index.php, this is the PHP program plus go, I did not change. There are two kinds of links to the same page.
By Nagios's monitoring page, the link to the Pnp4nagios monitor page is
Http://nagios.xxxx.com/pnp4nagios/index.php/graph?host=localhost&srv=PING
Point Php4nagios the connection on the monitor page and then add a index.php,
Http://nagios.xxxx.com/pnp4nagios/index.php/index.php/graph?host=localhost&srv=PING
And that's why I want to add this sentence rewrite ^/pnp4nagios/index.php/index.php/(. *) $/pnp4nagios/index.php/$1; The cause of a break;

Second, install Perl MySQL extensions

# yum Install Perl-class-dbi-mysql

Three, check_mysqld.php and check_mysqld.pl

1, download

Http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=174&cf_id=30
http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=174&cf_id=36
2, modify check_mysqld.php and check_mysqld.pl, this machine is 64 bits, there is no/usr/lib/nagios, so to the file in the Lib to lib64

3,copy and modify file permissions


# CP Check_mysqld.pl/usr/lib64/nagios/plugins

# chmod 755/usr/lib64/nagios/plugins/check_mysqld.pl
# CHGRP nagios/usr/lib64/nagios/plugins/check_mysqld.pl

# CP Check_mysqld.php/usr/share/nagios/html/pnp4nagios/templates.dist

Four, Nagios configuration

1, modify Command.cfg


# vim/etc/nagios/objects/commands.cfg

Define Command{
Command_name Check_mysqld
Command_line $USER 1$/check_mysqld.pl-h $HOSTADDRESS $-U nagios-p $USER 7$-a Uptime,threads_connected,questions,slow_ Queries,open_tables-w ',,,, '-c ',,,, '-A $USER 21$
}

2, modify Resource.cfg


# vim/etc/nagios/objects/resource.cfg

$USER 7$=nagios
$USER 21$= ' Com_select,com_update,com_insert,com_insert_select,
Com_commit,com_delete,com_rollback,aborted_clients,
Aborted_connects,binlog_cache_disk_use,binlog_cache_use,
Bytes_received,bytes_sent,connections,created_tmp_disk_tables,
Created_tmp_files,created_tmp_tables,delayed_errors,
Delayed_insert_threads,delayed_writes,handler_update,handler_write,
Handler_delete,handler_read_first,handler_read_key,
Handler_read_next,handler_read_prev,handler_read_rnd,
Handler_read_rnd_next,key_blocks_not_flushed,
Key_blocks_unused,key_blocks_used,key_read_requests,key_reads,
Key_write_requests,key_writes,max_used_connections,
Not_flushed_delayed_rows,open_files,open_streams,open_tables,
Opened_tables,prepared_stmt_count,qcache_free_blocks,
Qcache_free_memory,qcache_hits,qcache_inserts,
Qcache_lowmem_prunes,qcache_not_cached,
Qcache_queries_in_cache,qcache_total_blocks,questions,
Select_full_join,select_rangle_check,slow_launch_threads,
Slow_queries,table_locks_immediate,table_locks_waited,
Threads_cached,threads_connected,threads_created,
Threads_running '

Notice here that the content behind the $USER 21$ is on one line.

3, modify Localhost.cfg


# vim/etc/nagios/objects/localhost.cfg

Define Service {
Use Local-service,srv-pnp//SRV-PNP for your custom
HOST_NAME localhost
Service_description MYSQLD
Check_command Check_mysqld!localhost!nagios!nagios
}
Increased check_mysqld.cfg in 4,pnp4nagios
# vim/etc/pnp4nagios/check_commands/check_mysqld.cfg

DATATYPE = COUNTER

Five, restart Nagios

#/ETC/INIT.D/NPCD Restart
#/etc/init.d/nrpe Restart
#/etc/init.d/nagios Restart

Six, view the results

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.