运维监控之zabbix


商业监控软件汇总
【1】博睿:http://www.oneapm.com
【2】监控宝:http://www.jiankongbao.com
【3】基调(听云):http://www.tingyun.com

开源监控软件汇总
【1】cacti
【2】nagios
【3】zabbix

监控思想
【1】监控对象
【2】监控指标
【3】监控实现

网络监控
【1】站长工具:http://tool.chinaz.com
【2】smokeping:http://oss.oetiker.ch/smokeping(rrdtool作者编写)
【3】17ce:http://www.17ce.com

硬件监控
【1】机房巡检:正常巡检,每季度/次
【2】ipmitool:硬件状态,但不能获取硬盘的状态
【3】megacli:RAID状态

系统监控
【1】cpu:top
【2】mem:vmstat
【3】swap
【4】I/O:iotop
【5】disk:使用率
【6】network:iftop/ifstat
【7】tcp连接数:11种状态数
【8】进程:进程总数
【8-1】cpu使用率:top10
【8-2】mem使用率:top10
【8-3】network使用率:top10
【8-4】I/O使用率:top10
【9】重要文件,如:/etc/passwd
【10】系统负载
【11】系统登录用户数
【12】系统运行时间

应用监控
【1】Apache、Nginx、Tomcat、Resin、PHP、Redis、Memcached、MySQL、Oracle、LVS、Haproxy
【2】端口
【3】网站:响应时间、下载速度、PV、UV、IP
【4】接口(访问控制ACL):调用次数、响应时间

自动化监控
【1】zabbix agent自动注册
【2】zabbix server discovery
【3】zabbix API
【3-1】User-->user.login
[root@linux-node1 ~]# curl -s -X PSOT -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "user": "keywa",
        "password": "axbc1kof"
    },
    "id": 1
}' http://192.168.100.128:48836/api_jsonrpc.php | python -mjson.tool
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": "37b1834bbd121a1e8aad59c6a77e4094"
}

【3-2】Host-->host.get
[root@linux-node1 ~]# curl -s -X PSOT -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"]
    },
    "auth": "37b1834bbd121a1e8aad59c6a77e4094",
    "id": 2
}' http://192.168.100.128:48836/api_jsonrpc.php | python -mjson.tool
{
    "id": 2,
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10105"
        }
    ]
}

[root@linux-node1 ~]# curl -s -X PSOT -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["host"]
    },
    "auth": "37b1834bbd121a1e8aad59c6a77e4094",
    "id": 2
}' http://192.168.100.128:48836/api_jsonrpc.php | python -mjson.tool
{
    "id": 2,
    "jsonrpc": "2.0",
    "result": [
        {
            "host": "kw web01",
            "hostid": "10105"
        }
    ]
}

zabbix API步骤
【1】验证,获取session ID
[root@linux-node1 ~]# curl -s -X PSOT -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "user": "keywa",
        "password": "axbc1kof"
    },
    "id": 1
}' http://192.168.100.128:48836/api_jsonrpc.php | python -mjson.tool
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": "37b1834bbd121a1e8aad59c6a77e4094"
}
【2】请求API,附带session ID
Host-->host.create
[root@linux-node1 ~]# curl -s -X PSOT -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "Zabbix server",
        "interfaces": [
            {
                "type": 1,
                "main": 1,
                "useip": 1,
                "ip": "192.168.100.128",
                "dns": "",
                "port": "10050"
            }
        ],
        "groups": [
            {
                "groupid": "8"
            }
        ],
        "templates": [
            {
                "templateid": "10118",
				"templateid": "10119",
				"templateid": "10108",
				"templateid": "10109",
				"templateid": "10115",
				"templateid": "10112",
				"templateid": "10111"
            }
        ]
    },
    "auth": "37b1834bbd121a1e8aad59c6a77e4094",
    "id": 1
}' http://192.168.100.128:48836/api_jsonrpc.php | python -mjson.tool
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10124"
        ]
    }
}

zabbix官方网站:http://www.zabbix.com

[root@linux-node1 ~]# yum -y install mysql-server mysql
[root@linux-node1 ~]# /etc/init.d/mysqld start
[root@linux-node1 ~]# netstat -tnlup|grep "3306"|grep -v "grep"
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      2068/mysqld
[root@linux-node1 ~]# /bin/cp -a /usr/share/mysql/my-medium.cnf /etc/my.cnf
[root@linux-node1 ~]# vim /etc/my.cnf
[mysqld]
port            = 3306
socket          = /var/lib/mysql/mysql.sock
skip-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
character-set-server = utf8
init-connect = 'SET NAMES utf8'
collation-server = utf8_general_ci
[root@linux-node1 ~]# /etc/init.d/mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[root@linux-node1 ~]# netstat -tnlup|grep "3306"|grep -v "grep"
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      2338/mysqld
[root@linux-node1 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73-log Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.03 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@linux-node1 ~]# chkconfig --level 3 mysqld on
[root@linux-node1 ~]# chkconfig --list mysqld
mysqld          0:off   1:off   2:off   3:on    4:off   5:off   6:off
[root@linux-node1 ~]# rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
Retrieving http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
warning: /var/tmp/rpm-tmp.fk9HRc: Header V4 DSA/SHA1 Signature, key ID 79ea5ed4: NOKEY
Preparing...                ########################################### [100%]
   1:zabbix-release         ########################################### [100%]
[root@linux-node1 ~]# rpm -ql zabbix-release-2.4-1.el6.noarch
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
/etc/yum.repos.d/zabbix.repo
/usr/share/doc/zabbix-release-2.4
/usr/share/doc/zabbix-release-2.4/GPL
[root@linux-node1 ~]# ls -l /etc/yum.repos.d/zabbix.repo
-rw-r--r--. 1 root root 636 Sep 14  2016 /etc/yum.repos.d/zabbix.repo
[root@linux-node1 ~]# yum -y install zabbix zabbix-server zabbix-web zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-get
[root@linux-node1 ~]# rpm -qa zabbix zabbix-server zabbix-web zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-get
zabbix-2.4.8-1.el6.x86_64
zabbix-server-2.4.8-1.el6.x86_64
zabbix-agent-2.4.8-1.el6.x86_64
zabbix-server-mysql-2.4.8-1.el6.x86_64
zabbix-web-2.4.8-1.el6.noarch
zabbix-get-2.4.8-1.el6.x86_64
zabbix-web-mysql-2.4.8-1.el6.noarch
[root@linux-node1 ~]# vim /etc/httpd/conf.d/zabbix.conf
<Directory "/usr/share/zabbix">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all

    <IfModule mod_php5.c>
        php_value max_execution_time 300
        php_value memory_limit 128M
        php_value post_max_size 16M
        php_value upload_max_filesize 2M
        php_value max_input_time 300
        php_value date.timezone Asia/Shanghai
    </IfModule>
