企業級Zabbix應用監控實踐

Zabbix監控TCP

Tcp的連接狀態對於我們web服務器來說是至關重要的,尤其是併發量ESTAB;或者是syn_recv值,假如這個值比較大的話我們可以認爲是不是受到了攻擊,或是是time_wait值比較高的話,我們要考慮看我們內核是否需要調優,太高的time_wait值的話會佔用太多端口,要是端口少的話後果不堪設想:所以今天我們來學學如何使用Zabbix監控tcp狀態

1.編寫Shell腳本

[root@linux-node1 ~]# cd /etc/zabbix/scripts
[root@linux-node1 scripts]# vim tcp_status.sh
#!/bin/bash
############################################################
# $Name:         tcp_status.sh
# $Version:      v1.0
# $Function:     TCP Status
# $Author:       xuliangwei
# $organization: www.xuliangwei.com
# $Create Date:  2016-06-23
# $Description:  Monitor TCP Service Status
############################################################
[ $# -ne 1 ] && echo "Usage:CLOSE-WAIT|CLOSED|CLOSING|ESTAB|FIN-WAIT-1|FIN-WAIT-2|LAST-ACK|LISTEN|SYN-RECV SYN-SENT|TIME-WAIT" && exit 1
tcp_status_fun(){
    TCP_STAT=$1
    ss -ant | awk 'NR>1 {++s[$1]} END {for(k in s) print k,s[k]}' > /tmp/ss.txt
    TCP_STAT_VALUE=$(grep "$TCP_STAT" /tmp/ss.txt | cut -d ' ' -f2)
    if [ -z "$TCP_STAT_VALUE" ];then
        TCP_STAT_VALUE=0
    fi
    echo $TCP_STAT_VALUE
}
tcp_status_fun $1;

添加執行權限

[root@linux-node1 scripts]# chmod +x tcp_status.sh 

2.監控項linux_tcp.conf的配置文件如下:

[root@linux-node1 ~]# cat /etc/zabbix/zabbix_agentd.d/tcp.conf
UserParameter=tcp_status[*],/bin/bash /etc/zabbix/scripts/tcp_status.sh "$1"

3.重啓zabbix-agent修改配置文件必須重啓

[root@linux-node1 ~]# systemctl restart  zabbix-agent

4.Server測試Agent是否能獲取到值,通過Zabbix_get(不要直接執行腳本)

[root@linux-node1 scripts]# zabbix_get -s 192.168.90.11 -k tcp_status[ESTAB]
8

5.添加所有監控項(記得將模板關聯主機)

6.查看圖形(圖形是自定義創建)

Zabbix監控Nginx

實驗環境

服務器系統

角色

IP

CentOS 7.4 x86_64

Zabbix-Server

192.168.90.10

CentOS 7.4 x86_64

Zabbix-Agent

192.168.90.11

2.在nginx.confServer標籤下添加如下內容

location /nginx_status {
    stub_status on;
    access_log  off;
    allow 127.0.0.1;
    deny all;
    }

3.本地訪問Nginx Status

[root@linux-node1 ~]# curl http://127.0.0.1/nginx_status
Active connections: 1
server accepts handled requests
 1 1 1
Reading: 0 Writing: 1 Waiting: 0

Nginx狀態解釋:
Active connections  Nginx正處理的活動鏈接數1個
server              Nginx啓動到現在共處理了1個連接。
accepts             Nginx啓動到現在共成功創建1次握手。 
handled requests    Nginx總共處理了1次請求。
Reading             Nginx讀取到客戶端的 Header 信息數。
Writing             Nginx返回給客戶端的 Header 信息數。
Waiting             Nginx已經處理完正在等候下一次請求指令的駐留鏈接,開啓。

Keep-alive的情況下,這個值等於active-(reading + writing)。
請求丟失數=(握手數-連接數)可以看出,本次狀態顯示沒有丟失請求。

4.編寫Nginx的Shell腳本(如果端口不一致,只需要修改腳本端口即可)

[root@Agent ~]# mkdir -p /etc/zabbix/scripts
[root@linux-node1 scripts]# vim /etc/zabbix/scripts/nginx_status.sh
#!/bin/bash
############################################################
# $Name:         nginx_status.sh
# $Version:      v1.0
# $Function:     Nginx Status
# $Author:       xuliangwei
# $organization: www.xuliangwei.com,www,bjstack.com
# $Create Date:  2016-06-23
# $Description:  Monitor Nginx Service Status
############################################################

NGINX_PORT=80  #如果端口不同僅需要修改腳本即可,否則修改xml很麻煩
NGINX_COMMAND=$1


nginx_active(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Active/ {print $NF}'
}

nginx_reading(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Reading/ {print $2}'
}

nginx_writing(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Writing/ {print $4}'
       }

nginx_waiting(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Waiting/ {print $6}'
       }

nginx_accepts(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $1}'
       }

