TOUVE 发表于 2019-1-11 08:11:52

利用cacti监控各种服务

利用cacti监控各种服务 (2011-11-17 09:06)  用cacti监控memcache
  我们在部署好memcache以后,并不意味着不管不顾,更多的我们应该监控memcahce的状态,内存使用情况,hit/miss值是多少,利 用 cacti能够很形象的监控memcache的各个参数,接下来我们就来了解下如何利用cacti来监控我们的memcache!
  首先我们可以从官网上学习如何添加cacti和memcache监控!地址如下:http://dealnews.com/developers/cacti/memcached.html
  我们来详细说下操作步骤!
  1、Python Client API
  下载Python Client API(在cacti服务器上下载)
  wget ftp://ftp.tummy.com/pub/python-memcached/python-memcached-1.47.tar.gz
  tar xzvf python-memcached-1.47.tar.gz
  python setup.py install
  我运行上面的命令的时候出现如下错误
  Traceback (most recent call last):
  File "setup.py", line 3, in ?
  from setuptools import setup
  ImportError: No module named setuptools
  解决办法:
  yum -y install python-setuptools
  安装成功后再次 python setup.py install 安装就可以成功了。
  2、Template
  wget http://content.dealnews.com/dealnews/developers/cacti-memcached-1.0.tar.gz
  tar zxvf cacti-memcached-1.0.tar.gz
  cd cacti-memcached
  把memcached.py 拷贝到Cacti 的scripts目录下!
  3、设置cacti
  进入Cacti控制界面点击
  Import Templates --> Import Template from Local File
  在浏览里面选择 cacti_memcached_host_template.xml 这个文件,然后点击save就OK!
  剩下的就是添加新图片的事情了
  4、更改
  以上设置只是针对默认端口11211,但是当你的端口不是11211,而是其他的端口,比如我的是12000,这样的话你就要对你的cacti的data source做下小更改了,操作如下:
  Console---Data Input Methods--Memcached – Statistics
  找到Input String的值python /scripts/memcached.py
  更改成:
  python /scripts/memcached.py –p 12000
  如果你是其他端口的,只要将端口号更改成其他的值就可以了!利用Cacti监控memcache就成功了。
http://blog.chinaunix.net/attachment/201111/17/23914782_1321492325q1XI.jpg
  监控Apache
  检查有没有安装状态显示模块,rpm版本的默认安装了。
  # ll /usr/local/apache/modules/mod_status.so
  -rwxr-xr-x 1 root root 51760 08-24 14:11 /usr/local/apache/modules/mod_status.so
  2. 修改apache配置文件
  vi /usr/local/apache2/conf/httpd.conf
  Shift + g 去到末行 加入
  
  SetHandler server-status
  Order deny,allow
  Deny from all
  Allow from 192.168.88.0/24
  
  ExtendedStatus On
  3. 在cacti监控机添加监控apache模块
  将 ss_apache_stats.php 拷贝到/www/cacti/scripts/ 下
  # unzip ApacheStats_0.8.2.zip
  # cd ApacheStats_0.8.2
  # cp ss_apache_stats.php /var/www/html/cacti/scripts/
  # chown apache:apache /var/www/html/cacti/scripts/ -R
  # chmod 755 /var/www/html/cacti/scripts/ -R
  导入模块 左边菜单栏 选择Import Templates 浏览--选择你解压的那文件夹里面的cacti_host_template_webserver_-_apache.xml 点击import 导入模块
http://blog.chinaunix.net/attachment/201111/17/23914782_1321492500yhnP.jpg
  4.导入模块后我们需要添加一个新组 web
  Device——>Add——>Host Template(Webserver apache)如图所示:
http://blog.chinaunix.net/attachment/201111/17/23914782_1321492586O40c.jpg
  Advance Ping 脚本及模板
  下载地址:http://forums.cacti.net/about10049.html
  注:要使用此模板,编译PHP时必须加上--enable-sockets选项来支持套接字。
  1).功能:此模板用来监控一个TCP/UDP端口、ICMP的延时情况和丢包情况。
  2).下载ss_fping.php脚本并放到/var/www/html/cacti/scripts/目录下,下载cacti_graph_template_ping_advanced_ping_v1_3.xml模板,用cacti的模板导入页将此模板导入