</Directory>
[root@linux-node1 ~]# /etc/init.d/httpd start
Starting httpd:                                            [  OK  ]
[root@linux-node1 ~]# cd /usr/share/doc/zabbix-server-mysql-2.4.8/create/
[root@linux-node1 create]# ls
data.sql  images.sql  schema.sql
[root@linux-node1 create]# mysql -uroot -p zabbix < schema.sql
[root@linux-node1 create]# mysql -uroot -p zabbix < images.sql
[root@linux-node1 create]# mysql -uroot -p zabbix < data.sql
[root@linux-node1 create]# vim /etc/zabbix/zabbix_server.conf
72 DBHost=localhost
82 DBName=zabbix
98 DBUser=zabbix
106 DBPassword=zabbix
[root@linux-node1 create]# grep "^[a-Z]" /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
SNMPTrapperFile=/var/log/snmptt/snmptt.log
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
[root@linux-node1 create]# /etc/init.d/httpd restart

浏览器访问:http://192.168.100.133/zabbix

默认登录账号密码
user:Admin
password:zabbix

[root@linux-node1 ~]# /etc/init.d/zabbix-server start
Starting Zabbix server:                                    [  OK  ]
[root@linux-node1 ~]# netstat -tnlup|grep "10051"|grep -v "grep"
tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      27785/zabbix_server
tcp        0      0 :::10051                    :::*                        LISTEN      27785/zabbix_server
[root@linux-node1 ~]# chkconfig --level 3 zabbix-server on
[root@linux-node1 ~]# chkconfig --list zabbix-server
zabbix-server   0:off   1:off   2:off   3:on    4:off   5:off   6:off

修改密码:Profile-->Change Password-->update

[root@linux-node1 ~]# vim /etc/zabbix/zabbix_agentd.conf
85 Server=192.168.100.133
[root@linux-node1 ~]# grep "^[a-Z]" /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.100.133
ServerActive=127.0.0.1
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agentd.d/
[root@linux-node1 ~]# /etc/init.d/zabbix-agent start
Starting Zabbix agent:                                     [  OK  ]
[root@linux-node1 ~]# netstat -tnlup|grep "10050"|grep -v "grep"
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      28271/zabbix_agentd
tcp        0      0 :::10050                    :::*                        LISTEN      28271/zabbix_agentd
[root@linux-node1 ~]# chkconfig --level 3 zabbix-agent on
[root@linux-node1 ~]# chkconfig --list zabbix-agent
zabbix-agent    0:off   1:off   2:off   3:on    4:off   5:off   6:off

[root@linux-node2 ~]# rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
Retrieving http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
warning: /var/tmp/rpm-tmp.9T9bnk: Header V4 DSA/SHA1 Signature, key ID 79ea5ed4: NOKEY
Preparing...                ########################################### [100%]
   1:zabbix-release         ########################################### [100%]
[root@linux-node2 ~]# rpm -ql zabbix-release
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
/etc/yum.repos.d/zabbix.repo
/usr/share/doc/zabbix-release-2.4
/usr/share/doc/zabbix-release-2.4/GPL
[root@linux-node2 ~]# yum -y install zabbix-agent
[root@linux-node2 ~]# vim /etc/zabbix/zabbix_agentd.conf
85 Server=192.168.100.133
[root@linux-node2 ~]# grep "^[a-Z]" /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.100.133
ServerActive=127.0.0.1
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agentd.d/
[root@linux-node2 ~]# /etc/init.d/zabbix-agent start
Starting Zabbix agent:                                     [  OK  ]
[root@linux-node2 ~]# netstat -tnlup|grep "10050"|grep -v "grep"
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      27515/zabbix_agentd
tcp        0      0 :::10050                    :::*                        LISTEN      27515/zabbix_agentd
[root@linux-node2 ~]# chkconfig --level 3 zabbix-agent on
[root@linux-node2 ~]# chkconfig --list zabbix-agent
zabbix-agent    0:off   1:off   2:off   3:on    4:off   5:off   6:off

自定义监控项步骤
【1】修改配置文件(zabbix_agentd.conf)
【2】网页加入监控(zabbix web)
[root@linux-node2 ~]# vim /etc/zabbix/zabbix_agentd.conf
280 UserParameter=login.users.num,who -u|wc -l		<==key在整个系统是唯一的,可返回最大数据512KB
[root@linux-node2 ~]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent:                                [  OK  ]
Starting Zabbix agent:                                     [  OK  ]

[root@linux-node1 ~]# zabbix_get -s 192.168.100.128 -k login.users.num
1

网站流量分析工具:https://piwik.org

SEO:搜索引擎优化

PV、UV、IP
====================================================================================
zabbix短信报警
[root@linux-node1 ~]# vim /etc/zabbix/zabbix_server.conf
447 AlertScriptsPath=${datadir}/zabbix/alertscripts
[root@linux-node1 ~]# mkdir /usr/local/zabbix/zabbix/alertscripts -p
[root@linux-node1 ~]# ls -ld /usr/local/zabbix/zabbix/alertscripts/
drwxr-xr-x 2 root root 4096 Aug  1 09:49 /usr/local/zabbix/zabbix/alertscripts/
[root@linux-node1 ~]# cd /usr/local/zabbix/zabbix/alertscripts/
[root@linux-node1 alertscripts]# 
====================================================================================
zabbix监控TCP连接数
[root@linux-node1 ~]# vim /server/scripts/zabbix/tcp_status.sh
#!/bin/bash
# Name:tcp_status.sh
# Version:V1.0
# Type:Monitor
# Language:Bash Shell
# Date:2016-04-26
# Author:LinBin
# Email:linbin@keywa.com
# Description:Monitor TCP Connections

