munin 监控 mongodb
1,下载munin的mongodb插件
https://github.com/erh/mongo-munin
2,安装munin mongodb的依赖
# yum install pymongo
这个插件是python写的,如果不装的话,会报以下错误:
# munin-run mongo_mem
Traceback (most recent call last):
File "/etc/munin/plugins/mongo_mem", line 8, in <module>
import pymongo
ImportError: No module named pymongo
3,安装配置munin mongodb插件
# tar zxvf comerford-mongo-munin-8980f32.tar.gz
# cd comerford-mongo-munin-8980f32
# ln -sf /路径/mongo_* /etc/munin/plugins/
# chmod +x /路径/mongo_*
# ./build.sh
# vim /etc/munin/plugin-conf.d/mongodb //创建文件
[mongo_*]
user root //要用root,不然会报错
Can't exec "/etc/munin/plugins/pmongo_mem": Permission denied
4,测试并重启
# munin-run mongo_btree
missRatio.value 0
resets.value 0
hits.value 2
misses.value 0
accesses.value 2
# munin-run mongo_conn
connections.value 2
# munin-run mongo_docs
deleted.value 0
updated.value 0
inserted.value 3
returned.value 0
# munin-run mongo_lock
locked.value 0
# munin-run mongo_mem
resident.value 39845888
virtual.value 623902720
mapped.value 167772160
# munin-run mongo_ops
getmore.value 0
insert.value 3
update.value 0
command.value 43194
query.value 3978
delete.value 0
如果上面都有数据的话,就说明插件安装成功
# /etc/init.d/munin-node restart
munin 监控 redis
1,下载munin redis插件
https://github.com/bpineau/redis-munin
2,加载redis插件
# ln -sf /路径/redis_ /etc/munin/plugins/
3,创建munin的redis配置文件
# vim /etc/munin/plugin-conf.d/redis //新增文件
[redis_*]
user root //在这里要root用户
env.host 127.0.0.1
env.port 6379
Can't exec "/etc/munin/plugins/redis_": 权限不够 at /usr/share/perl5/vendor_perl/Munin/Node/Service.pm line 263.
出现这样的错误,基本上权限问题,如文件及文件夹权限,用户没用对等
4,测试munin redis插件是不是ok了
[root@node1 plugins]# munin-run redis_
multigraph redis_clients
clients.value 2
multigraph redis_blocked_clients
blocked.value 0
multigraph redis_memory
memory.value 735040
multigraph redis_fragmentation
frag.value 9.79
multigraph redis_changes_since_last_save
changes.value 0
multigraph redis_total_connections
connections.value 154
multigraph redis_expired_keys
expired.value 2
multigraph redis_evicted_keys
evicted.value 0
multigraph redis_pubsub_channels
channels.value 0
multigraph redis_commands
commands.value 157
hits.value 0
misses.value 2
multigraph redis_dbs
db0keys.value 4
db0expires.value 0
5,重启munin-node,就可以看到图片了
# /etc/init.d/munin-node restart
munin 监控 php-fpm
php5.3以前php-fpm和php-cgi是分开的,php-fpm做为php-cgi,第三方的管理工具包存在的,php5.3以后,php吸收了php-fpm,当你查看进程时,在也看不到php-cgi了,取尔代之的是php-fpm进程。了解php-fpm进程的相关情况就很有必要了。
1,修改php-fpm配置
# vim /etc/php-fpm.d/www.conf
pm.status_path = /status //把前面注释去掉
# /etc/init.d/php-fpm restart //重启
2,修改nginx配置
# vim /etc/nginx/conf.d/munin.conf //添加以下内容
location ~ ^/(status|ping)$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
allow 127.0.0.1;
#allow 192.168.1.101;
#allow munin.51yip.com;
deny all;
}
# /etc/init.d/nginx restart //重启
访问http://xxxxx.com/status,如果出现以下内容,说明nginx和php-fpm配置对了
pool: www
process manager: dynamic
start time: 14/Jan/2015:09:26:23 +0800
start since: 28796
accepted conn: 261
listen queue: 0
max listen queue: 0
listen queue len: 128
idle processes: 6
active processes: 1
total processes: 7
max active processes: 4
max children reached: 0
3,下载munin的php-fpm插件
https://github.com/tjstein/php5-fpm-munin-plugins
4,配置munin php-fpm插件
# unzip php5-fpm-munin-plugins-master.zip
# cd php5-fpm-munin-plugins-master
# chmod +x phpfpm_*
# ln -s /路径/phpfpm_* /etc/munin/plugins/
# vim /etc/munin/plugin-conf.d/php-fpm //创建新文件
[phpfpm*]
user tank
env.url http://munin.com/status
env.ports 80
env.phpbin php-fpm
env.phppool www
# /etc/init.d/munin-node restart //重启
这里要注意[phpfpm*]可不是随便写的,根这个正则去找插件的,如果不匹配的话,在运行munin-run phpfpm_status 的时候,会报以下错误
Can't exec "/etc/munin/plugins/phpfpm_status": Permission denied
5,查看php-fpm插件是不是安装好了
[root@node1 plugins]# munin-run phpfpm_memory
ram.value 277811200
[root@node1 plugins]# munin-run phpfpm_status
idle.value 6
active.value 1
total.value 7
[root@node1 plugins]# munin-run phpfpm_processes
php_processes.value 7
[root@node1 plugins]# munin-run phpfpm_connections
accepted.value 406
munin 监控 nginx
1,加载插件
# ln -s /usr/share/munin/plugins/nginx* /etc/munin/plugins
munin自带的nginx功能就二个,如果下了第三方的插件,可以一并放到/etc/munin/plugins,这样监控的会多些
2,配置nginx的munin
# vim /etc/nginx/conf.d/munin.conf //添加以下内容
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
# /etc/init.d/nginx restart //重启nginx
然后看一下http://xxxx.com/nginx_status是否能访问,如果配置正确,会出现以下内容
Active connections: 2
server accepts handled requests
374 374 1726
Reading: 0 Writing: 1 Waiting: 1
3,配置munin的nginx
# vim /etc/munin/plugin-conf.d/nginx //创建文件
[nginx*]
env.url http://xxxx.com/nginx_status
env.port 80
[nginx_error] //查看nginx错误信息的,默认没有这个插件
user tank
env.logpath /var/log/nginx
# /etc/init.d/munin-node restart //重启munin
4,检查munin是否配置正确
[root@node1 plugins]# munin-node-configure |grep nginx //检查nginx是否激活
nginx_request | yes |
nginx_status | yes |
[root@node1 plugins]# munin-node-configure --suggest 2>&1 | grep nginx //检查nginx是否配置正确
nginx_request | yes | yes
nginx_status | yes | yes
如果上面二步都是yes的话,说明已安装配置成功了。
munin 监控 mysql 2种方法
munin自带的有mysql监控功能,但是没有启用。试了二种方法,都可以监控mysql。
一,安装munin mysql的perl扩展
# yum install perl-Cache-Cache perl-IPC-ShareLite perl-DBD-MySQL
二,为监控创建mysql用户
mysql> CREATE USER munin@localhost IDENTIFIED BY '123456';
mysql> GRANT SUPER,PROCESS ON *.* TO munin@localhost;
mysql> FLUSH PRIVILEGES;
二,munin自带的mysql
1,建立munin mysql插件软连接
# ln -sf /usr/share/munin/plugins/mysql_* /etc/munin/plugins
2,创建配置文件
# vim /etc/munin/plugin-conf.d/mysql.conf //添加以下内容
env.mysqlconnection DBI:mysql:mytest;host=localhost;port=3306
env.mysqladmin /usr/bin/mysqladmin
env.mysqluser munin
env.mysqlpassword 123456
3,查看munin是不是支持mysql
# munin-node-configure |grep mysql
mysql_ | yes |
mysql_bytes | yes |
mysql_innodb | yes |
mysql_isam_space_ | yes |
mysql_queries | yes |
mysql_slowqueries | yes |
mysql_threads | yes |
4,查看munin mysql配置是不是正确
[root@node1 plugin-conf.d]# munin-node-configure --suggest 2>&1 | grep mysql
mysql_ | yes | yes (+bin_relay_log +commands +connections +files_tables +
如果缺少perl模块就会是no|no
然后重启munin就配置好了。在这里要注意一点就是,munin自带的mysql,监控的东西不多,并且有部分功能不出图片。
三,用第三方的munin mysql插件(推荐)
1,下载地址:https://github.com/kjellm/munin-mysql
2,解压,配置,并安装
# unzip munin-mysql-master.zip
# cd munin-mysql-master
# vim Makefile //修改安装文件
PLUGIN_DIR:=/usr/share/munin/plugins //改为自己的munin plugins路径
# vim mysql.conf //原来的删除掉,添加以下内容
env.mysqlconnection DBI:mysql:mytest;host=localhost;port=3306
env.mysqladmin /usr/bin/mysqladmin
env.mysqluser munin
env.mysqlpassword 123456
# chmod +x Makefile //加可执行
# make install //安装命令
安装结束后,并会自动重启munin。用第三方的munin mysql插件,监控的功能多,并且都可以生成图片。如下图: