cacti運維手冊php
1 前言css
1.1 系統功能概述html
cacti是經過 snmpget來獲取數據,使用 RRDtool繪畫圖形,並且你徹底能夠不須要了解RRDtool複雜的參數。它提供了很是強大的數據和用戶管理功能,能夠指定每個用戶能查看樹狀結構、host以及任何一張圖,還能夠與LDAP結合進行用戶驗證,同時也能本身增長模板,功能很是強大完善。界面友好。軟件 Cacti 的發展是基於讓 RRDTool 使用者更方便使用該軟件,除了基本的 Snmp 流量跟系統資訊監控外,Cacti 也可外掛 Scripts 及加上 Templates 來做出各式各樣的監控圖。mysql
2 系統架構linux
2.1 服務器架構圖nginx
l 這裏是使用nginx+cacti架構,圖以下(圖1):c++
圖1web
l 架構圖解析redis
1 cacti是經過web訪問的監控程序,因此須要依賴web服務,這裏使用nginx來作web服務。sql
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