# Determine The Number Of Parameters.
if [ $# -ne 1 ]
then
    echo "USAGE:$0 {SYN_SENT|SYN_RECV|ESTABLISHED|FIN_WAIT_1|CLOSE_WAIT|FIN_WAIT_2|LAST_ACK|TIME_WAIT|CLOSED|CLOSING|LISTEN}"
    exit 1
fi

# Defined Variables.
SS="/usr/sbin/ss"
Tmp_File="/tmp/ss.txt"

# Functions To Return TCP Connections.
function tcp_status() {
         TCP_STAT=$1
             $SS -ant|awk 'NR>1{array[$1]++}END{for(key in array) print key,array[key]}' > $Tmp_File
             TCP_STAT_VALUE=$(awk '/'$TCP_STAT'/ {print $2}' $Tmp_File)
             if [ -z "$TCP_STAT_VALUE" ]
             then
                 TCP_STAT_VALUE=0
             fi
             echo $TCP_STAT_VALUE
         }

# Execute Functions.
tcp_status $1
[root@linux-node1 ~]# chmod +x /server/scripts/zabbix/tcp_status.sh
[root@linux-node1 ~]# ls -l /server/scripts/zabbix/tcp_status.sh
-rwxr-xr-x 1 root root 908 Jul 20 14:30 /server/scripts/zabbix/tcp_status.sh

[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
278 UnsafeUserParameters=1
263 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/UserParams_TcpStatus.conf
UserParameter=tcp.status[*],/bin/bash /server/scripts/zabbix/tcp_status.sh "$1"
[root@linux-node1 ~]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd:                               [  OK  ]
Starting zabbix_agentd:                                    [  OK  ]

[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k tcp.status[SYN_SENT]
0
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k tcp.status[SYN_RECV]
0
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k tcp.status[ESTAB]
12
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k tcp.status[FIN_WAIT_1]
0
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k tcp.status[FIN_WAIT_2]
0
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k tcp.status[CLOSE_WAIT]
0
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k tcp.status[LAST_ACK]
0
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k tcp.status[TIME_WAIT]
0
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k tcp.status[CLOSED]
0
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k tcp.status[CLOSING]
0
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k tcp.status[LISTEN]
8
====================================================================================
zabbix监控Nginx状态
[root@linux-node1 ~]# vim /usr/local/nginx/conf/vhost/nginx_php-fpm_status.conf
server {
     listen       52113;
     server_name  localhost;
     location /nginx_status {
         stub_status on;
         access_log  off;
         allow 127.0.0.1;
         deny all;
     }
 }
[root@linux-node1 ~]# vim /etc/nginx/nginx.conf
include       /usr/local/nginx/conf/vhost/*.conf;
[root@linux-node1 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@linux-node1 ~]# /usr/local/nginx/sbin/nginx -s reload
[root@linux-node1 ~]# curl http://127.0.0.1:52113/nginx_status
Active connections: 3
server accepts handled requests
 131 131 3111
Reading: 0 Writing: 1 Waiting: 2

[root@linux-node1 ~]# vim /server/scripts/zabbix/nginx_status.sh
#!/bin/bash
# Name:nginx_status.sh
# Version:V1.0
# Type:Monitor
# Language:Bash Shell
# Date:2016-04-26
# Author:LinBin
# Email:linbin@keywa.com
# Description:Monitor Nginx Service Status

# Defined Variables.
Curl="/usr/bin/curl"
Host="127.0.0.1"
Port="52113"
Command=$1

# Functions To Return Nginx Status.
function nginx_active() {
         $Curl -s "http://$Host:$Port"/nginx_status|awk 'NR==1{print $NF}'
     }

function nginx_reading() {
         $Curl -s "http://$Host:$Port"/nginx_status|awk 'NR==4{print $2}'
     }

function nginx_writing() {
         $Curl -s "http://$Host:$Port"/nginx_status|awk 'NR==4{print $4}'
     }

function nginx_waiting() {
         $Curl -s "http://$Host:$Port"/nginx_status|awk 'NR==4{print $NF}'
     }

function nginx_accepts() {
         $Curl -s "http://$Host:$Port"/nginx_status|awk 'NR==3{print $1}'
     }

function nginx_handled() {
         $Curl -s "http://$Host:$Port"/nginx_status|awk 'NR==3{print $2}'
     }

function nginx_requests() {
         $Curl -s "http://$Host:$Port"/nginx_status|awk 'NR==3{print $3}'
     }

# Run The Requested Functions.
case $Command in
    active)
           nginx_active
           ;;

    reading)
           nginx_reading
           ;;

    writing)
           nginx_writing
           ;;

    waiting)
           nginx_waiting
           ;;

    accepts)
           nginx_accepts
           ;;

    handled)
           nginx_handled
           ;;

    requests)
           nginx_requests
           ;;

           *)
           echo "USAGE:$0 {active|reading|writing|waiting|accepts|handled|requests}"
esac
[root@linux-node1 ~]# chmod +x /server/scripts/zabbix/nginx_status.sh
[root@linux-node1 ~]# ls -l /server/scripts/zabbix/nginx_status.sh
-rwxr-xr-x 1 root root 1598 Jul 20 13:40 /server/scripts/zabbix/nginx_status.sh

[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
278 UnsafeUserParameters=1
263 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/UserParams_NginxStatus.conf
UserParameter=nginx_status[*],/bin/bash /server/scripts/zabbix/nginx_status.sh "$1"
[root@linux-node1 ~]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd:                               [  OK  ]
Starting zabbix_agentd:                                    [  OK  ]

[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k nginx_status[active]
3
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k nginx_status[reading]
0
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k nginx_status[writing]
1
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k nginx_status[waiting]
2
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k nginx_status[accepts]
140
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k nginx_status[handled]
141
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k nginx_status[requests]
3526
====================================================================================
zabbix监控登录用户数
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
278 UnsafeUserParameters=1
263 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/UserParams_LoginUserNumber.conf
UserParameter=login.user.number,who -q|awk -F"=" 'NR==2{print $2}'
[root@linux-node1 ~]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd:                               [  OK  ]
Starting zabbix_agentd:                                    [  OK  ]
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k login.user.number
3
====================================================================================
zabbix监控内存
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
278 UnsafeUserParameters=1
263 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/UserParams_Memory.conf
# Monitor Physical Memory.
UserParameter=memory.total,free -m|awk 'NR==2{print $2}'
UserParameter=memory.used,free -m|awk 'NR==3{print $3}'
UserParameter=memory.free,free -m|awk 'NR==3{print $NF}'

# Monitor Virtual Memory.
UserParameter=swap.total,free -m|awk 'NR==4{print $2}'
UserParameter=swap.used,free -m|awk 'NR==4{print $3}'
UserParameter=swap.free,free -m|awk 'NR==4{print $NF}'
[root@linux-node1 ~]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd:                               [  OK  ]
Starting zabbix_agentd:                                    [  OK  ]
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k memory.total
1873
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k memory.used
1250
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k memory.free
622
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k swap.total
699
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k swap.used
0
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k swap.free
699
====================================================================================
zabbix监控PHP-FPM
[root@linux-node1 ~]# vim /usr/local/php/etc/php-fpm.conf
pm.status_path = /php-fpm_status
[root@linux-node1 ~]# /etc/init.d/php-fpm reload
Reload service php-fpm  done
[root@linux-node1 ~]# vim /usr/local/nginx/conf/vhost/nginx_php-fpm_status.conf
server {
     listen       52113;
     server_name  localhost;
     location /nginx_status {
         stub_status on;
         access_log  off;
         allow 127.0.0.1;
         deny all;
     }
 
     location /php-fpm_status {
         include fastcgi_params;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         access_log  off;
         allow 127.0.0.1;
         deny all;
     }
 }
[root@linux-node1 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@linux-node1 ~]# /usr/local/nginx/sbin/nginx -s reload

[root@linux-node1 ~]# curl http://127.0.0.1:52113/php-fpm_status
pool:                 www
process manager:      dynamic
start time:           26/Jul/2017:10:35:41 +0800
start since:          13
accepted conn:        2
listen queue:         0
max listen queue:     0
listen queue len:     16384
idle processes:       1
active processes:     1
total processes:      2
max active processes: 1
max children reached: 0
slow requests:        0

[root@linux-node1 ~]# vim /server/scripts/zabbix/php-fpm_status.sh
#!/bin/bash
# Name:php-fpm_status.sh
# Version:V1.0
# Type:Monitor
# Language:Bash Shell
# Date:2016-04-26
# Author:LinBin
# Email:linbin@keywa.com
# Description:Monitor PHP-FPM Service Status

# Defined Variables.
Curl="/usr/bin/curl"
Host="127.0.0.1"
Port="52113"
Item=$1

# Functions To Return PHP-FPM Status.
function start_since() {
         $Curl -s "http://$Host:$Port"/php-fpm_status|awk 'NR==4{print $3}'
     }

function accepted_conn() {
         $Curl -s "http://$Host:$Port"/php-fpm_status|awk 'NR==5{print $3}'
     }

function listen_queue() {
         $Curl -s "http://$Host:$Port"/php-fpm_status|awk 'NR==6{print $3}'
     }

function max_listen_queue() {
         $Curl -s "http://$Host:$Port"/php-fpm_status|awk 'NR==7{print $4}'
     }

function listen_queue_len() {
         $Curl -s "http://$Host:$Port"/php-fpm_status|awk 'NR==8{print $4}'
     }

function idle_processes() {
         $Curl -s "http://$Host:$Port"/php-fpm_status|awk 'NR==9{print $3}'
     }

function active_processes() {
         $Curl -s "http://$Host:$Port"/php-fpm_status|awk 'NR==10{print $3}'
     }

function total_processes() {
         $Curl -s "http://$Host:$Port"/php-fpm_status|awk 'NR==11{print $3}'
     }

function max_active_processes() {
         $Curl -s "http://$Host:$Port"/php-fpm_status|awk 'NR==12{print $4}'
     }

function max_children_reached() {
         $Curl -s "http://$Host:$Port"/php-fpm_status|awk 'NR==13{print $4}'
     }

function slow_requests() {
         $Curl -s "http://$Host:$Port"/php-fpm_status|awk 'NR==14{print $3}'
     }

# Run The Requested Functions.
case $Item in
    start_since)
                start_since
                ;;

    accepted_conn)
                accepted_conn
                ;;

    listen_queue)
                listen_queue
                ;;

    max_listen_queue)
                max_listen_queue
                ;;

    listen_queue_len)
                listen_queue_len
                ;;

    idle_processes)
                idle_processes
                ;;

    active_processes)
                active_processes
                ;;

    total_processes)
                total_processes
                ;;

    max_active_processes)
                max_active_processes
                ;;

    max_children_reached)
                max_children_reached
                ;;

    slow_requests)
                slow_requests
                ;;

    *)
                echo "USAGE:$0 {start_since|accepted_conn|listen_queue|max_listen_queue|listen_queue_len|idle_processes|active_processes|total_processes|max_active_processes|max_children_reached|slow_requests"
            esac
[root@linux-node1 ~]# chmod +x /server/scripts/zabbix/php-fpm_status.sh
[root@linux-node1 ~]# ls -l /server/scripts/zabbix/php-fpm_status.sh
-rwxr-xr-x 1 root root 2663 Jul 26 10:58 /server/scripts/zabbix/php-fpm_status.sh

[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
278 UnsafeUserParameters=1
263 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/UserParams_Php-FpmStatus.conf
UserParameter=php-fpm.status[*],/bin/bash /server/scripts/zabbix/php-fpm_status.sh "$1"
[root@linux-node1 ~]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd:                               [  OK  ]
Starting zabbix_agentd:                                    [  OK  ]

[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k php-fpm.status[accepted_conn]
179
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k php-fpm.status[start_since]
1696
====================================================================================
zabbix自动发现监控多实例Redis状态
[root@linux-node1 ~]# vim /server/scripts/zabbix/discover_redis.sh
#!/bin/bash
# Name:discover_redis.sh
# Version:V1.0
# Type:Monitor
# Language:Bash Shell
# Date:2016-04-26
# Author:LinBin
# Email:linbin@keywa.com
# Description:Automatically Discover Redis

Redis_Port_Array=(`ps -ef|grep "redis-server"|grep -v "grep"|awk -F":" '{print $NF}'`)
Length_Array=${#Redis_Port_Array[@]}
printf "{\n"
printf  '\t'"\"data\":["
for ((port=0;port<$Length_Array;port++))
do
    printf '\n\t\t{'
    printf "\"{#REDIS_PORT}\":\"${Redis_Port_Array[$port]}\"}"
    if [ $port -lt $[$Length_Array-1] ]
    then
        printf ','
    fi
done
printf  "\n\t]\n"
printf "}\n"
[root@linux-node1 ~]# chmod +x /server/scripts/zabbix/discover_redis.sh
[root@linux-node1 ~]# ls -l /server/scripts/zabbix/discover_redis.sh
-rwxr-xr-x 1 root root 611 Jul 24 17:13 /server/scripts/zabbix/discover_redis.sh
[root@linux-node1 ~]# sh /server/scripts/zabbix/discover_redis.sh
{
        "data":[
                {"{#REDIS_PORT}":"6379"}
        ]
}

[root@linux-node1 ~]# vim /server/scripts/zabbix/redis_status.sh
#!/bin/bash
# Name:redis_status.sh
# Version:V1.0
# Type:Monitor
# Language:Bash Shell
# Date:2016-04-26
# Author:LinBin
# Email:linbin@keywa.com
# Description:Monitor Redis Service Status

# Determine The Number Of Parameters.
if [ $# -ne 2 ]
then
    echo "USAGE:$0 {6379 keys|6378 used_cpu_user}"
    exit 1
fi

# Defined Variables.
Nc="/usr/bin/nc"
Host=$(ifconfig eth0|awk -F"[ :]+" 'NR==2{print $4}')
Password=axbc1kof
Port=$1
Item=$2
Tmp_File="/tmp/redis_$Port.txt"

# Functions To Return Redis Status.
function redis_status() {
         (echo -en "AUTH $Password\r\nINFO\r\n;sleep 1;")|$Nc "$Host" "$Port" > $Tmp_File
         if [ $Item == "keys" ]
         then
             REDIS_STAT_VALUE=$(awk -F"[:=,]" '/db[0-9]+/ {array[$2]+=$3}END{for(key in array) print array[key]}' $Tmp_File)
             echo "$REDIS_STAT_VALUE"
         elif [ $Item == "expires" ]
         then
             REDIS_STAT_VALUE=$(awk -F"[:=,]" '/db[0-9]+/ {array[$4]+=$5}END{for(key in array) print array[key]}' $Tmp_File)
             echo "$REDIS_STAT_VALUE"
         else
             REDIS_STAT_VALUE=$(grep "$Item:" $Tmp_File|awk -F":" '{print $2}')
             echo "$REDIS_STAT_VALUE"
         fi
     }

# Run The Requested Functions.
case $Item in
    uptime_in_seconds)
             redis_status "$Port" "$Item"
             ;;

    uptime_in_days)
             redis_status "$Port" "$Item"
             ;;

    connected_clients)
             redis_status "$Port" "$Item"
             ;;

    blocked_clients)
             redis_status "$Port" "$Item"
             ;;

    used_memory)
             redis_status "$Port" "$Item"
             ;;

    used_memory_peak)
             redis_status "$Port" "$Item"
             ;;

    rdb_changes_since_last_save)
             redis_status "$Port" "$Item"
             ;;

    rdb_last_bgsave_status)
             redis_status "$Port" "$Item"
             ;;

    aof_last_write_status)
             redis_status "$Port" "$Item"
             ;;

    aof_current_size)
             redis_status "$Port" "$Item"
             ;;

    total_connections_received)
             redis_status "$Port" "$Item"
             ;;

    total_commands_processed)
             redis_status "$Port" "$Item"
             ;;

    instantaneous_ops_per_sec)
             redis_status "$Port" "$Item"
             ;;

    rejected_connections)
             redis_status "$Port" "$Item"
             ;;

    expired_keys)
             redis_status "$Port" "$Item"
             ;;

    evicted_keys)
             redis_status "$Port" "$Item"
             ;;

    keyspace_hits)
             redis_status "$Port" "$Item"
             ;;

    keyspace_misses)
             redis_status "$Port" "$Item"
             ;;

    connected_slaves)
             redis_status "$Port" "$Item"
             ;;

    used_cpu_sys)
             redis_status "$Port" "$Item"
             ;;

    used_cpu_user)
             redis_status "$Port" "$Item"
             ;;

    keys)
             redis_status "$Port" "$Item"
             ;;

    expires)
             redis_status "$Port" "$Item"
             ;;

    *)
             echo "USAGE:$0 {6379 keys|6378 used_cpu_user}"
         esac
[root@linux-node1 ~]# chmod +x /server/scripts/zabbix/redis_status.sh
[root@linux-node1 ~]# ls -l /server/scripts/zabbix/redis_status.sh
-rwxr-xr-x 1 root root 2676 Jul 25 13:43 /server/scripts/zabbix/redis_status.sh

[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
278 UnsafeUserParameters=1
263 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/UserParams_RedisStatus.conf
UserParameter=discover.redis,/bin/bash /server/scripts/zabbix/discover_redis.sh
UserParameter=redis.status[*],/bin/bash /server/scripts/zabbix/redis_status.sh "$1" "$2"
[root@linux-node1 ~]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd:                               [  OK  ]
Starting zabbix_agentd:                                    [  OK  ]
====================================================================================
zabbix监控主机存活
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
278 UnsafeUserParameters=1
263 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/UserParams_.conf

[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k redis.status[6379,total_commands_processed]
21
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k redis.status[6379,total_connections_received]
12
====================================================================================
zabbix自动发现TCP端口
[root@linux-node1 ~]# vim /server/scripts/zabbix/discover_port.sh
#!/bin/bash
# Name:discover_port.sh
# Version:V1.0
# Type:Monitor
# Language:Bash Shell
# Date:2016-04-26
# Author:LinBin
# Email:linbin@keywa.com
# Description:Automatically Discover Port

Port_Array=(`netstat -tnlp 2>/dev/null|egrep -i "$1"|awk 'NR>2{print $4}'|awk -F"[:]+" '{print $NF}'|sort|uniq`)
Length_Array=${#Port_Array[@]}
printf "{\n"
printf  '\t'"\"data\":["
for ((port=0;port<$Length_Array;port++))
do
    printf '\n\t\t{'
    printf "\"{#TCP_PORT}\":\"${Port_Array[$port]}\"}"
    if [ $port -lt $[$Length_Array-1] ]
    then
        printf ','
    fi
done
printf  "\n\t]\n"
printf "}\n"
[root@linux-node1 ~]# chmod +x /server/scripts/zabbix/discover_port.sh
[root@linux-node1 ~]# ls -l /server/scripts/zabbix/discover_port.sh
-rwxr-xr-x 1 root root 604 Jul 20 17:20 /server/scripts/zabbix/discover_port.sh

[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
278 UnsafeUserParameters=1
263 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/UserParams_DiscoverPort.conf
UserParameter=tcp.port.listen,/bin/bash /server/scripts/zabbix/discover_port.sh
[root@linux-node1 ~]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd:                               [  OK  ]
Starting zabbix_agentd:                                    [  OK  ]

[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k tcp.port.listen
{
        "data":[
                {"{#TCP_PORT}":"10050"},
                {"{#TCP_PORT}":"10051"},
                {"{#TCP_PORT}":"22"},
                {"{#TCP_PORT}":"3306"},
                {"{#TCP_PORT}":"48836"},
                {"{#TCP_PORT}":"52113"},
                {"{#TCP_PORT}":"9000"}
        ]
}
====================================================================================
zabbix自动发现进程占用内存TOP10
[root@linux-node1 ~]# vim /server/scripts/zabbix/discover_process_top10.sh
#!/bin/bash
# Name:discover_process_top10.sh
# Version:V1.0
# Type:Monitor
# Language:Bash Shell
# Date:2016-04-26
# Author:LinBin
# Email:linbin@keywa.com
# Description:Automatically Discover The Process Uses Resources TOP10

# Defined Variables.
Top="/usr/bin/top"
Tail="/usr/bin/tail"
Tmp_File="/tmp/top10.txt"

if [ -x $Top ]
then
    $Top -b -n 1 > $Tmp_File 2>/dev/null
fi

Process_Array=(`$Tail -n +8 $Tmp_File|awk '{array[$NF]+=$10}END{for(key in array) print array[key],key}'|sort -gr|awk 'NR<11{print $2}'`)
Length_Array=${#Process_Array[@]}
printf "{\n"
printf  '\t'"\"data\":["
for ((process=0;process<$Length_Array;process++))
do
    printf '\n\t\t{'
    printf "\"{#PROCESS_NAME}\":\"${Process_Array[$process]}\"}"
    if [ $process -lt $[$Length_Array-1] ]
    then
        printf ','
    fi
done
printf  "\n\t]\n"
printf "}\n"
[root@linux-node1 ~]# chmod +x /server/scripts/zabbix/discover_process_top10.sh
[root@linux-node1 ~]# ls -l /server/scripts/zabbix/discover_process_top10.sh
-rwxr-xr-x 1 root root 844 Jul 21 15:31 /server/scripts/zabbix/discover_process_top10.sh

[root@linux-node1 ~]# vim /server/scripts/zabbix/process_usage.sh
#!/bin/bash
# Name:process_usage.sh
# Version:V1.0
# Type:Monitor
# Language:Bash Shell
# Date:2016-04-26
# Author:LinBin
# Email:linbin@keywa.com
# Description:Monitor The Process Uses Resources TOP10

# Determine The Number Of Parameters.
if [ $# -ne 2 ]
then
    echo "USAGE:$0 {mysqld cpu|nginx memory}"
    exit 1
fi

# Defined Variables.
Tail="/usr/bin/tail"
Tmp_File="/tmp/top10.txt"
Process_Name=$1
Item=$2

case $Item in
    memory)
           $Tail -n +8 $Tmp_File|grep "\b"$Process_Name"\b"|awk '{array[$NF]+=$10}END{for(key in array) print array[key]}'
           ;;

    cpu)
           $Tail -n +8 $Tmp_File|grep "\b"$Process_Name"\b"|awk '{array[$NF]+=$9}END{for(key in array) print array[key]}'
           ;;

    *)
           echo "USAGE:$0 {mysqld cpu|nginx memory}"
       esac
[root@linux-node1 ~]# chmod +x /server/scripts/zabbix/process_usage.sh
[root@linux-node1 ~]# ls -l /server/scripts/zabbix/process_usage.sh
-rwxr-xr-x 1 root root 819 Jul 24 14:52 /server/scripts/zabbix/process_usage.sh

[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
278 UnsafeUserParameters=1
263 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/UserParams_DiscoverPrecessTOP10.conf
UserParameter=discover.process,/bin/bash /server/scripts/zabbix/discover_process_top10.sh
UserParameter=process.status[*],/bin/bash /server/scripts/zabbix/process_usage.sh "$1" "$2"
[root@linux-node1 ~]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd:                               [  OK  ]
Starting zabbix_agentd:                                    [  OK  ]

[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k process.status[mysqld,cpu]
3.9
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k process.status[mysqld,memory]
52.3
[root@linux-node1 ~]# chown zabbix:zabbix /tmp/top10.txt
[root@linux-node1 ~]# ls -l /tmp/top10.txt
-rw-r--r-- 1 zabbix zabbix 9758 Jul 24 16:05 /tmp/top10.txt
====================================================================================
zabbix插件grafana安装
grafana官方网站:https://grafana.com/
grafana官方文档网站:http://docs.grafana.org/

安装garfana
[root@linux-node1 ~]# wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.4.1-1.x86_64.rpm
[root@linux-node1 ~]# yum -y install initscripts fontconfig urw-fonts
[root@linux-node1 ~]# rpm -ivh grafana-4.4.1-1.x86_64.rpm
warning: grafana-4.4.1-1.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 24098cb6: NOKEY
Preparing...                ########################################### [100%]
   1:grafana                ########################################### [100%]
### NOT starting grafana-server by default on bootup, please execute
 sudo /sbin/chkconfig --add grafana-server
### In order to start grafana-server, execute
 sudo service grafana-server start
POSTTRANS: Running script
[root@linux-node1 ~]# cp -a /etc/grafana/grafana.ini /etc/grafana/grafana.ini_$(date +%F)
[root@linux-node1 ~]# vim /etc/grafana/grafana.ini
16 data = /var/lib/grafana
20 logs = /var/log/grafana
24 plugins = /var/lib/grafana/plugins
30 protocol = http
33 http_addr = 192.168.100.128
36 http_port = 48835
39 domain = localhost
143 admin_user = keywa
146 admin_password = axbc1kof
[root@linux-node1 ~]# /etc/init.d/grafana-server start
Starting Grafana Server: ...                               [  OK  ]
[root@linux-node1 ~]# chkconfig --level 3 grafana-server on
[root@linux-node1 ~]# chkconfig --list grafana-server
grafana-server  0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@linux-node1 ~]# netstat -tnlup|grep "48835"|grep -v "grep"
tcp        0      0 192.168.100.128:48835                     0.0.0.0:*                        LISTEN      12847/grafana-serve 
[root@linux-node1 ~]# ps -ef|grep "grafana-serve"|grep -v "grep"
grafana    9301      1  0 14:34 ?        00:00:00 /usr/sbin/grafana-server --pidfile=/var/run/grafana-server.pid --config=/etc/grafana/grafana.ini cfg:default.paths.data=/var/lib/grafana cfg:default.paths.logs=/var/log/grafana cfg:default.paths.plugins=/var/lib/grafana/plugins
[root@linux-node1 ~]# lsof -i:48835
COMMAND    PID    USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
grafana-s 9301 grafana    9u  IPv4 5514351      0t0  TCP kw_zabbix_server:48835 (LISTEN)

安装garfana-zabbix
garfana-zabbix官方网站:https://github.com/alexanderzobnin/grafana-zabbix
garfana-zabbix官方文档:http://docs.grafana-zabbix.org/installation/
[root@linux-node1 ~]# grafana-cli plugins list-remote
id: abhisant-druid-datasource version: 0.0.4
id: adremsoft-netcrunch-app version: 1.0.0
id: alexanderzobnin-zabbix-app version: 3.5.1
id: ayoungprogrammer-finance-datasource version: 1.0.0
id: belugacdn-app version: 1.2.0
id: bessler-pictureit-panel version: 1.0.0
id: bosun-app version: 0.0.28
id: briangann-datatable-panel version: 0.0.1
id: briangann-gauge-panel version: 0.0.3
id: btplc-alarm-box-panel version: 0.1.1
id: btplc-peak-report-panel version: 0.0.3
id: btplc-status-dot-panel version: 0.0.1
id: btplc-trend-box-panel version: 0.0.3
id: cloudflare-app version: 0.1.2
id: crate-datasource version: 0.5.1
id: dalmatinerdb-datasource version: 1.0.5
id: digiapulssi-breadcrumb-panel version: 1.0.0
id: digiapulssi-organisations-panel version: 1.0.1
id: digrich-bubblechart-panel version: 1.0.0
id: fastweb-openfalcon-datasource version: 1.0.0
id: fetzerch-sunandmoon-datasource version: 0.1.2
id: foursquare-clouderamanager-datasource version: 0.9.2
id: gnocchixyz-gnocchi-datasource version: 1.2.0
id: grafana-clock-panel version: 0.0.9
id: grafana-example-app version: 1.0.1
id: grafana-influxdb-08-datasource version: 1.0.2
id: grafana-kairosdb-datasource version: 2.0.1
id: grafana-piechart-panel version: 1.1.5
id: grafana-simple-json-datasource version: 1.3.3
id: grafana-worldmap-panel version: 0.0.17
id: gridprotectionalliance-openhistorian-datasource version: 1.0.1
id: gridprotectionalliance-osisoftpi-datasource version: 1.0.1
id: hawkular-datasource version: 1.0.8
id: jdbranham-diagram-panel version: 1.4.0
id: kentik-app version: 1.2.4
id: monasca-datasource version: 1.0.0
id: monitoringartist-monitoringart-datasource version: 1.0.0
id: mtanda-google-calendar-datasource version: 1.0.1
id: mtanda-heatmap-epoch-panel version: 0.1.7
id: mtanda-histogram-panel version: 0.1.6
id: natel-discrete-panel version: 0.0.5
id: natel-influx-admin-panel version: 0.0.2
id: natel-plotly-panel version: 0.0.3
id: neocat-cal-heatmap-panel version: 0.0.3
id: novalabs-annotations-panel version: 0.0.1
id: ns1-app version: 0.0.5
id: opennms-datasource version: 2.1.0
id: percona-percona-app version: 1.0.0
id: petrslavotinek-carpetplot-panel version: 0.0.1
id: praj-ams-datasource version: 1.0.1
id: rackerlabs-blueflood-datasource version: 0.0.2
id: radensolutions-netxms-datasource version: 1.1.0
id: raintank-kubernetes-app version: 0.0.7
id: raintank-snap-app version: 0.0.5
id: raintank-worldping-app version: 1.2.3
id: ryantxu-ajax-panel version: 0.0.2
id: satellogic-3d-globe-panel version: 0.1.0
id: savantly-heatmap-panel version: 0.2.0
id: sni-pnp-datasource version: 1.0.1
id: stagemonitor-elasticsearch-app version: 0.26.0
id: udoprog-heroic-datasource version: 0.1.0
id: vertamedia-clickhouse-datasource version: 0.0.2
id: vonage-status-panel version: 1.0.4
id: voxter-app version: 0.0.1

Restart grafana after installing plugins . <service grafana-server restart>
[root@linux-node1 ~]# grafana-cli plugins install alexanderzobnin-zabbix-app
installing alexanderzobnin-zabbix-app @ 3.5.1
from url: https://grafana.com/api/plugins/alexanderzobnin-zabbix-app/versions/3.5.1/download
into: /var/lib/grafana/plugins

✔ Installed alexanderzobnin-zabbix-app successfully 

Restart grafana after installing plugins . <service grafana-server restart>

[root@zabbix-server ~]# grafana-cli plugins install grafana-worldmap-panel
installing grafana-worldmap-panel @ 0.0.17
from url: https://grafana.com/api/plugins/grafana-worldmap-panel/versions/0.0.17/download
into: /var/lib/grafana/plugins

✔ Installed grafana-worldmap-panel successfully 

Restart grafana after installing plugins . <service grafana-server restart>

[root@zabbix-server ~]# grafana-cli plugins install grafana-piechart-panel
installing grafana-piechart-panel @ 1.1.5
from url: https://grafana.com/api/plugins/grafana-piechart-panel/versions/1.1.5/download
into: /var/lib/grafana/plugins

✔ Installed grafana-piechart-panel successfully 

Restart grafana after installing plugins . <service grafana-server restart>
[root@linux-node1 ~]# /etc/init.d/grafana-server restart
Stopping Grafana Server: ...                               [  OK  ]
Starting Grafana Server: ...                               [  OK  ]

query匹配原则
*                    returns all groups
*.*                  returns all hosts (from all groups)
Servers.*            returns all hosts in group Servers
Servers.*.*          returns all applications in group Servers
Servers.*.*.*        returns all items from hosts in group Servers



====================================================================================
zabbix监控MySQL状态
[root@linux-node1 ~]# rpm -ivh percona-zabbix-templates-1.1.7-2.noarch.rpm
warning: percona-zabbix-templates-1.1.7-2.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
Preparing...                ########################################### [100%]
   1:percona-zabbix-template########################################### [100%]

Scripts are installed to /var/lib/zabbix/percona/scripts
Templates are installed to /var/lib/zabbix/percona/templates
[root@linux-node1 ~]# ls -l /var/lib/zabbix/percona/scripts
total 64
-rwxr-xr-x 1 root root  1251 Dec 10  2016 get_mysql_stats_wrapper.sh
-rwxr-xr-x 1 root root 59976 Dec 10  2016 ss_get_mysql_stats.php
[root@linux-node1 ~]# ls -l /var/lib/zabbix/percona/templates
total 284
-rw-r--r-- 1 root root  18866 Dec 10  2016 userparameter_percona_mysql.conf
-rw-r--r-- 1 root root 269258 Dec 10  2016 zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml
[root@linux-node1 ~]# rpm -ql percona-zabbix-templates
/var/lib/zabbix/percona
/var/lib/zabbix/percona/scripts
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
/var/lib/zabbix/percona/templates
/var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf
/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml
[root@linux-node1 ~]# cp -a /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d/UserParams_PerconaMySQL.conf
[root@linux-node1 ~]# vim /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
14 CMD="/usr/local/php/bin/php -q $DIR/ss_get_mysql_stats.php --host $HOST --items gg"
[root@linux-node1 ~]# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
30 $mysql_user = 'root';
31 $mysql_pass = 'axbc1kof';
32 $mysql_port = 3306;
33 $mysql_socket = NULL;
34 $mysql_flags = 0;
[root@linux-node1 ~]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd:                               [  OK  ]
Starting zabbix_agentd:                                    [  OK  ]
[root@linux-node1 ~]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gm
0
[root@linux-node1 ~]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gw
26076
====================================================================================
zabbix监控系统平均负载
[root@linux-node1 ~]# vim /server/scripts/zabbix/loadavg.sh
#!/bin/bash
# Name:loadavg.sh
# Version:V1.0
# Type:Monitor
# Language:Bash Shell
# Date:2016-04-26
# Author:LinBin
# Email:linbin@keywa.com
# Description:Monitor System Average Load

# Determine The Number Of Parameters.
if [ $# -ne 1 ]
then
    echo "USAGE:$0 {1|5|15}"
    exit 1
fi

# Defined Variables.
File="/proc/loadavg"
Command=$1

case $Command in
    1)
      cat $File|awk '{print $1}'
      ;;

    5)
      cat $File|awk '{print $2}'
      ;;

    15)
      cat $File|awk '{print $3}'
      ;;

    *)
      echo "USAGE:$0 {1|5|15}"
  esac
[root@linux-node1 ~]# chmod +x /server/scripts/zabbix/loadavg.sh
[root@linux-node1 ~]# ls -l /server/scripts/zabbix/loadavg.sh
-rwxr-xr-x 1 root root 570 Jul 22 13:39 /server/scripts/zabbix/loadavg.sh

[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
278 UnsafeUserParameters=1
263 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/UserParams_Loadavg.conf
UserParameter=load.average[*],/bin/bash /server/scripts/zabbix/loadavg.sh "$1"
[root@linux-node1 ~]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd:                               [  OK  ]
Starting zabbix_agentd:                                    [  OK  ]

[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k load.average[1]
0.74
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k load.average[5]
3.32
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k load.average[15]
2.30
====================================================================================
zabbix监控磁盘I/O状态
[root@linux-node1 ~]# vim /server/scripts/zabbix/discover_disk.sh
#!/bin/bash
# Name:discover_disk.sh
# Version:V1.0
# Type:Monitor
# Language:Bash Shell
# Date:2016-04-26
# Author:LinBin
# Email:linbin@keywa.com
# Description:Automatically Discover Disks

File="/proc/diskstats"
Disk_Array=(`cat $File|egrep "\bsd[a-z]|\bvd[a-z]|\bxvd[a-z]"|awk '{print $3}'`)
Length_Array=${#Disk_Array[@]}
printf "{\n"
printf  '\t'"\"data\":["
for ((disk=0;disk<$Length_Array;disk++))
do
    printf '\n\t\t{'
    printf "\"{#DISK_NAME}\":\"${Disk_Array[$disk]}\"}"
    if [ $disk -lt $[$Length_Array-1] ]
    then
        printf ','
    fi
done
printf  "\n\t]\n"
printf "}\n"
[root@linux-node1 ~]# chmod +x /server/scripts/zabbix/discover_disk.sh
[root@linux-node1 ~]# ls -l /server/scripts/zabbix/discover_disk.sh
-rwxr-xr-x 1 root root 612 Jul 22 15:59 /server/scripts/zabbix/discover_disk.sh

[root@linux-node1 ~]# /server/scripts/zabbix/discover_disk.sh
{
        "data":[
                {"{#DISK_NAME}":"sda"},
                {"{#DISK_NAME}":"sda1"},
                {"{#DISK_NAME}":"sda2"},
                {"{#DISK_NAME}":"sda3"}
        ]
}

[root@linux-node1 ~]# vim /server/scripts/zabbix/disk_status.sh
#!/bin/bash
# Name:disk_status.sh
# Version:V1.0
# Type:Monitor
# Language:Bash Shell
# Date:2016-04-26
# Author:LinBin
# Email:linbin@keywa.com
# Description:Monitor Disk I/0 Status

# Determine The Number Of Parameters.
if [ $# -ne 2 ]
then
    echo "USAGE:$0 {sda1 read/s|sda1 wrtn/s}"
    exit 1
fi

# Defined Variables.
Iostat="/usr/bin/iostat"
Disk=$1
Command=$2

case $Command in
    tps)
        $Iostat -p -k|grep "\b$1\b"|awk '{print $2}'
        ;;

    read/s)
        $Iostat -p -k|grep "\b$1\b"|awk '{print $3}'
        ;;

    wrtn/s)
        $Iostat -p -k|grep "\b$1\b"|awk '{print $4}'
        ;;

    read)
        $Iostat -p -k|grep "\b$1\b"|awk '{print $5}'
        ;;

    wrtn)
        $Iostat -p -k|grep "\b$1\b"|awk '{print $6}'
        ;;

    *)
        echo "USAGE:$0 {sda1 read/s|sda1 wrtn/s}"
    esac
[root@linux-node1 ~]# chmod +x /server/scripts/zabbix/disk_status.sh
[root@linux-node1 ~]# ls -l /server/scripts/zabbix/disk_status.sh
-rwxr-xr-x 1 root root 843 Jul 22 16:57 /server/scripts/zabbix/disk_status.sh

[root@linux-node1 ~]# /server/scripts/zabbix/disk_status.sh sda3 read/s
22.75
[root@linux-node1 ~]# /server/scripts/zabbix/disk_status.sh sda3 wrtn/s
122.60

[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
278 UnsafeUserParameters=1
263 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/UserParams_DiskIO.conf
UserParameter=discovery.disk,/bin/bash /server/scripts/zabbix/discover_disk.sh
UserParameter=disk.status[*],/bin/bash /server/scripts/zabbix/disk_status.sh "$1" "$2"
[root@linux-node1 ~]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd:                               [  OK  ]
Starting zabbix_agentd:                                    [  OK  ]

[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k disk.status[sda3,read/s]
22.75
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k disk.status[sda3,wrtn/s]
122.60
====================================================================================
zabbix监控文件系统状态
[root@linux-node1 ~]# vim /server/scripts/zabbix/discover_file_system.sh
#!/bin/bash
# Name:discover_file_system.sh
# Version:V1.0
# Type:Monitor
# Language:Bash Shell
# Date:2016-04-26
# Author:LinBin
# Email:linbin@keywa.com
# Description:Automatically File System

File="/proc/mounts"
File_System_Array=(`cat $File|awk '/^\/dev/ {print $2}'`)
Length_Array=${#File_System_Array[@]}
printf "{\n"
printf  '\t'"\"data\":["
for ((file_system=0;file_system<$Length_Array;file_system++))
do
    printf '\n\t\t{'
    printf "\"{#FILE_SYSTEM_NAME}\":\"${File_System_Array[$file_system]}\"}"
    if [ $file_system -lt $[$Length_Array-1] ]
    then
        printf ','
    fi
done
printf  "\n\t]\n"
printf "}\n"
[root@linux-node1 ~]# chmod +x /server/scripts/zabbix/discover_file_system.sh
[root@linux-node1 ~]# ls -l /server/scripts/zabbix/discover_file_system.sh
-rwxr-xr-x 1 root root 646 Jul 24 09:04 /server/scripts/zabbix/discover_file_system.sh

[root@linux-node1 ~]# /server/scripts/zabbix/discover_file_system.sh
{
        "data":[
                {"{#FILE_SYSTEM_NAME}":"/"},
                {"{#FILE_SYSTEM_NAME}":"/boot"}
        ]
}

[root@linux-node1 ~]# vim /server/scripts/zabbix/file_system_status.sh
#!/bin/bash
# Name:file_system_status.sh
# Version:V1.0
# Type:Monitor
# Language:Bash Shell
# Date:2016-04-26
# Author:LinBin
# Email:linbin@keywa.com
# Description:Monitor File System Usage Status

# Determine The Number Of Parameters.
 if [ $# -ne 2 ]
 then
     echo "USAGE:$0 {/ total|/boot used}"
     exit 1
 fi

# Defined Variables.
DF="/bin/df"
File_System=$1
Command=$2

case $Command in
    total)
          $DF -hm|grep "$1$"|awk '{print $2}'
          ;;

    used)
          $DF -hm|grep "$1$"|awk '{print $3}'
          ;;

    usage)
          $DF -hm|grep "$1$"|awk '{printf "%.0f\n",$3/$2*100}'
          ;;

    *)
          echo "USAGE:$0 {/ total|/boot used}"
      esac
[root@linux-node1 ~]# chmod +x /server/scripts/zabbix/file_system_status.sh
[root@linux-node1 ~]# ls -l /server/scripts/zabbix/file_system_status.sh
-rwxr-xr-x 1 root root 581 Jul 24 10:17 /server/scripts/zabbix/file_system_status.sh

[root@linux-node1 ~]# /server/scripts/zabbix/file_system_status.sh / used
6569
[root@linux-node1 ~]# /server/scripts/zabbix/file_system_status.sh / total
14105
[root@linux-node1 ~]# /server/scripts/zabbix/file_system_status.sh / usage
47

[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
278 UnsafeUserParameters=1
263 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
[root@linux-node1 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/UserParams_DiskUsage.conf
UserParameter=discovery.filesystem,/bin/bash /server/scripts/zabbix/discover_file_system.sh
UserParameter=filesystem.status[*],/bin/bash /server/scripts/zabbix/file_system_status.sh "$1" "$2"
[root@linux-node1 ~]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd:                               [  OK  ]
Starting zabbix_agentd:                                    [  OK  ]

[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k filesystem.status[/,total]
14105
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k filesystem.status[/,used] 
6570
[root@linux-node1 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.100.128 -k filesystem.status[/,usage]
47
====================================================================================
zabbix监控DELL服务器
[root@linux-node1 ~]# yum -y install net-snmp net-snmp-utils
[root@linux-node1 ~]# snmpget -v 2c -c keywa 192.168.0.30 .1.3.6.1.4.1.674.10892.2.1.1.2.0
SNMPv2-SMI::enterprises.674.10892.2.1.1.2.0 = STRING: "iDRAC8"
[root@linux-node1 ~]# snmpwalk -v 2c -c keywa 192.168.0.30 .1.3.6.1.4.1.674.10892.2.1.1.2.0
SNMPv2-SMI::enterprises.674.10892.2.1.1.2.0 = STRING: "iDRAC8"
====================================================================================


作者头像
南宫俊逸创始人

君子好学,自强不息~

上一篇:linux 运维工程师必备技能
下一篇:CentOS 7 Redis-3.2.8 安装配置

相关推荐

4

发表评论

阿里云2021年 618 年中钜惠活动