码迷,mamicode.com
首页 > 其他好文 > 详细

cacti运维手册

时间:2017-08-25 17:46:28      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:cacti 监控

cacti运维手册

 

1      前言

1.1  系统功能概述

cacti是通过 snmpget来获取数据,使用 RRDtool绘画图形,而且你完全可以不需要了解RRDtool复杂的参数。它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查看树状结构、host以及任何一张图,还可以与LDAP结合进行用户验证,同时也能自己增加模板,功能非常强大完善。界面友好。软件 Cacti 的发展是基于让 RRDTool 使用者更方便使用该软件,除了基本的 Snmp 流量跟系统资讯监控外,Cacti 也可外挂 Scripts 及加上 Templates 来作出各式各样的监控图。

2      系统架构

2.1  服务器架构图

l  这里是使用nginx+cacti架构,图如下(图1):

技术分享

图1

l  架构图解析

1 cacti是通过web访问的监控程序,所以需要依赖web服务,这里使用nginx来做web服务。

2 cacti是拿取被监控机的snmp协议端口的信息数据来画图监控。

3 cacti模板和rra 文件存入mysql数据库中。

2.2  cacti架构图

l  cacti工作流程架构图如下(图2):

技术分享

图2

l  架构图解析

通过上图我们可以发现Cacti 有三大组件:MySQL 数据库、RRDtool 工具、Net-Snmp 程序。MySQL并不负责监控数据的存储,只保存模板和rra 文件与主机对应等信息,而真正的监控数据存储和图像展现都是rrdtool 来做的。而Net-SNMP 负责数据的采集。

cacti是用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用rrdtool储存和更新数据,当用户需要查看数据的时候用rrdtool生成图表呈现给用户。因此,snmp和rrdtool是cacti的关键。Snmp关系着数据的收集,rrdtool关系着数据存储和图表的生成。

Mysql配合PHP程序存储一些变量数据并对变量数据进行调用,如:主机名、主机ip、snmp团体名、端口号、模板信息等变量。

snmp抓到数据不是存储在mysql中,而是存在rrdtool生成的rrd文件中(在cacti根目录的rra文件夹下)。rrdtool对数据的更新和存储就是对rrd文件的处理,rrd文件是大小固定的档案文件(Round Robin Archive),它能够存储的数据笔数在创建时就已经定义。

3      安装配置

3.1  安装配置nginx

3.1.1      安装依赖程序

l  yum安装部分

yum install -y pcre  pcre-devel  gd  gd-devel  GeoIP  GeoIP-devel  gcc-c++

l  编译安装部分

安装libunwind和google-perftools

#  wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-beta.tar.gz

#  tar -xzvf libunwind-0.99-beta.tar.gz

#  cd libunwind-0.99-beta

#  ./configure

#  make

#  make install

#  echo "/usr/local/lib" >> /etc/ld.so.conf

#  ldconfig

 

#  wget http://down1.chinaunix.net/distfiles/google-perftools-1.9.tar.gz

#  tar -xzvf google-perftools-1.9.tar.gz

#  cd google-perftools-1.9

#  ./configure

#  make

#  make install

#  ldconfig

3.1.2      创建用户和组

# useradd -g users -s /bin/false -M webuser

# mkdir -p /opt/nginx/temp/client_body_temp

3.1.3      编译安装nginx

# tar -xzvf nginx-1.6.0.tar.gz

# cd nginx-1.6.0

#./configure --prefix=/opt/nginx \

--user=webuser \

--group=users \

--with-poll_module \

--with-http_ssl_module \

--with-http_realip_module \

--with-http_addition_module \

--with-http_geoip_module \

--with-http_flv_module \

--with-http_gzip_static_module \

--with-http_secure_link_module \

--with-http_stub_status_module \

--http-client-body-temp-path=/opt/nginx/temp/client_body_temp \

--http-proxy-temp-path=/opt/nginx/temp/proxy_temp \

--http-fastcgi-temp-path=/opt/nginx/temp/fastcgi_temp \

--http-uwsgi-temp-path=/opt/nginx/temp/uwsgi_temp \

--http-scgi-temp-path=/opt/nginx/temp/scgi_temp \

--with-google_perftools_module

 

make

makeinstall

3.1.4      配置nginx

l  修改nginx配置文件

vi /opt/nginx/conf/nginx.conf(红色为修改部分

user  webuser users;
worker_processes  1;
 
#error_log  logs/error.log;
error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
pid        logs/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    #log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
    #                  ‘$status $body_bytes_sent "$http_referer" ‘
    #                  ‘"$http_user_agent" "$http_x_forwarded_for"‘;
 
    #access_log  logs/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
 
#gzip  on;
    server {
        listen       80;
        server_name  10.0.112.100;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   html;
            index  index.html index.htm index.php;
        }
 
        #error_page  404              /404.html;
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi.conf;
            fastcgi_ignore_client_abort on;
        }
   }
}

3.1.5      启动,关闭,重新加载nginx

l  启动nginx

# /opt/nginx/sbin/nginx

l  关闭停止nginx

# /opt/nginx/sbin/nginx -s stop

l  重新加载nginx配置

# /usr/sbin/nginx -s reload

至此,已经完成了nginx的安装部署。

 

3.2  安装配置PHP

3.2.1      安装依赖程序

l  yum安装部分

yum install libxml2-devel bzip2-devel libcurl-devel freetype-devel libpng-devel mysql-devel

l  编译安装部分

tar zxvf libmcrypt-2.5.7.tar.gz

cd libmcrypt-2.5.7

./configure --prefix=/usr/local/libmcrytp

make

make install

 

tar zxvf freetds-0.95rc3.tar.gz

cd freetds-0.95rc3

./configure

make

make install

l  库文件软连接

ln -s /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so

3.2.2      编译安装php

./configure --prefix=/opt/php5 \

--sysconfdir=/opt/php5/etc \

--enable-soap \

--enable-fpm \

--enable-ftp \

--enable-gd-native-ttf \

--enable-mbstring \

--enable-shmop=shared \

--enable-sockets \

--enable-sysvsem=shared \

--enable-zip \

--disable-ctype \

--disable-ipv6 \

--disable-mbregex \

--disable-mbregex-backtrack \

--disable-posix \

--disable-tokenizer \

--with-bz2=shared \

--with-config-file-path=/opt/php5/etc \

--with-curl \

--with-curlwrappers \

--with-freetype-dir=/usr \

--with-fpm-group=users \

--with-fpm-user=webuser \

--with-gd \

--with-iconv-dir=shared \

--with-ldap-sasl=shared,/usr \

--with-mcrypt=/usr/local/libmcrytp \

--with-mhash=shared \

--with-mssql=shared \

--with-mysql=/usr \

--with-mysqli=/usr/bin/mysql_config \

--with-openssl \

--with-pdo-mysql=shared \

--with-zlib \

--without-cdb \

--without-pdo-sqlite \

--with-png-dir=/usr --without-sqlite3

 

make

make install

3.2.3      配置php

l  拷贝配置文件

cp /opt/php5/etc/php-fpm.conf.default  /opt/php5/etc/php-fpm.conf

cp /usr/local/src/php-5.4.28/php.ini-production /opt/php5/etc/php.ini

l  修改php.ini

# vi /opt/php5/etc/php.ini

在Dynamic Extensions 段下添加以下内容:

extension=eaccelerator.so

extension=memcache.so

extension=mongo.so

extension=redis.so

extension=pdo_dblib.so

extension=pdo_mysql.so

在末尾增加以下关于eaccelerator的配置:

short_open_tag="On"

eaccelerator.cache_dir="/opt/php5/var/tmp/eaccelerator_cache"

eaccelerator.debug="0"

eaccelerator.shm_only="1"

eaccelerator.shm_size="256"

修改以下配置:

default_charset = "UTF-8"

error_log = /opt/php5/var/log/php_errors.log

html_errors = off

upload_max_filesize = 32M

upload_tmp_dir = /opt/php5/var/tmp

date.timezone="Asia/Shanghai"