http://blog.chinaunix.net/attachment/201111/17/23914782_1321492689KGoU.jpg
  创建设备
  3).在Console选项卡下的左侧菜单栏中选择Devices,为要监控的主机新建一个Devices或选择已有Devices。在AssociatedGraph Templates中添加AdvancedPingv1.3模板。并点击最上面的Create Graphs for thisHost链接。
  在GraphTemplates的选择框中选择PING - Advanced Pingv1.3,然后点击Create按钮,出现以下WEB页。
  第一项意思是一次向要监控的端口发送多少个探测包(默认20个),第二项是使用的协议,可以是ICMP、TCP、UDP,第三项是要监控的端口号(只有第二项为TCP或是UDP时使用),填写完成后点击create按钮。
  在Console控制台选项卡下的左侧菜单中选择DateSources,选择以上新建的数据源可以修改以上填写的信息。
http://blog.chinaunix.net/attachment/201111/17/23914782_1321492800re4n.jpg
  如图80端口:其他端口,同理添加设备即可
  在graphs选项卡下浏览创建的Advanced Ping监控图。
http://blog.chinaunix.net/attachment/201111/17/23914782_1321492874IYEg.jpg
  监控Mysql
  1.基本上和apche那样 下载解压模板 添加模板 复制*.php *.pl 到 /var/www/html/cacti/scripts/下
  # tar xvf mysql-cacti-templates-1.1.3.tar.gz
  # cd mysql-cacti-templates-1.1.3
  # cp ss_get_mysql_stats.php /var/www/html/cacti/scripts/
  chmod 755 /var/www/html/cacti/scripts –R
  2. 添加mysql组 新建mysql主机并加入mysql组
  新建mysql主机,模块选择 x-db...
http://blog.chinaunix.net/attachment/201111/17/23914782_13214929597B5b.jpg
  3.修改脚本
  vi /var/www/html/cacti/scripts/ss_get_mysql_stats.php
  $mysql_user = 'cacti';
  $mysql_pass = 'cacti';
  $cache_dir = '/var/www/html/cacti/cache';
  # cd /var/www/html/cacti/
  # mkdir cache
  # chmod 777 cache
  4. 在mysql数据授权 cacti 用户获取数据信息

  mysql > grant super, process, replication client on *.* to 'cacti'@'%'>  mysql> FLUSH PRIVILEGES;
  5.创建设备监控Mysql,如图
http://blog.chinaunix.net/attachment/201111/17/23914782_1321493043gF6C.jpg
  监控nginx
  1. 修改nginx服务器配置 使其支持状态信息显示
  vi /usr/local/nginx/conf/nginx.conf
  server {.......
  在server{}中加入下面:
  location /nginx_status {
  stub_status on;
  access_log off;
  }
  .....}
  重启新载入后可以直接输入网址:http://nginxwebsite/nginx_status 查看数据,所以最好设置权限,cacti就是获取这些数据生成图表的。
  2. 导入模块
  nginx 模板下载地址:http://down.运维网.com/data/169487
  nginx和上面有所不同 ,
  首先导入模板,两个文件
  cacti_graph_template_nginx_clients_stat.xml
  cacti_graph_template_nginx_sockets_stat.xml
  将两个pl脚本放到/www/cacti/scripts 下 》授权 755
  如果没装perl需先按装,不然运行不了脚本
  # yum -y install perl-libwww-perl
  然后添加NGINX主机,这时候模块栏并没有出现nginx的模块选择,那么我们先选择基本的主机监控模块。按下 create ,
http://blog.chinaunix.net/attachment/201111/17/23914782_1321493167U8Fl.jpg
  在最下面处选择nginx-clients-stat 按ADD
http://blog.chinaunix.net/attachment/201111/17/23914782_1321493242TNtc.jpg
  再选nginx-sockets-stat add
http://blog.chinaunix.net/attachment/201111/17/23914782_1321493316Kddx.jpg
  这时候按上面的 *Create Graphs for this Host 建立图表:
http://blog.chinaunix.net/attachment/201111/17/23914782_1321493418wX71.jpg
  输入地址:http://10.1.1.2/nginx_status注意不要输错哦
http://blog.chinaunix.net/attachment/201111/17/23914782_1321493490p5op.jpg
  create 完成后点SAVE 大功告成!(出图需要等10分钟)
http://blog.chinaunix.net/attachment/201111/17/23914782_1321493563SKqf.jpg

页: [1]
查看完整版本: 利用cacti监控各种服务