nginx_handled(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $2}'
       }

nginx_requests(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $3}'
       }


  case $NGINX_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

5.給腳本添加執行權限

[root@Agent]# chmod +x /etc/zabbix/scripts/nginx_status.sh

6.監控項nginx_status.conf的配置文件如下:

[root@Agent ~]# cat /etc/zabbix/zabbix_agentd.d/nginx_status.conf
UserParameter=nginx_status[*],/bin/bash /etc/zabbix/zabbix_agentd.d/scripts/nginx/nginx_status.sh "$1"

6.重啓zabbix-agent

[root@Agent ~]# systemctl restart  zabbix-agent

7.使用Zabbix_get來獲取值

[root@linux-node1 ~]# zabbix_get -s 192.168.90.11 -k nginx_status[writing]
1

8.添加所有監控項, 如圖4-3, 記得關聯到指定的主機

Zabbix監控PHP-FPM

實踐環境

服務器系統

角色

IP

CentOS 7.4 x86_64

Zabbix-Server

192.168.90.10

CentOS 7.4 x86_64

Zabbix-Agent

192.168.90.11

1.PHP-FPM工作模式通常與Nginx結合使用,修改php-fpm.conf

[root@Agent ~]# vim /etc/php-fpm.d/www.conf
pm.status_path = /phpfpm_status

2.修改nginx.conf的配置文件,增加如下location訪問PHP-FPM狀態信息。

   location ~ ^/(phpfpm_status)$ {
        include fastcgi_params;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

3.訪問測試phpfpm_status

[root@Agent ~]# curl http://127.0.0.1/phpfpm_status
pool:                 www
process manager:      dynamic
start time:           05/Jul/2016:15:30:56 +0800
start since:          409
accepted conn:        22
listen queue:         0
max listen queue:     0
listen queue len:     128
idle processes:       4
active processes:     1
total processes:      5
max active processes: 2
max children reached: 0

#PHP-FPM狀態解釋:
pool #fpm池名稱,大多數爲www
process manager #進程管理方式dynamic或者static
start time #啓動日誌,如果reload了fpm,時間會更新
start since #運行時間
accepted conn #當前池接受的請求數
listen queue #請求等待隊列,如果這個值不爲0,那麼需要增加FPM的進程數量
max listen queue #請求等待隊列最高的數量
listen queue len #socket等待隊列長度
idle processes #空閒進程數量
active processes #活躍進程數量
total processes #總進程數量
max active processes #最大的活躍進程數量(FPM啓動開始計算)
max children reached #程最大數量限制的次數,如果這個數量不爲0,那說明你的最大進程數量過小,可以適當調整。

4.編寫php-fpmShell腳本(如果端口不一致,只需要修改腳本端口即可)

[root@Agent ~]# cd /etc/zabbix/scripts
[root@Agent scripts]# vim phpfpm_status.sh
#!/bin/bash
############################################################
# $Name:         phpfpm_status.sh
# $Version:      v1.0
# $Function:     Nginx Status
# $Author:       xuliangwei
# $organization: www.xuliangwei.com
# $Create Date:  2016-06-23
# $Description:  Monitor Nginx Service Status
############################################################

PHPFPM_COMMAND=$1
PHPFPM_PORT=80  #根據監聽不同端口進行調整

start_since(){
    /usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^start since:/ {print $NF}'
}

accepted_conn(){
    /usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^accepted conn:/ {print $NF}'
}

listen_queue(){
    /usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^listen queue:/ {print $NF}'
}

max_listen_queue(){
    /usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^max listen queue:/ {print $NF}'
}

listen_queue_len(){
    /usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^listen queue len:/ {print $NF}'
}

idle_processes(){
    /usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^idle processes:/ {print $NF}'
}

active_processes(){
    /usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^active processes:/ {print $NF}'
}

total_processes(){
    /usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^total processes:/ {print $NF}'
}

max_active_processes(){
    /usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^max active processes:/ {print $NF}'
}

max_children_reached(){
    /usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^max children reached:/ {print $NF}'
}

slow_requests(){
    /usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^slow requests:/ {print $NF}'
}

case $PHPFPM_COMMAND 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}"
    esac

5.給腳本添加執行權限

[root@Agent scripts]# chmod +x phpfpm_status.sh

6.監控項的phpfpm_status.conf配置文件如下:

[root@Agent ~]# cat /etc/zabbix/zabbix_agentd.d/phpfpm_status.conf
UserParameter=phpfpm_status[*],/bin/bash /etc/zabbix/scripts/phpfpm_status.sh "$1"

6.重啓zabbix-agent

[root@Agent ~]# systemctl restart  zabbix-agent

7.Server使用zabbix_get命令來獲取Agent端的值

[root@linux-node1 zabbix_agentd.d]# zabbix_get -s 192.168.90.11 -k phpfpm_status[accepted_conn]
45

8.添加所有監控項, 如下圖4-5, 最後記得關聯至對應主機

9.查看圖形,如圖4-4(圖形自定義)

Zabbix監控Tomcat

在Zabbix中,JMX監控數據的獲取由專門的代理程序來實現,即Zabbix-Java-Gateway來負責數據的採集,Zabbix-Java-Gateway和JMX的Java程序之間通信獲取數據

JMX在Zabbix中的運行流程:

1.Zabbix-Server找Zabbix-Java-Gateway獲取Java數據
2.Zabbix-Java-Gateway找Java程序(zabbix-agent)獲取數據
3.Java程序返回數據給Zabbix-Java-Gateway
4.Zabbix-Java-Gateway返回數據給Zabbix-Server
5.Zabbix-Server進行數據展示

配置JMX監控的步驟:

1.安裝Zabbix-Java-Gateway。
2.配置zabbix_java_gateway.conf參數。
3.配置zabbix-server.conf參數。
4.Tomcat應用開啓JMX協議。
5.ZabbixWeb配置JMX監控的Java應用。

實踐環境

服務器系統

角色

IP

CentOS 7.4 x86_64

Zabbix-Server

192.168.56.11

CentOS 7.4 x86_64

Zabbix-java-gateway

192.168.56.12

CentOS 7.4 x86_64

Zabbix-Agent

192.168.56.13

1.安裝java以及zabbix-java-gateway (如果源碼安裝加上--enable-java參數)

//安裝java-gateway
[root@linux-node1 ~]# yum install  zabbix-java-gateway java-1.8.0-openjdk -y

2.配置zabbix-java-gateway

vim /etc/zabbix/zabbix_java_gateway.conf

3.啓動zabbix-java-gateway

[root@linux-node1 ~]# systemctl start zabbix-java-gateway
[root@linux-node1 ~]# netstat -lntup|grep 10052
tcp6       0      0 :::10052                :::*                    LISTEN      13042/java

4.修改zabbix-server 配置文件

[root@linux-node1 ~]# vim /etc/zabbix/zabbix_server.conf
#java gateway地址
JavaGateway=192.168.90.11  
#java gateway默認端口10052
JavaGatewayPort=10052
#啓動進程輪詢java gateway
StartJavaPollers=5

5.重啓zabbix-server

[root@linux-node1 ~]# systemctl restart zabbix-server

6.安裝tomcat服務

mkdir /soft/package/src -p
wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.2/bin/apache-tomcat-9.0.2.tar.gz
tar xf apache-tomcat-9.0.2.tar.gz -C /soft/
ln -s /soft/apache-tomcat-9.0.2/ /soft/tomcat

7.開啓tomcat的遠程jvm配置文件

[root@linux-node1 ~]# vim /usr/local/tomcat/bin/catalina.sh
CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.90.11"


#jvm配置文件解釋
CATALINA_OPTS="$CATALINA_OPTS
//啓用遠程監控JMX
-Dcom.sun.management.jmxremote
//jmx啓用遠程端口,Zabbix添加時必須一致
-Dcom.sun.management.jmxremote.port=12345
//不開啓用戶密碼認證
-Dcom.sun.management.jmxremote.authenticate=false
//不啓用ssl加密傳輸
-Dcom.sun.management.jmxremote.ssl=false
//運行tomcat主機的IP地址
-Djava.rmi.server.hostname=192.168.90.11"

7.重啓tomcat服務

[root@linux-node1 ~]# /usr/local/tomcat/bin/shutdown.sh
[root@linux-node1 ~]# /usr/local/tomcat/bin/startup.sh

8.zabbix添加tomcat主機,並添加Zabbix自帶java監控模板,如圖4-10、圖4-11、圖4-12

圖4-10

圖4-11

圖4-129.查看圖形,如圖4-13

圖4-13

10.自帶的監控可能無法滿足企業需求,大家可以根據公司的業務定製不同的JVM監控模板。

Zabbix監控MySQL

percona Monitoring Plugins是一個高質量的組件,爲MySQL數據庫添加企業級的監控和圖表功能。但其腳本使用PHP實現,故而Zabbix-Agent需要安裝PHP環境。

percona工具集

實踐環境

服務器系統

角色

IP

CentOS 7.4 x86_64

Zabbix-Server

192.168.90.10

CentOS 7.4 x86_64

Zabbix-Agent

192.168.90.11

1.在Zabbix-Agent端安裝percona Monitoring Plugins

[root@Agent ~]# yum install -y http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
[root@Agent ~]# yum install percona-zabbix-templates -y

2.查看percona安裝後的目錄結構

[root@Agent percona]# tree /var/lib/zabbix/percona
/var/lib/zabbix/percona
├── scripts  #腳本文件路徑
│   ├── get_mysql_stats_wrapper.sh
│   └── ss_get_mysql_stats.php
└── templates
    ├── userparameter_percona_mysql.conf  #key文件位置
    └── zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.6.xml #模板文件位置

4.將自定義監控項配置文件複製至/etc/zabbix_agentd.conf.d目錄下

[root@Agent ~]# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf  /etc/zabbix/zabbix_agentd.d/percona_mysql.conf

5.重啓zabbix-agent

[root@Agent ~]# systemctl restart zabbix-agent

6.修改腳本中的MySQL用戶名和密碼

[root@Agent scripts]# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'root';
$mysql_pass = 'xuliangwei.com';
$mysql_port = 3306;

7.在Zabbix-Server端上使用Zabbix_get獲取值(否則會失敗)

[root@Server ~]# zabbix_get -s 192.168.90.11 -k MySQL.pool-read-requests
223003813

//如果獲取不到值常見問題
1.看是否是MySQL密碼錯誤
2.不要直接執行腳本來獲取
3.刪除/tmp/localhost-mysql_cacti_stats.txt文件
4.權限問題導致

8.在Zabbix頁面模板選項中導入Percona模板, 模板存放在/var/lib/zabbix/percona/templates, 最後關聯主機即可。

Zabbix監控Redis

Redis使用自帶的INFO命令,進行狀態監控。以一種易於解釋且易於閱讀的格式,返回關於Redis服務器的各種信息和統計數值。

實踐環境

服務器系統

角色

IP

CentOS 7.4 x86_64

Zabbix-Server

192.168.90.10

CentOS 7.4 x86_64

Zabbix-Agent

192.168.90.11

1.編寫Shell腳本

  • 腳本端口、連接redis服務地址根據具體情況進行修改
  • AUTH認證沒有開啓,將PASSWD修改爲空即可。
[root@Agent ~]# mkdir -p  /etc/zabbix/scripts
[root@Agent ~]# vim /etc/zabbix/scripts/redis_status.sh
#!/bin/bash
############################################################
# $Name:         redis_status.sh
# $Version:      v1.0
# $Function:     Redis Status
# $Author:       xuliangwei
# $organization: www.xuliangwei.com
# $Create Date:  2016-06-23
# $Description:  Monitor Redis Service Status
############################################################

R_COMMAND="$1"
R_PORT="6379"  #根據實際情況調整端口
R_SERVER="127.0.0.1"  #根據具體情況調整IP地址
PASSWD=""    #如果沒有設置Redis密碼,爲空即可


redis_status(){
   (echo -en "AUTH $PASSWD\r\nINFO\r\n";sleep 1;) | /usr/bin/nc "$R_SERVER" "$R_PORT" > /tmp/redis_"$R_PORT".tmp
      REDIS_STAT_VALUE=$(grep "$R_COMMAND:" /tmp/redis_"$R_PORT".tmp | cut -d ':' -f2)
       echo "$REDIS_STAT_VALUE"
}