include_path = ".:/opt/php5/include/php:/opt/php5/lib/php"

short_open_tag = On

l  配置php-fpm服务

# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

其中. /sapi/fpm/init.d.php-fpm为存放在源码包中的文件

# chmod 755 /etc/init.d/php-fpm

# chkconfig --add php-fpm

# cp /opt/php5/etc/php-fpm.conf.default /opt/php5/etc/php-fpm.conf

 

3.2.4      启动,关闭,重新加载php

l  运行php

# service php-fpm start

l  停止php

# service php-fpm stop

l  重新加载php

# service php-fpm restart

3.3  安装配置mysql

3.3.1      yum安装mysql

yum install mysql-server mysql

3.3.2      启动mysql

/etc/ini.d/mysqld start

3.3.3      设置用户密码

mysqladmin -u root -p password "123456"

 

3.4  安装配置cacti

3.4.1      下载cacti

这里下载的版本是0.8.8c

http://www.cacti.net/downloads/cacti-0.8.8c.tar.gz

http://www.cacti.net/downloads/ (里面可以自己选择相应版本)

 

3.4.2      安装cacti

l  解压cacti

tar zxvf  cacti-0.8.8c.tar.gz

l  拷贝cacti

cp –rf cacti-0.8.8c /opt/nginx/html

3.4.3      数据库设置

l  导入cacti数据库

mysql –uroot –p

mysql> create database cacti

mysql> quit

tar zxvf

mysql –uroot –p cacti < cacti.sql

注:cacti.sql文件位置:/opt/nginx/html/cacti/cacti.sql

l  创建cacti数据库用户

useradd cacti

vi /etc/passwd

cacti:x:501:501::/home/cacti:/sbin/nologin             #设置cacti用户不可登陆,增加安全性

mysql –uroot –p

mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY ‘cacti123‘;

3.4.4      配置修改

vi /opt/nginx/html/cacti/include/config.php

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "127.0.0.1";

$database_username = "cacti";

$database_password = "cacti123";

$database_port = "3306";

$database_ssl = false;

3.4.5      增加crontab

crontab –e

*/5 * * * * /opt/php5/bin/php /opt/nginx/html/cacti/poller.php

3.5  网页安装cacti

注意:如果出现网页图片为x,nginx错误日志报错为这样类似:FastCGI sent in stderr: "Access to the script ‘/var/www/html//phpmyadmin/setup/styles.css‘ has been denied (see security.limit_extensions)"

从5.3.9开始,php官方加入了一个配置"security.limit_extensions",默认状态下只允许执行扩展名为".php"的文件,造成了其他类型的文件不支持的问题。

修改php-fpm.conf,找到security.limit_extensions把他修改为:

security.limit_extensions=.php .html .js .css .jpg .jpeg .gif .png .htm (常用的文件扩展名)

就解决了

l  安装地址:http://IP/cacti/install 并按Next继续,如图(图3):

技术分享

图3

l  选择New install 并按Next继续,如图(图4):

技术分享

图4

l  填写正确rrdtool和php程序路径,并按Finish完成安装。如图(图5)

技术分享

图5

3.6  登陆cacti

l  登陆地址:http://IP/cacti/ 初始用户名:admin 初始密码:admin 如图(图6)

技术分享

图6

l  admin用户初次登陆,会被要求强制修改密码,这里我修改密码为:123456,点击“Save(保存)”。如图(图7):

技术分享

图7

l  这是登陆cacti界面,如图(图8):

技术分享

图8

3.7  安装配置cacti-spine

3.7.1      前言

出于效率原因,在大量采集数据时使用自带的cmd.php轮询器会比较慢,1分钟1次的采集频率可能无法完成轮询所有机器。这里为了优化,采用官方推荐的spine来高效轮询。

3.7.2      下载cacti-spine

注:必须和cacti版本一致

http://www.cacti.net/downloads/spine/cacti-spine-0.8.8c.tar.gz

http://www.cacti.net/downloads/spine/(里面可以自己选择相应版本)

3.7.3      编译安装

tar zxvf cacti-spine-0.8.8c.tar.gz

cd cacti-spine-0.8.8c

./configure

make

make install

3.7.4      修改配置

cd /usr/local/spine/etc

cp spine.conf.dist spine.conf

vi spine.conf

DB_Host         127.0.0.1

DB_Database     cacti

DB_User         cacti

DB_Pass         cacti123

DB_Port         3306

DB_PreG         0

3.7.5      配置修改

 

l  登陆cacti,选择Settings 如图(图9)

技术分享

图9

l  然后选择poller,并在poller type 里面选择spine 并点击save保存。如图(图10):

技术分享

技术分享

图10

3.8  安装配置snmp(被监控机操作)

3.8.1      安装snmp

yum install net-snmp net-snmp-libs net-snmp-utils

3.8.2      配置snmp

vi /etc/snmp/snmpd.conf          修改下内容

com2sec notConfigUser  192.168.0.1      123456

                                            cacti的IP       snmp密码

view all    included  .1     #去掉注释

access  notConfigGroup ""      any       noauth    exact  all none none   #改成all

3.8.3      启动snmp

/etc/init.d/snmpd start

3.9  窗口界面基本操作

3.9.1      增加主机

l  点击devices,再点击add进入添加主机页面,如图(图11)

技术分享

图11

l  填写主机相应信息,并保存。如图(图12,图13)

技术分享

图12

技术分享

图13

l  再次进入主机页面,选择相应图形模板添加并保存。如图(图14)

技术分享

图14

3.9.2      增加图形

l  点击New Graphs进入增加图形界面,如图(图15)

技术分享

图15

l  选择需要增加的图形,然后创建,如图(图16)

技术分享

图16

3.9.3      创建目录树

l  点击Graph Trees进入创建目录树。并点击Add创建。如图(图17)

技术分享

图17

l  输入名字后,点击创建。如图(图18)

技术分享

图18

l  然后点击Add添加主机到目录树下,如图(图19)

技术分享

图19

l  选择host,再选择主机名,并创建,如图(图20)

技术分享

图20

3.10   查看监控图

直接点击graphs就可以查看监控图,如图(图21)

技术分享

图21

4      监控IO

4.1  前言

监控硬盘IO这里介绍两种方法,一个是通过snmpdiskio监控IO,还一个是Cacti_Net-SNMP监控IO。推荐使用snmpdiskio,但如果这种监控方法失败或者内核已经超过2.6版本。就使用第二种方法Cacti_Net-SNMP。两种方法效果基本是一样的,看个人喜好选择吧。

4.2  通过snmpdiskio监控IO

4.2.1      解压snmpdiskio

tar zxvf snmpdiskio-0.9.4.tar.gz

4.2.2      拷贝partition.xml(监控机操作)

cp snmpdiskio-0.9.4/partition.xml /opt/nginx/html/cacti/resource/snmp_queries/

4.2.3      修改partition.xml

注意:下面oid要根据实际情况更改,比如如下:

snmpwalk -v 2c -c public 192.168.8.131 .1.3.6.1.4.1.2021.54

UCD-SNMP-MIB::ucdavis.54.1.0 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.54.2.1.2.5.104.100.78.117.109 = STRING: "/bin/bash"

UCD-SNMP-MIB::ucdavis.54.2.1.3.5.104.100.78.117.109 = STRING: "/usr/local/bin/snmpdiskio hdNum"

UCD-SNMP-MIB::ucdavis.54.2.1.4.5.104.100.78.117.109 = ""

UCD-SNMP-MIB::ucdavis.54.2.1.5.5.104.100.78.117.109 = INTEGER: 5

UCD-SNMP-MIB::ucdavis.54.2.1.6.5.104.100.78.117.109 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.54.2.1.7.5.104.100.78.117.109 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.54.2.1.20.5.104.100.78.117.109 = INTEGER: 4

UCD-SNMP-MIB::ucdavis.54.2.1.21.5.104.100.78.117.109 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.54.3.1.1.5.104.100.78.117.109 = STRING: "33"

UCD-SNMP-MIB::ucdavis.54.3.1.2.5.104.100.78.117.109 = STRING: "33"

UCD-SNMP-MIB::ucdavis.54.3.1.3.5.104.100.78.117.109 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.54.3.1.4.5.104.100.78.117.109 = INTEGER: 0

UCD-SNMP-MIB::ucdavis.54.4.1.2.5.104.100.78.117.109.1 = STRING: "33"

OID是.1.3.6.1.4.1.2021.54.4.1.2.5.104.100.78.117.109.1

 

snmpwalk -v 2c -c public 192.168.8.131 .1.3.6.1.4.1.2021.55

UCD-SNMP-MIB::ucdavis.55.1.0 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.55.2.1.2.7.104.100.73.110.100.101.120 = STRING: "/bin/bash"

UCD-SNMP-MIB::ucdavis.55.2.1.3.7.104.100.73.110.100.101.120 = STRING: "/usr/local/bin/snmpdiskio hdIndex"

UCD-SNMP-MIB::ucdavis.55.2.1.4.7.104.100.73.110.100.101.120 = ""

UCD-SNMP-MIB::ucdavis.55.2.1.5.7.104.100.73.110.100.101.120 = INTEGER: 5

UCD-SNMP-MIB::ucdavis.55.2.1.6.7.104.100.73.110.100.101.120 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.55.2.1.7.7.104.100.73.110.100.101.120 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.55.2.1.20.7.104.100.73.110.100.101.120 = INTEGER: 4

UCD-SNMP-MIB::ucdavis.55.2.1.21.7.104.100.73.110.100.101.120 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.55.3.1.1.7.104.100.73.110.100.101.120 = STRING: "1"

UCD-SNMP-MIB::ucdavis.55.3.1.2.7.104.100.73.110.100.101.120 = STRING: "1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33"

UCD-SNMP-MIB::ucdavis.55.3.1.3.7.104.100.73.110.100.101.120 = INTEGER: 33

UCD-SNMP-MIB::ucdavis.55.3.1.4.7.104.100.73.110.100.101.120 = INTEGER: 0

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.1 = STRING: "1"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.2 = STRING: "2"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.3 = STRING: "3"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.4 = STRING: "4"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.5 = STRING: "5"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.6 = STRING: "6"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.7 = STRING: "7"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.8 = STRING: "8"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.9 = STRING: "9"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.10 = STRING: "10"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.11 = STRING: "11"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.12 = STRING: "12"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.13 = STRING: "13"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.14 = STRING: "14"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.15 = STRING: "15"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.16 = STRING: "16"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.17 = STRING: "17"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.18 = STRING: "18"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.19 = STRING: "19"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.20 = STRING: "20"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.21 = STRING: "21"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.22 = STRING: "22"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.23 = STRING: "23"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.24 = STRING: "24"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.25 = STRING: "25"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.26 = STRING: "26"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.27 = STRING: "27"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.28 = STRING: "28"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.29 = STRING: "29"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.30 = STRING: "30"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.31 = STRING: "31"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.32 = STRING: "32"

UCD-SNMP-MIB::ucdavis.55.4.1.2.7.104.100.73.110.100.101.120.33 = STRING: "33"

OID是.1.3.6.1.4.1.2021.55.4.1.2.7.104.100.73.110.100.101.120

 

snmpwalk -v 2c -c public 192.168.8.131 .1.3.6.1.4.1.2021.56

UCD-SNMP-MIB::ucdavis.56.1.0 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.56.2.1.2.7.104.100.68.101.115.99.114 = STRING: "/bin/bash"

UCD-SNMP-MIB::ucdavis.56.2.1.3.7.104.100.68.101.115.99.114 = STRING: "/usr/local/bin/snmpdiskio hdDescr"

UCD-SNMP-MIB::ucdavis.56.2.1.4.7.104.100.68.101.115.99.114 = ""

UCD-SNMP-MIB::ucdavis.56.2.1.5.7.104.100.68.101.115.99.114 = INTEGER: 5

UCD-SNMP-MIB::ucdavis.56.2.1.6.7.104.100.68.101.115.99.114 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.56.2.1.7.7.104.100.68.101.115.99.114 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.56.2.1.20.7.104.100.68.101.115.99.114 = INTEGER: 4

UCD-SNMP-MIB::ucdavis.56.2.1.21.7.104.100.68.101.115.99.114 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.56.3.1.1.7.104.100.68.101.115.99.114 = STRING: "ram0"

UCD-SNMP-MIB::ucdavis.56.3.1.2.7.104.100.68.101.115.99.114 = STRING: "ram0

ram1

ram2

ram3

ram4

ram5

ram6

ram7

ram8

ram9

ram10

ram11

ram12

ram13

ram14

ram15

loop0

loop1

loop2

loop3

loop4

loop5

loop6

loop7

sr0

sda

sda1

sda2

sda3

sdb

sdb1

sdb2

dm-0"

UCD-SNMP-MIB::ucdavis.56.3.1.3.7.104.100.68.101.115.99.114 = INTEGER: 33

UCD-SNMP-MIB::ucdavis.56.3.1.4.7.104.100.68.101.115.99.114 = INTEGER: 0

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.1 = STRING: "ram0"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.2 = STRING: "ram1"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.3 = STRING: "ram2"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.4 = STRING: "ram3"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.5 = STRING: "ram4"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.6 = STRING: "ram5"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.7 = STRING: "ram6"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.8 = STRING: "ram7"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.9 = STRING: "ram8"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.10 = STRING: "ram9"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.11 = STRING: "ram10"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.12 = STRING: "ram11"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.13 = STRING: "ram12"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.14 = STRING: "ram13"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.15 = STRING: "ram14"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.16 = STRING: "ram15"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.17 = STRING: "loop0"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.18 = STRING: "loop1"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.19 = STRING: "loop2"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.20 = STRING: "loop3"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.21 = STRING: "loop4"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.22 = STRING: "loop5"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.23 = STRING: "loop6"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.24 = STRING: "loop7"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.25 = STRING: "sr0"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.26 = STRING: "sda"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.27 = STRING: "sda1"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.28 = STRING: "sda2"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.29 = STRING: "sda3"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.30 = STRING: "sdb"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.31 = STRING: "sdb1"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.32 = STRING: "sdb2"

UCD-SNMP-MIB::ucdavis.56.4.1.2.7.104.100.68.101.115.99.114.33 = STRING: "dm-0"

OID是.1.3.6.1.4.1.2021.56.4.1.2.7.104.100.68.101.115.99.114

 

snmpwalk -v 2c -c pubilc 192.168.8.131 .1.3.6.1.4.1.2021.57

UCD-SNMP-MIB::ucdavis.57.1.0 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.57.2.1.2.10.104.100.73.110.66.108.111.99.107.115 = STRING: "/bin/bash"

UCD-SNMP-MIB::ucdavis.57.2.1.3.10.104.100.73.110.66.108.111.99.107.115 = STRING: "/usr/local/bin/snmpdiskio hdInBlocks"

UCD-SNMP-MIB::ucdavis.57.2.1.4.10.104.100.73.110.66.108.111.99.107.115 = ""

UCD-SNMP-MIB::ucdavis.57.2.1.5.10.104.100.73.110.66.108.111.99.107.115 = INTEGER: 5

UCD-SNMP-MIB::ucdavis.57.2.1.6.10.104.100.73.110.66.108.111.99.107.115 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.57.2.1.7.10.104.100.73.110.66.108.111.99.107.115 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.57.2.1.20.10.104.100.73.110.66.108.111.99.107.115 = INTEGER: 4

UCD-SNMP-MIB::ucdavis.57.2.1.21.10.104.100.73.110.66.108.111.99.107.115 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.57.3.1.1.10.104.100.73.110.66.108.111.99.107.115 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.3.1.2.10.104.100.73.110.66.108.111.99.107.115 = STRING: "0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

2807481356288

45056

156467200

2807324844032

855380480

438969344

416407040

416194560"

UCD-SNMP-MIB::ucdavis.57.3.1.3.10.104.100.73.110.66.108.111.99.107.115 = INTEGER: 33

UCD-SNMP-MIB::ucdavis.57.3.1.4.10.104.100.73.110.66.108.111.99.107.115 = INTEGER: 0

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.1 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.2 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.3 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.4 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.5 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.6 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.7 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.8 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.9 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.10 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.11 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.12 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.13 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.14 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.15 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.16 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.17 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.18 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.19 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.20 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.21 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.22 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.23 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.24 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.25 = STRING: "0"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.26 = STRING: "2807481356288"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.27 = STRING: "45056"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.28 = STRING: "156467200"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.29 = STRING: "2807324844032"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.30 = STRING: "855380480"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.31 = STRING: "438969344"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.32 = STRING: "416407040"

UCD-SNMP-MIB::ucdavis.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115.33 = STRING: "416194560"

OID是.1.3.6.1.4.1.2021.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115

 

snmpwalk -v 2c -c public 192.168.8.131 .1.3.6.1.4.1.2021.58

UCD-SNMP-MIB::ucdavis.58.1.0 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.58.2.1.2.11.104.100.79.117.116.66.108.111.99.107.115 = STRING: "/bin/bash"

UCD-SNMP-MIB::ucdavis.58.2.1.3.11.104.100.79.117.116.66.108.111.99.107.115 = STRING: "/usr/local/bin/snmpdiskio hdOutBlocks"

UCD-SNMP-MIB::ucdavis.58.2.1.4.11.104.100.79.117.116.66.108.111.99.107.115 = ""

UCD-SNMP-MIB::ucdavis.58.2.1.5.11.104.100.79.117.116.66.108.111.99.107.115 = INTEGER: 5

UCD-SNMP-MIB::ucdavis.58.2.1.6.11.104.100.79.117.116.66.108.111.99.107.115 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.58.2.1.7.11.104.100.79.117.116.66.108.111.99.107.115 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.58.2.1.20.11.104.100.79.117.116.66.108.111.99.107.115 = INTEGER: 4

UCD-SNMP-MIB::ucdavis.58.2.1.21.11.104.100.79.117.116.66.108.111.99.107.115 = INTEGER: 1

UCD-SNMP-MIB::ucdavis.58.3.1.1.11.104.100.79.117.116.66.108.111.99.107.115 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.3.1.2.11.104.100.79.117.116.66.108.111.99.107.115 = STRING: "0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

4083470336

2640896

13680640

4066096128

150828032

138458112

12132352

8193024"

UCD-SNMP-MIB::ucdavis.58.3.1.3.11.104.100.79.117.116.66.108.111.99.107.115 = INTEGER: 33

UCD-SNMP-MIB::ucdavis.58.3.1.4.11.104.100.79.117.116.66.108.111.99.107.115 = INTEGER: 0

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.1 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.2 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.3 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.4 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.5 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.6 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.7 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.8 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.9 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.10 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.11 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.12 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.13 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.14 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.15 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.16 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.17 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.18 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.19 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.20 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.21 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.22 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.23 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.24 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.25 = STRING: "0"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.26 = STRING: "4083470336"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.27 = STRING: "2640896"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.28 = STRING: "13680640"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.29 = STRING: "4066096128"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.30 = STRING: "150828032"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.31 = STRING: "138458112"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.32 = STRING: "12132352"

UCD-SNMP-MIB::ucdavis.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115.33 = STRING: "8193024"

OID是.1.3.6.1.4.1.2021.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115

 

<interface>
       <name>Get SNMP Partitions</name>
       <description>Queries a host for a list of monitorable partitions</description>
       <oid_index>.1.3.6.1.4.1.2021.55.4.1.2.7.104.100.73.110.100.101.120</oid_index>
       <oid_num_indexes>.1.3.6.1.4.1.2021.54.4.1.2.5.104.100.78.117.109.1</oid_num_indexes>
       <index_order>hdDescr:hdIndex</index_order>
       <index_order_type>numeric</index_order_type>
       <index_title_format>|chosen_order_field|</index_title_format>
 
       <fields>
              <hdIndex>
                     <name>Index</name>
                     <method>walk</method>
                     <source>value</source>
                     <direction>input</direction>
                     <oid>.1.3.6.1.4.1.2021.55.4.1.2.7.104.100.73.110.100.101.120</oid>
              </hdIndex>
              <hdDescr>
                     <name>Description</name>
                     <method>walk</method>
                     <source>value</source>
                     <direction>input</direction>
                     <oid>.1.3.6.1.4.1.2021.56.4.1.2.7.104.100.68.101.115.99.114</oid>
              </hdDescr>
              <hdInBlocks>
                     <name>Bytes Written</name>
                     <method>walk</method>
                     <source>value</source>
                     <direction>output</direction>
                     <oid>.1.3.6.1.4.1.2021.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115</oid>
              </hdInBlocks>
              <hdOutBlocks>
                     <name>Bytes Read</name>
                     <method>walk</method>
                     <source>value</source>
                     <direction>output</direction>
                     <oid>.1.3.6.1.4.1.2021.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115</oid>
              </hdOutBlocks>
       </fields>
</interface>

4.2.4      升级snmpdiskio

由于9.4太老不支持2.6内核,需要修改升级

vi snmpdiskio-0.9.4/snmpdiskio        将下面内容覆盖到这文件

#!/bin/bash
# $Id: snmpdiskio,v 1.5 2008/01/31 21:19:50 dverlaeckt Exp $
# snmpdiskio v0.9.6 (c) 2008 Dieter Verlaeckt <dieter.verlaeckt@gmail.com>
# snmpdiskio v0.9.5 (c) 2007 Pablo Destefanis <pdestefanis@gmail.com>
# snmpdiskio v0.9.4 (c) 2006 Mikael Fridh <mikael@meanstreak.se>
 
# Fields in /proc/partitions (kernel 2.4)
# major minor #blocks name rio rmerge rsect ruse wio wmerge wsect wuse running use aveq
 
# Fields in /proc/diskstats (kernel 2.6) for disks (i.e. hda)
# major minor name rio rmerge rsect ruse wio wmerge wsect wuse running use aveq
 
# Fields in /proc/diskstats (kernel 2.6) for partitions (i.e. hda1)
# major minor name rio rsect wio wsect
 
# InBlocks = sectors written to disk
# OutBlocks = sectors read from disk
 
# Set default procfile for kernel 2.4
PROCFILE="/proc/partitions"
MODE="linux24"
 
# Probably kernel 2.6:
if [ -f /proc/diskstats ]; then
   PROCFILE=/proc/diskstats
   MODE="linux26"
fi
 
 
function hdNum()
{
       awk ‘ BEGIN { num=0 } $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ { num++ } END { print num } ‘ $PROCFILE
}
 
function hdIndex()
{
       awk ‘ BEGIN { num=0 } $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ { num++; print num } ‘ $PROCFILE
}
 
function hdDescr()
{
       if [ "$MODE" = "linux26" ]; then
               awk ‘ $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ { printf "%s\n", $3 }‘ $PROCFILE
       else
               awk ‘ $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ { printf "%s\n", $4 }‘ $PROCFILE
       fi
}
 
function hdInBlocks()
{
       if [ "$MODE" = "linux26" ]; then
               awk ‘ $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ && NF == 7 { printf "%.0f\n", $7 * 512 }
                     $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ && NF == 14 { printf "%.0f\n", $10 * 512 } ‘ $PROCFILE
       else
               awk ‘ $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ && NF == 15 { printf "%.0f\n", $11 * 512 } ‘ $PROCFILE
       fi
}
 
function hdOutBlocks()
{
       if [ "$MODE" = "linux26" ]; then
               awk ‘ $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ && NF == 7 { printf "%.0f\n", $5 * 512 }
                     $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ && NF == 14 { printf "%.0f\n", $6 * 512 } ‘ $PROCFILE
       else
               awk ‘ $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ && NF == 15 { printf "%.0f\n", $7 * 512 } ‘ $PROCFILE
       fi
}
 