case $R_COMMAND in
    used_cpu_user_children)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    used_cpu_sys)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    total_commands_processed)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    role)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    lru_clock)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    latest_fork_usec)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    keyspace_misses)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    keyspace_hits)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    keys)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    expires)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    expired_keys)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    evicted_keys)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    connected_clients)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    changes_since_last_save)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    blocked_clients)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    bgsave_in_progress)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    bgrewriteaof_in_progress)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    used_memory_peak)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    used_memory)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    used_cpu_user)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    used_cpu_sys_children)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    total_connections_received)
    redis_status "$R_PORT" "$R_COMMAND"
    ;;
    *)
    echo $"USAGE:$0 {used_cpu_user_children|used_cpu_sys|total_commands_processed|role|lru_clock|latest_fork_usec|keyspace_misses|keyspace_hits|keys|expires|expired_keys|connected_clients|changes_since_last_save|blocked_clients|bgrewriteaof_in_progress|used_memory_peak|used_memory|used_cpu_user|used_cpu_sys_children|total_connections_received}"
    esac

Redis狀態參數解釋:

server : Redis 服務器信息,包含以下域:
redis_version : Redis 服務器版本
redis_git_sha1 : Git SHA1
redis_git_dirty : Git dirty flag
os : Redis 服務器的宿主操作系統
arch_bits : 架構(32 或 64 位)
multiplexing_api : Redis 所使用的事件處理機制
gcc_version : 編譯 Redis 時所使用的 GCC 版本
process_id : 服務器進程的 PID
run_id : Redis 服務器的隨機標識符(用於 Sentinel 和集羣)
tcp_port : TCP/IP 監聽端口
uptime_in_seconds : 自 Redis 服務器啓動以來,經過的秒數
uptime_in_days : 自 Redis 服務器啓動以來,經過的天數
lru_clock : 以分鐘爲單位進行自增的時鐘,用於 LRU 管理
clients : 已連接客戶端信息,包含以下域:
connected_clients : 已連接客戶端的數量(不包括通過從屬服務器連接的客戶端)
client_longest_output_list : 當前連接的客戶端當中,最長的輸出列表
client_longest_input_buf : 當前連接的客戶端當中,最大輸入緩存
blocked_clients : 正在等待阻塞命令(BLPOP、BRPOP、BRPOPLPUSH)的客戶端的數量
memory : 內存信息,包含以下域:
used_memory : 由 Redis 分配器分配的內存總量,以字節(byte)爲單位
used_memory_human : 以人類可讀的格式返回 Redis 分配的內存總量
used_memory_rss : 從操作系統的角度,返回 Redis 已分配的內存總量(俗稱常駐集大小)。這個值和 top 、 ps 等命令的輸出一致。
used_memory_peak : Redis 的內存消耗峯值(以字節爲單位)
used_memory_peak_human : 以人類可讀的格式返回 Redis 的內存消耗峯值
used_memory_lua : Lua 引擎所使用的內存大小(以字節爲單位)
mem_fragmentation_ratio : used_memory_rss 和 used_memory 之間的比率
persistence : RDB 和 AOF 的相關信息
stats : 一般統計信息
replication : 主/從複製信息
cpu : CPU 計算量統計信息
commandstats : Redis 命令統計信息
cluster : Redis 集羣信息
keyspace : 數據庫相關的統計信息
參數還可以是下面這兩個:
all : 返回所有信息
default : 返回默認選擇的信息
當不帶參數直接調用 INFO 命令時,使用 default 作爲默認參數。

3.添加腳本執行權限

[root@Agent ~]# chmod +x /etc/zabbix/scripts/redis_status.sh

4.Zabbix權限不足處理辦法

[root@Agent ~]# rm -f /tmp/redis_6379.tmp

5.key的redis_status.conf的配置文件如下:

[root@Agent ~]# cat /etc/zabbix/zabbix_agentd.d/redis_status.conf
UserParameter=redis_status[*],/bin/bash /etc/zabbix/scripts/redis_status.sh "$1" 

6.重啓zabbix-agent

[root@Agent ~]# systemctl restart  zabbix-agent

7.在Zabbix-Server使用Zabbix_get獲取值

[root@Server ~]# zabbix_get -s 192.168.90.11 -k redis_status[used_cpu_sys]
16.81

8.展示所有Key(記得將模板關聯主機)如圖4-14

圖4-14

9.查看圖形,如圖4-15、圖4-16(圖形自定義)

圖4-15

圖4-16

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章