function usage()
{
       cat <<-EOUSAGE
Usage: $0 <hdNum|hdIndex|hdDescr|hdInBlocks|hdOutBlocks>
EOUSAGE
}
 
if [ 1 -ne $# ]; then
       usage
       exit 1
fi
 
case $1 in
       hdNum|hdIndex|hdDescr|hdInBlocks|hdOutBlocks)
               $1
       ;;
       ‘hdNum‘)
               hdNum
       ;;
       ‘hdIndex‘)
               hdIndex
       ;;
       ‘hdDescr‘)
               hdDescr
       ;;
       ‘hdInBlocks‘)
               hdInBlocks
       ;;
       ‘hdOutBlocks‘)
               hdOutBlocks
       ;;
       *)
               usage
               exit 1
       ;;
esac
 
exit 0

4.2.5      拷贝snmpdiskio (被监控机操作)

cp snmpdiskio-0.9.4/snmpdiskio /usr/local/bin/

4.2.6      修改snmp配置(被监控机操作)

vi /etc/snmp/snmpd.conf     在最后加入以下几行

extend .1.3.6.1.4.1.2021.54 hdNum /bin/bash /usr/local/bin/snmpdiskio hdNum

extend .1.3.6.1.4.1.2021.55 hdIndex /bin/bash /usr/local/bin/snmpdiskio hdIndex

extend .1.3.6.1.4.1.2021.56 hdDescr /bin/bash /usr/local/bin/snmpdiskio hdDescr

extend .1.3.6.1.4.1.2021.57 hdInBlocks /bin/bash /usr/local/bin/snmpdiskio hdInBlocks

extend .1.3.6.1.4.1.2021.58 hdOutBlocks /bin/bash /usr/local/bin/snmpdiskio hdOutBlocks

4.2.7      导入模板

l  将压缩包里以下两个文件解压

cacti_data_query_snmp_disk_statistics.xml

cacti_graph_template_disk_io_bytessec.xml

l  进入cacti界面的导入模板如图(图22)

技术分享

图22

4.2.8      测试

在监控机上运行如下命令:

snmpwalk -v 2c -c public 192.168.0.2 .1.3.6.1.4.1.2021.58

                   snmp密码  被监控机IP    

UCD-SNMP-MIB::ucdavis.58.1.1 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.58.2.1 = STRING: "hdOutBlocks"
UCD-SNMP-MIB::ucdavis.58.3.1 = STRING: "/bin/sh /usr/local/bin/snmpdiskio hdOutBlocks"
UCD-SNMP-MIB::ucdavis.58.100.1 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.58.101.1 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.2 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.3 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.4 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.5 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.6 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.7 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.8 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.9 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.10 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.11 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.12 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.13 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.14 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.15 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.16 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.17 = STRING: "390659584"
UCD-SNMP-MIB::ucdavis.58.101.18 = STRING: "823808"
UCD-SNMP-MIB::ucdavis.58.101.19 = STRING: "386556928"
UCD-SNMP-MIB::ucdavis.58.101.20 = STRING: "827904"
UCD-SNMP-MIB::ucdavis.58.101.21 = STRING: "5120"
UCD-SNMP-MIB::ucdavis.58.101.22 = STRING: "2224640"
UCD-SNMP-MIB::ucdavis.58.101.23 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.24 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.25 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.102.1 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.58.103.1 = ""

出现如上数据表示正常

4.2.9      添加图形

l  进入cacti界面,点击主机,添加snmpdiskio,如图(图23,图24)

技术分享

图23

技术分享

图24

l  点击增加图形,并选择需要监控的盘符名称,点击创建即可。如图(图25,图26)

技术分享

图25

技术分享

图26

4.3  通过Cacti_Net-SNMP监控IO

4.3.1      下载Cacti_Net-SNMP

下载地址:https://www.centos.bz/wp-content/uploads/2012/09/Cacti_Net-SNMP_DevIO_v3.1.zip

4.3.2      检查是否支持IO监控

snmpwalk -v 1 -c public 监控机的IP  UCD | more

执行如上命令,如果返回类似如下数据,则表示支持disk io的监控,否则需要重新编译增加diskio-module模块。

UCD-DISKIO-MIB::diskIOIndex.1 = INTEGER: 1

UCD-DISKIO-MIB::diskIOIndex.2 = INTEGER: 2

UCD-DISKIO-MIB::diskIOIndex.3 = INTEGER: 3

......

4.3.3      解压并拷贝net-snmp_devio.xml

cp net-snmp_devio.xml /opt/nginx/html/cacti/resource/snmp_queries/

4.3.4      导入模板

通过cacti后台的"Import Templates"导入所有的*_TMPL.xml文件,最后导入net-snmp_devIO-Data_query.xml文件。完成后,你就可以在“Data Queries”看到“ucd/net - Get Device I/O”。如图(图27)

技术分享

图27

4.3.5      添加图形

点击主机页面,在最后增加ucd/net - Get Device I/O模板。并在增加图形中选择相应盘符创建图形即可。如图(图28,29,30,31)

技术分享

图28

技术分享

图29

技术分享

图30

技术分享

图31

5      自定义监控

5.1  前言

自定义监控是通过被监控机上的自动脚本(如shell),取出你需要的数值,并将这数值赋予OID值。cacti

通过snmp协议来获取OID值并画图。如果一个监控图需要多个数值画线,只需要创建多个OID值,将多个数值合成一个监控图。就可以实现多线图。这里通过CPU和内存的自定义脚本监控图来进行说明。

5.2  CPU自定义监控

5.2.1      脚本构架图

脚本架构图如下(图32)

技术分享

图32

架构图说明:

由于check_cpu.sh脚本运行时间较长,如果cacti直接取这脚本数值会导致超时失败。所以我们用cpu.sh脚本赋予各种类型数值并写入临时文件,然后让cacti去读取临时文件数值,这样速度会很快不会导致超时。cacti会将OID里的数值集合在一张图,画多线图。

所有脚本都放在/usr/local/bin

5.2.2      check_cpu.sh脚本

内容如下:

#!/bin/bash
#ScriptName:check_cpu.sh
#USAGE:./check_cpu.sh -w 70 -c 90 -s 2 -a
#Directions:Check CPU Usage via /proc/stats,-w [int] warning value,-c [int] critical value,-s [int] decimal precision of results,-a return values for all cpus individually;
#Category:
 
# Check CPU Usage via /proc/stats
########################
# DECLARATIONS
########################
 
PROGNAME=`basename $0`
REVISION=`echo ‘$Revision: 1.0 $‘ | sed -e ‘s/[^0-9.]//g‘`
 
DEBUG=0
 
exitstatus=0
result=""
perfdata=""
scale=2
show_all=0
warning=999
critical=999
 
TMPFILE="/tmp/check_cpu.tmp"
 
status[0]="OK: "
status[1]="WARNING: "
status[2]="CRITICAL: "
status[3]="UNKNOWN: "
 
########################
# FUNCTIONS
########################
 
print_usage() {
  echo "Usage: $PROGNAME [options]"
  echo "  e.g. $PROGNAME -w 75 -c 90 -s 2 --all"
  echo
  echo "Options:"
  echo -e "\t --help    | -h       print help"
  echo -e "\t --version | -V       print version"
  echo -e "\t --verbose | -v       be verbose (debug mode)"
  echo -e "\t --scale   | -s [int] decimal precision of results"
  echo -e "\t                        default=2"
  echo -e "\t --all     | -a       return values for all cpus individually"
  echo -e "\t                        default= summary data only"
  echo -e "\t -w [int]             set warning value"
  echo -e "\t -c [int]             set critical value"
  echo
  echo
}
 
print_help() {
#  print_revision $PROGNAME $REVISION
  echo "${PROGNAME} Revision: ${REVISION}"
  echo
  echo "This plugin checks local cpu usage using /proc/stat"
  echo
  print_usage
  echo
# support
  exit 3
}
 
parse_options() {
# parse cmdline arguments
  (( DEBUG )) && echo "Parsing options $1 $2 $3 $4 $5 $6 $7 $8"
  if [ "$#" -gt 0 ]; then
    while [ "$#" -gt 0 ]; do
      case "$1" in
        ‘--help‘|‘-h‘)
          print_help
          exit 3
          ;;
        ‘--version‘|‘-V‘)
          #print_revision $PROGNAME $REVISION
          echo "${PROGNAME} Revision: ${REVISION}"
          exit 3
          ;;
        ‘--verbose‘|‘-v‘)
          DEBUG=1
          shift 1
          ;;
        ‘--scale‘|‘-s‘)
          scale="$2"
          shift 2
          ;;
        ‘--all‘|‘-a‘)
          show_all=1
          shift 1
          ;;
        ‘-c‘)
          critical="$2"
          shift 2
          ;;
        ‘-w‘)
          warning="$2"
          shift 2
          ;;
        *)
          echo "Unknown option!"
          print_usage
          exit 3
          ;;
      esac
    done
  fi
}
 
write_tmpfile() {
  echo "old_date=$(date +%s)" > ${TMPFILE}
  for a in $(seq 0 1 ${cpucount} ); do
    echo "old_system[${a}]=${system[${a}]}" >> ${TMPFILE}
    echo "old_user[${a}]=${user[${a}]}" >> ${TMPFILE}
    echo "old_nice[${a}]=${nice[${a}]}" >> ${TMPFILE}
    echo "old_iowait[${a}]=${iowait[${a}]}" >> ${TMPFILE}
    echo "old_irq[${a}]=${irq[${a}]}" >> ${TMPFILE}
    echo "old_softirq[${a}]=${softirq[${a}]}" >> ${TMPFILE}
    echo "old_idle[${a}]=${idle[${a}]}" >> ${TMPFILE}
    echo "old_used[${a}]=${used[${a}]}" >> ${TMPFILE}
    echo "old_total[${a}]=${total[${a}]}" >> ${TMPFILE}
  done
}
 
read_tmpfile() {
  if [ -e ${TMPFILE} ]; then
    source ${TMPFILE}                   # include the vars from the tmp file
  fi
  (( DEBUG )) && cat ${TMPFILE}
}
 
########################
# MAIN
########################
 
parse_options $@
 
read_tmpfile
 
procstat=$(cat /proc/stat 2>&1)
 (( DEBUG )) && echo "$procstat"
cpucount=$(( $(grep -i cpu <<< "${procstat}" | tail -n 1 | cut -d‘ ‘ -f 1 | grep -Eo [0-9]+) + 1 ))
  (( DEBUG )) && echo "cpucount=${cpucount}"
 
for a in $(seq 0 1 ${cpucount} ); do
  if [ $a -eq ${cpucount} ]; then
    cpu[$a]=$(head -n 1 <<< "${procstat}" | sed ‘s/  / /g‘)
  else
    cpu[$a]=$(grep cpu${a} <<< "${procstat}")
  fi
  user[$a]=$(cut -d‘ ‘ -f 2 <<< ${cpu[$a]})
  nice[$a]=$(cut -d‘ ‘ -f 3 <<< ${cpu[$a]})
  system[$a]=$(cut -d‘ ‘ -f 4 <<< ${cpu[$a]})
  idle[$a]=$(cut -d‘ ‘ -f 5 <<< ${cpu[$a]})
  iowait[$a]=$(cut -d‘ ‘ -f 6 <<< ${cpu[$a]})
  irq[$a]=$(cut -d‘ ‘ -f 7 <<< ${cpu[$a]})
  softirq[$a]=$(cut -d‘ ‘ -f 8 <<< ${cpu[$a]})
  used[$a]=$((( ${user[$a]} + ${nice[$a]} + ${system[$a]} + ${iowait[$a]} + ${irq[$a]} + ${softirq[$a]} )))
  total[$a]=$((( ${user[$a]} + ${nice[$a]} + ${system[$a]} + ${idle[$a]} + ${iowait[$a]} + ${irq[$a]} + ${softirq[$a]} )))
 
  [ -z ${old_user[${a}]} ] && old_user[${a}]=0
  [ -z ${old_nice[${a}]} ] && old_nice[${a}]=0
  [ -z ${old_system[${a}]} ] && old_system[${a}]=0
  [ -z ${old_idle[${a}]} ] && old_idle[${a}]=0
  [ -z ${old_iowait[${a}]} ] && old_iowait[${a}]=0
  [ -z ${old_irq[${a}]} ] && old_irq[${a}]=0
  [ -z ${old_softirq[${a}]} ] && old_softirq[${a}]=0
  [ -z ${old_used[${a}]} ] && old_used[${a}]=0
  [ -z ${old_total[${a}]} ] && old_total[${a}]=0
 
  diff_user[$a]=$(((${user[$a]}-${old_user[${a}]})))
  diff_nice[$a]=$(((${nice[$a]}-${old_nice[${a}]})))
  diff_system[$a]=$(((${system[$a]}-${old_system[${a}]})))
  diff_idle[$a]=$(((${idle[$a]}-${old_idle[${a}]})))
  diff_iowait[$a]=$(((${iowait[$a]}-${old_iowait[${a}]})))
  diff_irq[$a]=$(((${irq[$a]}-${old_irq[${a}]})))
  diff_softirq[$a]=$(((${softirq[$a]}-${old_softirq[${a}]})))
  diff_used[$a]=$(((${used[$a]}-${old_used[${a}]})))
  diff_total[$a]=$(((${total[$a]}-${old_total[${a}]})))
 
  pct_user[$a]=$(bc <<< "scale=${scale};${diff_user[$a]}*100/${diff_total[$a]}")
  pct_nice[$a]=$(bc <<< "scale=${scale};${diff_nice[$a]}*100/${diff_total[$a]}")
  pct_system[$a]=$(bc <<< "scale=${scale};${diff_system[$a]}*100/${diff_total[$a]}")
  pct_idle[$a]=$(bc <<< "scale=${scale};${diff_idle[$a]}*100/${diff_total[$a]}")
  pct_iowait[$a]=$(bc <<< "scale=${scale};${diff_iowait[$a]}*100/${diff_total[$a]}")
  pct_irq[$a]=$(bc <<< "scale=${scale};${diff_irq[$a]}*100/${diff_total[$a]}")
  pct_softirq[$a]=$(bc <<< "scale=${scale};${diff_softirq[$a]}*100/${diff_total[$a]}")
  pct_used[$a]=$(bc <<< "scale=${scale};${diff_used[$a]}*100/${diff_total[$a]}")
done
 
write_tmpfile
 
if [ "$(cut -d‘.‘ -f 1 <<< ${pct_used[${cpucount}]})" = "" ]; then
  :
else
  [ $(cut -d‘.‘ -f 1 <<< ${pct_used[${cpucount}]}) -ge ${warning} ] && exitstatus=1
  [ $(cut -d‘.‘ -f 1 <<< ${pct_used[${cpucount}]}) -ge ${critical} ] && exitstatus=2
fi
 
result="CPU=${pct_used[${cpucount}]}"
if [ $show_all -gt 0 ]; then
  for a in $(seq 0 1 $(((${cpucount} - 1)))); do
    result="${result}, CPU${a}=${pct_used[${a}]}"
  done
fi
 
if [ "${warning}" = "999" ]; then
  warning=""
fi
if [ "${critical}" = "999" ]; then
  critical=""
fi
 
perfdata="used=${pct_used[${cpucount}]};${warning};${critical};; system=${pct_system[${cpucount}]};;;; user=${pct_user[${cpucount}]};;;; nice=${pct_nice[${cpucount}]};;;; iowait=${pct_iowait[${cpucount}]};;;; irq=${pct_irq[${cpucount}]};;;; softirq=${pct_softirq[${cpucount}]};;;;"
if [ $show_all -gt 0 ]; then
  for a in $(seq 0 1 $(((${cpucount} - 1)))); do
    perfdata="${perfdata} used${a}=${pct_used[${a}]};;;; system${a}=${pct_system[${a}]};;;; user${a}=${pct_user[${a}]};;;; nice${a}=${pct_nice[${a}]};;;; iowait${a}=${pct_iowait[${a}]};;;; irq${a}=${pct_irq[${a}]};;;; softirq${a}=${pct_softirq[${a}]};;;;"
  done
fi
 
echo "${status[$exitstatus]}${result} | ${perfdata}"
exit $exitstatus

运行脚本出来结果如下:

OK: CPU=4.10 | used=4.10;;;; system=1.01;;;; user=2.82;;;; nice=0;;;; iowait=.05;;;; irq=0;;;; softirq=.21;;;;

由于我们只需要数值,其他内容都不需要,而且CPU数值又分很多种类,需要取不同数值分成不同OID,让cacti取OID后进行多线画图,所以需要其他脚本来优化。

5.2.3      cpu.sh脚本

cpu.sh脚本是将各种类数值取出,然后写入临时文件,好让cacti取数值。

内容如下:

#!/bin/bash
/usr/local/bin/check_cpu.sh | sed ‘s/\=\./=0./g‘ | sed ‘s/;;;;//g‘ | awk -F"|" ‘{ print $2 }‘ > /tmp/cpu.tmp
awk -F " " ‘{ print $1 }‘ /tmp/cpu.tmp | awk -F"=" ‘{ print $2 }‘ > /tmp/used.tmp
awk -F " " ‘{ print $2 }‘ /tmp/cpu.tmp | awk -F"=" ‘{ print $2 }‘ > /tmp/system.tmp
awk -F " " ‘{ print $3 }‘ /tmp/cpu.tmp | awk -F"=" ‘{ print $2 }‘ > /tmp/user.tmp
awk -F " " ‘{ print $4 }‘ /tmp/cpu.tmp | awk -F"=" ‘{ print $2 }‘ > /tmp/nice.tmp
awk -F " " ‘{ print $5 }‘ /tmp/cpu.tmp | awk -F"=" ‘{ print $2 }‘ > /tmp/iowait.tmp
awk -F " " ‘{ print $6 }‘ /tmp/cpu.tmp | awk -F"=" ‘{ print $2 }‘ > /tmp/irq.tmp
awk -F " " ‘{ print $7 }‘ /tmp/cpu.tmp | awk -F"=" ‘{ print $2 }‘ > /tmp/softirq.tmp

5.2.4      取数值脚本

取数值脚本每个种类数值有一个脚本,分别是cpu_used.sh,cpu_system.sh,cpu_nice.sh,cpu_user.sh,cpu_iowait.sh,cpu_irq.sh,cpu_softirq.sh 这些脚本就是根据不同种类去显示不同数值,这里举例两个脚本内容:

cpu_used.sh

#!/bin/bash
cat /tmp/used.tmp

 

cpu_system.sh

#!/bin/bash
cat /tmp/system.tmp

 

5.2.5      配置snmp

修改snmp的配置文件

vi /etc/snmp/snmpd.conf

在最后增加以下几行

extend .1.3.6.1.4.1.2021.1 cpu_used  /usr/local/bin/cpu_used.sh

extend .1.3.6.1.4.1.2021.2 cpu_system /usr/local/bin/cpu_system.sh

extend .1.3.6.1.4.1.2021.3 cpu_nice  /usr/local/bin/cpu_nice.sh

extend .1.3.6.1.4.1.2021.5 cpu_user  /usr/local/bin/cpu_user.sh

extend .1.3.6.1.4.1.2021.6 cpu_iowait  /usr/local/bin/cpu_iowait.sh

extend .1.3.6.1.4.1.2021.7 cpu_irq  /usr/local/bin/cpu_irq.sh

extend .1.3.6.1.4.1.2021.8 cpu_softirq  /usr/local/bin/cpu_softirq.sh

命令       OID号          名称               脚本取值

注:OID号必须是未使用的号码,可以通过命令来检测OID号是否已用:

snmpwalk -v 2c –c  snmp密码  本机IP  .1.3.6.1.4.1.2021.1

如果出现:

UCD-SNMP-MIB::ucdavis.1 = No Such Object available on this agent at this OID

说明OID没有被使用,可以使用这个OID。

配置完毕需要重启snmp服务

/etc/init.d/snmpd restart

5.2.6      增加数据模板

l  登陆cacti,进入主界面,点击Data Templates,再点击Add增加新数据模板,如图(图33):

技术分享

图33

l  填写相应信息,并按创建。如图(图34)

技术分享

图34

红框信息如下:

Name:cpu_used                    #根据种类写名称

Name:|host_description| – CPU – used          #根据种类写名称

Data Input Method:Get SNMP Data               #选择snmp数据

Internal Data Source Name:cpuused                     #根据种类写名称

l  获取OID信息

比如获取cpu_used的OID,先查看snmp配置文件拿取OID,如图(图35):

技术分享

图35

登陆cacti服务器,执行以下命令:

snmpwalk -v 2c –c  snmp密码  被监控机IP  .1.3.6.1.4.1.2021.1

出现以下数据,如图(图36)

技术分享

图36

红框里面的数字OID .1.4.1.2.8.99.112.117.95.117.115.101.100.1 记下

真正OID是这样:.1.3.6.1.4.1.2021.1.4.1.2.8.99.112.117.95.117.115.101.100.1

红色部门是snmp配置的OID,蓝色部分是命令里生成OID

l  填写OID信息

当数据模板创建成功之后,下面会出现新的框,要写入OID信息。

将上面获取.1.3.6.1.4.1.2021.1.4.1.2.8.99.112.117.95.117.115.101.100.1填入,如图(图37)

技术分享

图37

l  创建完毕,如图会出现新数据。(图38)

技术分享

图38

l  每个种类数据都需创建一个,都创建好如图(图39):

技术分享

图39

5.2.7      增加图形模板

l  登陆cacti,进入主界面,点击Graph Templates,再点击Add增加新图形模板。如图(图40)

技术分享

图40

l  填入相应信息,按Create创建,如图(图41)

技术分享

图41

红框信息如下:

Name:CPU

Title:|host_description| – CPU

l  增加画线图形

上面创建完毕之后,就可以增加画线图形,如图(图42)

技术分享

图42

选择一个数据源(就是之前创建数据模板),然后填入相应信息(画图),如图(图43)

技术分享

图43

再新增点击Add,填入相应信息(显示现在数值),如图(图44)

技术分享

图44

再新增点击Add,填入相应信息(显示平均数值),如图(图45)

技术分享

图45

再新增点击Add,填入相应信息(显示最大数值),如图(图46)

技术分享

图46

这就完成了一个种类数据的图形模板,会如下显示,(图47)

技术分享

图47

按照以上方法同样完成其他种类的数据,全部完成之后,会显示这样。如图(图48)

技术分享

图48

5.2.8      增加图形

l  点击主机页面,增加CPU模板。如图(图49)

技术分享

图49

l  点击New Graphs,选择CPU,并创建,如图(图50)

技术分享

图50

5.2.9      出图效果

添加图形完毕之后,出图效果如下(图51):

技术分享

图51

5.3  内存自定义监控

5.3.1      脚本架构图

脚本架构图如下(图52)

技术分享

图52

架构图说明:

三个脚本主要通过free mem命令,运行速度很快,所以cacti可以直接拿取数值,比较简单。

所有脚本都放在/usr/local/bin

5.3.2      mem_total.sh

内容如下:

#!/bin/bash
memto=`free mem -b | grep Mem | awk -F" " ‘{ print $2}‘`
echo $memto

其实这里的数值主要是取free mem里面total数值,如图(图53)

技术分享

图53

5.3.3      mem_used.sh

内容如下:

#!/bin/bash
memto=`free mem -b | grep buffers/cache | awk -F" " ‘{ print $3}‘`
echo $memto

其实这里的数值主要是取free mem里面第二行的used数值,如图(图54)

技术分享

图54

5.3.4      mem_free.sh

内容如下:

#!/bin/bash
memto=`free mem -b | grep buffers/cache | awk -F" " ‘{ print $4}‘`
echo $memto

其实这里的数值主要是取free mem里面第二行的free数值,如图(图55)

技术分享

图55

5.3.5      配置snmp

修改snmp的配置文件

vi /etc/snmp/snmpd.conf

在最后增加以下几行

extend .1.3.6.1.4.1.2022.1 mem_total  /usr/local/bin/mem_total.sh

extend .1.3.6.1.4.1.2022.2 mem_used  /usr/local/bin/mem_used.sh

extend .1.3.6.1.4.1.2022.3 mem_free  /usr/local/bin/mem_free.sh

具体解释见5.2.5

5.3.6      增加数据模板

l  登陆cacti,进入主界面,点击Data Templates,再点击Add增加新数据模板,如图(图56):

技术分享

图56

l  填写相应信息,并按创建。如图(图57)

技术分享

图57

红框信息如下:

Name:mem_total                  #根据种类写名称

Name:|host_description| – MEM – total         #根据种类写名称

Data Input Method:Get SNMP Data               #选择snmp数据

Internal Data Source Name:memtotal            #根据种类写名称

l  填写OID信息,如图(图58)

技术分享

图58

注:如何获取OID详见5.2.6

l  创建完毕,如图会出现新数据。(图59)

技术分享

图59

l  每个种类数据都需创建一个,都创建好如图(图60):

技术分享

图60

5.3.7      增加图形模板

l  登陆cacti,进入主界面,点击Graph Templates,再点击Add增加新图形模板。如图(图61)

技术分享

图61

l  填入相应信息,按Create创建,如图(图62)

技术分享

图62

红框信息如下:

Name:MEM

Title:|host_description| – MEM

l  增加画线图形

上面创建完毕之后,就可以增加画线图形,如图(图63)

技术分享

图63

选择一个数据源(就是之前创建数据模板),然后填入相应信息(画图),如图(图64)

技术分享

图64

再新增点击Add,填入相应信息(显示现在数值),如图(图65)

技术分享

图65

再新增点击Add,填入相应信息(显示平均数值),如图(图66)

技术分享

图66

再新增点击Add,填入相应信息(显示最大数值),如图(图67)

技术分享

图67

这就完成了一个种类数据的图形模板,会如下显示,(图68)

技术分享

图68

按照以上方法同样完成其他种类的数据,全部完成之后,会显示这样。如图(图69)

技术分享

图69

注:mem_used用的图形类型是AREA,mem_free用的图形类型是STACK

5.3.8      增加图形

l  点击主机页面,增加MEM模板。如图(图70)

技术分享

图70

l  点击New Graphs,选择MEM,并创建,如图(图71)

技术分享

图71

5.3.9      出图效果

添加图形完毕之后,出图效果如下(图72):

技术分享

图72

5.4  windos监控

5.4.1      安装informant-std-16

5.4.2      安装snmp

通过SNMP监控Windows主机需要在被监控的服务器上安装简单网络管理协议(SNMP)的Windows组件,以Windows 7系统为例:

首先,在控制面板中找到“程序和功能”;如图(图73)

技术分享

图73

在弹出的窗口中单击“打开或关闭Windows功能”;如图(图74)

技术分享

图74

勾选弹出窗口中的“简单网络管理协议(SNMP)”项后单击“确定”并根据提示完成安装即可。如图(图75,图76)

技术分享

图75

技术分享

图76

5.4.3      配置snmp

完成SNMP服务的安装后,右键单击“计算机”选择“管理”

在弹出的“计算机管理”窗口中左侧导航栏中找到“服务”,并在右侧找到“SNMP Service”项;如图(图77)

技术分享

图77

鼠标双击“SNMP Service”选项,在弹出的窗口中切换到“安全”选项卡中,如上图添加“接受的社区名称”和接收那些主机发出的SNMP数据包。如图(图78)

技术分享

图78

到这里被监控端的Windows主机的SNMP服务就配置完成了。

5.4.4      配置cacti

解压文件Cacti_SNMP_Informant_Standard_Metrics_v13.zip,把template文件夹中的6个模板文件,通过cacit操作界面导入。如图(图79)

技术分享

图79

然后把文件夹中的xml文件,放到cacti服务器中的相应目录

cp snmp_informant*  /opt/nginx/html/cacti/resource/snmp_queries/

5.4.5      创建主机

windows主机图形增加如下,如图(图80)

技术分享

图80

5.4.6      安装informant-std-16(被监控机)

安装程序informant-std-16.exe,都按下一步完成安装即可。

5.4.7      增加图形

详见3.9.2

5.5  nginx监控

5.5.1      配置nginx

l  首先nginx编译时允许http_stub_status_module,不然是监控不到nginx的运行状态的。

l  编辑配置文件

vi nginx.conf

添加以下内容

location /NginxStatus/ {

stub_status on;

access_log off;

allow 192.168.0.0/16;#意思是只允许内网能看到监控信息

deny all;

}

l  重新加载nginx的配置文件

/opt/nginx/sbin/nginx –s reload

5.5.2      下载nginx监控模板(监控机)

wget http://forums.cacti.net/download.php?id=12676

tar xvfz cacti-nginx.tar.gz

cp cacti-nginx/get_nginx_socket_status.pl /data/cacti/scripts/

cp cacti-nginx/get_nginx_clients_status.pl /data/cacti/scripts/

chmod 755 /data/cacti/scripts/get_nginx*

5.5.3      测试插件

/data/cacti/scripts/get_nginx_clients_status.pl http://192.168.9.25/NginxStatus/

输出信息:nginx_active:245 nginx_reading:11 nginx_writing:4 nginx_waiting:230

/data/cacti/scripts/get_nginx_socket_status.pl http://192.168.9.25/NginxStatus/

输出信息:nginx_accepts:41377 nginx_handled:41377 nginx_requests:223307

注:如果出现no (LWP::UserAgent not found),出现这个问题是perl里缺少组件,你可以按照下面的步骤解决:

yum -y install perl-libwww-perl  或者

perl -MCPAN -e shell

cpan> install LWP::UserAgent

5.5.4      导入面板

之前下载的cacti-nginx.tar.gz里两个文件:

cacti_graph_template_nginx_clients_stat.xml

cacti_graph_template_nginx_sockets_stat.xml

技术分享

图81

5.5.5      创建图形

添加主机,在创建图形的时候会提示你输入URL of nginx stub status,后面你所监控的页面额url,比如上面我们的http://192.168.9.25/NginxStatus/,然后稍等下数据就会出来了。

 

5.6  apache监控

5.6.1      配置apache

l  编辑httpd.conf配置文件

vi httpd.conf

查找是否有status_module这个模块

LoadModule status_module modules/mod_status.so

将下面注释去掉

ExtendedStatus On

增加以下语句

<Location /server-status>

   SetHandler server-status

   Order deny,allow

   Deny from all

   Allow from localhost                        #此处localhost为Cacti监控主机

</Location>

注:如果是apache2.4版本请这样写:

<Location /server-status>

   SetHandler server-status

   Require ip 180.168.71.206

   Require all denied

</Location>

注:若apache服务器是通过源码编译安装,则在编译时需要加上相应的server_status模块

l  修改之后保存并重启

/etc/init.d/httpd reload

5.6.2          下载导入监控模板

l  下载所需模板和php文件

http://forums.cacti.net/download/file.php?id=18576&sid=8d429b69af5be45179d928e1303f2072

l  解压之后将ss_apache_stats.php上传到cacti/scripts目录内:

cp ss_apache_stats.php cacti/scripts/

l  在Cacti Web界面导入cacti_host_template_webserver_-_apache.xml模板:

点击Import/Export->Import Templates,上传模板即可

5.6.3          创建图形

l  登录Cacti Web界面,添加被监控apache服务器设备,并创建相应图表

l  有些图片出现位置不一致,按照下面进行设置即可:

技术分享

图82

技术分享

图83

技术分享

图84


本文出自 “桃子技术” 博客,请务必保留此出处http://taozijishu.blog.51cto.com/11320335/1959367

cacti运维手册

标签:cacti 监控

原文地址:http://taozijishu.blog.51cto.com/11320335/1959367

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!