<meta charset="utf-8">
第一章 監(jiān)控知識基本概述
1.為什么要使用監(jiān)控
1.對系統(tǒng)不間斷實時監(jiān)控
2.實時反饋系統(tǒng)當前狀態(tài)
3.保證服務可靠性安全性
4.保證業(yè)務持續(xù)穩(wěn)定運行
2.如何進行監(jiān)控,比如我們需要監(jiān)控磁盤的使用率
1.如何查看磁盤使用率 df -h
2.監(jiān)控磁盤的那些指標 block、 inode
3.如何獲取具體的信息 df -h|awk '//[圖片上傳失敗...(image-dc5411-1612709464520)]
(NF-1)}'
4.獲取的數(shù)值到達多少報警 80%
3.流行的監(jiān)控工具
1.Zabbix
2.Lepus(天兔)數(shù)據(jù)庫監(jiān)控系統(tǒng)
3.Open-Falcon 小米
4.Prometheus(普羅米修斯, Docker、 K8s)
4.如果去到一家新公司,如何入手監(jiān)控
1.硬件監(jiān)控 路由器、交換機、防火墻
2.系統(tǒng)監(jiān)控 CPU、內存、磁盤、網絡、進程、 TCP
3.服務監(jiān)控 nginx、 php、 tomcat、 redis、 memcache、 mysql
4.WEB 監(jiān)控 請求時間、響應時間、加載時間、
5.日志監(jiān)控 ELk(收集、存儲、分析、展示) 日志易
6.安全監(jiān)控 Firewalld、 WAF(Nginx+lua)、安全寶、牛盾云、安全狗
7.網絡監(jiān)控 smokeping 多機房
8.業(yè)務監(jiān)控 活動引入多少流量、產生多少注冊量、帶來多大價值
第二章 單機時代如何監(jiān)控
CPU 監(jiān)控命令: w、 top、 htop、 glances
%Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
us 用戶態(tài): 跟用戶的操作有關 35%
sy 系統(tǒng)態(tài): 跟內核的處理有關 60%
id CPU 空閑:
內存監(jiān)控命令: free
[root@m01 ~]# free -h
total used free shared buff/cache available
Mem: 977M 105M 724M 6.6M 148M 729M
Swap: 1.0G 0B 1.0G
磁盤監(jiān)控命令: df、 iotop
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.80 25.32 33.36 221034 291193
設備名 每秒傳輸次數(shù) 每秒讀大小 每秒寫大小 讀的總大小 寫的總大小
網絡監(jiān)控命令: ifconfig、 route、 glances、 iftop、 nethogs、 netstat
單位換算
Mbps 100Mbps/8
MB 12MB
iftop 中間的<= =>這兩個左右箭頭,表示的是流量的方向。
TX:發(fā)送流量、 RX:接收流量、 TOTAL:總流量
#查看 TCP11 中狀態(tài)
netstat -an|grep ESTABLISHED
netstat -rn # 查看路由信息
netstat -lntup
2.隨著時間的推移,用戶不斷的增多,服務隨時可能扛不住會被 oom(out of memory),當系統(tǒng)內存不足的時候,會
觸發(fā) oom
1.當系統(tǒng)內存不足的時候就會大量使用 swap
2.當系統(tǒng)大量使用 swap 的時候,系統(tǒng)會特別卡
注意: 有時可能內存還有剩余 300Mb-500Mb,但會發(fā)現(xiàn) swap 依然被使用
[root@ZabbixServer ~]# dd if=/dev/zero of=/dev/null bs=800M
[root@ZabbixServer ~]# tail -f /var/log/messages
Out of memory: Kill process 2227 (dd) score 778 or sacrifice child
Killed process 2227 (dd) total-vm:906724kB, anon-rss:798820kB, file-rss:0kB
3.那單機時代,如何使用 shell 腳本來實現(xiàn)服務器的監(jiān)控
需求: 每隔 1 分鐘監(jiān)控一次內存,當你的可用內存低于 100m,發(fā)郵件報警,要求顯示剩余內存
1.怎么獲取內存可用的值 free -m|awk '/^Mem/{print $NF}'
2.獲取到內存可用的值如何和設定的閾值進行比較
3.比較如果大于 100m 則不處理,如果小于 100 則報警
4.如何每隔 1 分鐘執(zhí)行一次
[root@ZabbixServer ~]# cat free.sh
#!/usr/bin/bash
HostName=$(hostname)_$(hostname -i)
Date=$(date +%F)
while true;do
Free=$(free -m|awk '/^Mem/{print $NF}')
if [ $Free -le 100 ];then
echo "$Date: $HostName Mem Is < ${Free}MB"
fi
sleep 5
done
第三章 zabbix 監(jiān)控快速安裝
首先檢查php版本: 若版本低更換新版本
php -v
更換yum源
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
停止相關服務
關閉 php-fpm,nginx/apache
service php-fpm stop
刪除已經安裝的 PHP 相關包
yum remove php* -y
或
yum remove php-common -y
安裝新版本 PHP
php 7.0/7.1/7.2 分別表示為 70w/71w/72w
yum install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-ldap php72w-mcrypt
重新啟動相關服務
service php-fpm start
1.配置zabbix倉庫
[root@m01 ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[root@m01 ~]# sed -i 's#repo.zabbix.com#mirrors.tuna.tsinghua.edu.cn/zabbix#g' /etc/yum.repos.d/zabbix.repo
2.安裝 Zabbix 程序包,以及 MySQL、 Zabbix-agent
[root@m01 ~]# yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent mariadb-server
[root@m01 ~]# systemctl start mariadb.service && systemctl enable mariadb.service
3.創(chuàng)建 Zabbix 數(shù)據(jù)庫以及用戶
[root@m01 ~]# mysqladmin password 123456
[root@m01 ~]# mysql -uroot -p123456
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
MariaDB [(none)]> flush privileges;
4.導入 Zabbix 數(shù)據(jù)至數(shù)據(jù)庫中
[root@m01 ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.11/create.sql.gz | mysql -uzabbix -pzabbix zabbix
5.編輯/etc/zabbix/zabbix_server.conf 文件,修改數(shù)據(jù)庫配置
[root@m01 ~]# grep "^[a-Z]" /etc/zabbix/zabbix_server.conf
...............
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
...............
6.啟動 Zabbix 服務進程,并加入開機自啟
[root@m01 ~]# systemctl start zabbix-server.service
[root@m01 ~]# systemctl enable zabbix-server.service
7.配置 Apache 的配置文件/etc/httpd/conf.d/zabbix.conf,修改時區(qū)
[root@m01 ~]# grep "Shanghai" /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai
8.重啟 Apache Web 服務器
[root@m01 ~]# systemctl start httpd
第四章 WEB安裝步驟
1.瀏覽器打開地址:http://10.0.1.61/zabbix/setup.php

2.檢查依賴項是否存在異常

3.配置zabbix連接數(shù)據(jù)庫

4.配置 ZabbixServer 服務器的信息

5.最終確認檢查

6.安裝成功
提示已成功地安裝了 Zabbix 前端。配置文件/etc/zabbix/web/zabbix.conf.php 被創(chuàng)建。

7.登陸zabbix
默認登陸 ZabbixWeb 的用戶名 Admin,密碼 zabbix

8.調整字符集為中文


9.修復中文亂碼
打開圖形之后會發(fā)現(xiàn)語言為亂碼,原因是缺少字體

解決方法:安裝字體并替換現(xiàn)有字體
[root@m01 ~]# yum install wqy-microhei-fonts -y
[root@m01 ~]# cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/zabbix/assets/fonts/graphfont.ttf
再次刷新發(fā)現(xiàn)已經變成中文了

第五章 Zabbix 監(jiān)控基礎架構
<meta charset="utf-8">
zabbix-agent(數(shù)據(jù)采集)—>zabbix-server(數(shù)據(jù)分析|報警)—> 數(shù)據(jù)庫(數(shù)據(jù)存儲)<—zabbix web(數(shù)據(jù)展示)

第六章 zabbix 快速監(jiān)控主機
1.安裝zabbix-agent
[root@web01 ~]# rpm -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.11-1.el7.x86_64.rpm
2.配置zabbix-agent
[root@web01 ~]# 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=10.0.1.61
ServerActive=127.0.0.1
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agentd.d/*.conf
3.啟動zabbix-agent并檢查
[root@web01 ~]# systemctl start zabbix-agent.service
[root@web01 ~]# systemctl enable zabbix-agent.service
[root@web01 ~]# netstat -lntup|grep 10050
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 10351/zabbix_agentd
tcp6 0 0 :::10050 :::* LISTEN 10351/zabbix_agentd
4.zabbix-web界面,添加主機



第七章 自定義監(jiān)控主機小試身手
1.監(jiān)控需求
監(jiān)控TCP11種狀態(tài)集
2.命令行實現(xiàn)
[root@web01 ~]# netstat -ant|grep -c TIME_WAIT
55
[root@web01 ~]# netstat -ant|grep -c LISTEN
12
3.編寫zabbix監(jiān)控文件(傳參形式)
[root@web01 ~]# cat /etc/zabbix/zabbix_agentd.d/tcp_status.conf
UserParameter=tcp_state[*],netstat -ant|grep -c $1
root@web01 ~]# systemctl restart zabbix-agent.service
4.server端進行測試
[root@m01 ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[root@m01 ~]# yum install zabbix-get.x86_64 -y
[root@m01 ~]# zabbix_get -s 10.0.1.7 -k tcp_state[TIME_WAIT]
51
[root@m01 ~]# zabbix_get -s 10.0.1.7 -k tcp_state[LISTEN]
12
5.web端添加


6.克隆監(jiān)控項
由于TCP有多種狀態(tài),需要添加多個監(jiān)控項,我們可以使用克隆快速達到創(chuàng)建的效果



其他的狀態(tài)依次添加即可
7.創(chuàng)建圖形

8.查看圖形

9.設置觸發(fā)器




第八章 郵件報警
<meta charset="utf-8">
1.定義發(fā)件人


2.定義收件人



3.自定義報警內容過
定制報警內容:
https://www.zabbix.com/documentation/4.0/zh/manual/appendix/macros/supported_by_location
參考博客
https://www.cnblogs.com/bixiaoyu/p/7302541.html
發(fā)送警告
報警郵件標題可以使用默認信息,亦可使用如下中文報警內容
名稱:Action-Email
默認標題:故障{TRIGGER.STATUS},服務器:{HOSTNAME1}發(fā)生: {TRIGGER.NAME}故障!
告警主機:{HOSTNAME1}
告警時間:{EVENT.DATE} {EVENT.TIME}
告警等級:{TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警項目:{TRIGGER.KEY1}
問題詳情:{ITEM.NAME}:{ITEM.VALUE}
當前狀態(tài):{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
恢復警告
恢復標題:恢復{TRIGGER.STATUS}, 服務器:{HOSTNAME1}: {TRIGGER.NAME}已恢復!
恢復信息:
告警主機:{HOSTNAME1}
告警時間:{EVENT.DATE} {EVENT.TIME}
告警等級:{TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警項目:{TRIGGER.KEY1}
問題詳情:{ITEM.NAME}:{ITEM.VALUE}
當前狀態(tài):{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
第九章 微信報警
1.查看配置文件里的腳本目錄路徑
[root@m01 ~]# grep "^AlertScriptsPath" /etc/zabbix/zabbix_server.conf
AlertScriptsPath=/usr/lib/zabbix/alertscripts
2.將weixin.py放在zabbix特定目錄
[root@m01 /usr/lib/zabbix/alertscripts]# ll
總用量 4
-rwxr-xr-x 1 root root 1344 8月 7 21:58 weixin.py
3.配置發(fā)信人


4.配置收信人

5.登陸企業(yè)微信公眾號添加賬戶
https://work.weixin.qq.com/wework_admin/loginpage_wx
1.登陸后在企業(yè)號上新建應用

2.上傳logo,填寫應用名稱 ,應用介紹等

3.查看啟動應用
同時會生成應用的AgentId以及Secret,這個在后面步驟會有用

4.接口調用測試
http://work.weixin.qq.com/api/devtools/devtool.php

這里的corpid為公司ID

Corpsecret就是剛才創(chuàng)建應用生成的Secrt,確認沒問題填寫進去然后下一步
如果沒問題會顯示200狀態(tài)碼

6.添加成員

7.關注公眾號

8.查看自己的賬號

9.修改腳本里的信息
[root@m01 /usr/lib/zabbix/alertscripts]# cat weixin.py
..............
corpid='微信企業(yè)號corpid'
appsecret='應用的Secret'
agentid=應用的id
..............
10.發(fā)信測試
[root@m01 /usr/lib/zabbix/alertscripts]# python weixin.py 你的賬號 '發(fā)信測試' ‘微信測試消息’
11.微信號上查看

12.發(fā)送到整個微信組
雖然我們實現(xiàn)了發(fā)送到單個用戶的功能,但是如果我們的用戶比較多,這樣還是麻煩的,不過我們可以發(fā)送到整個組,其實腳本里已經預留好了配置,只不過默認注釋了。
將腳本修改為以下內容,注釋掉用戶,打開組設置
#!/usr/bin/env python
import requests
import sys
import os
import json
import logging
logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s, %(filename)s, %(levelname)s, %(message)s',
datefmt = '%a, %d %b %Y %H:%M:%S',
filename = os.path.join('/tmp','weixin.log'),
filemode = 'a')
corpid='wwd26fdfb9940e7efa'
appsecret='Btg89FnZfMu0k7l6b4iagmAR5Z9TCgKknYbx-SMQvmg'
agentid=1000005
token_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret
req=requests.get(token_url)
accesstoken=req.json()['access_token']
msgsend_url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + accesstoken
#touser=sys.argv[1]
toparty=sys.argv[1]
subject=sys.argv[2]
message=sys.argv[2] + "\n\n" +sys.argv[3]
params={
#"touser": touser,
"toparty": toparty,
"msgtype": "text",
"agentid": agentid,
"text": {
"content": message
},
"safe":0
}
req=requests.post(msgsend_url, data=json.dumps(params))
logging.info('sendto:' + toparty + ';;subject:' + subject + ';;message:' + message)
12.隨機發(fā)送到指定用戶玩笑腳本
#!/bin/bash
num=$(echo $(($RANDOM%28+1)))
name=$(sed -n "${num}p" name.txt)
ok_boy=$(grep -v "${name}" name.txt)
for ok in ${ok_boy}
do
python weixin.py ${ok} "$1" "$2"
done
第十章 自定義模版
1.監(jiān)控TCP11種狀態(tài)
<meta charset="utf-8">
編寫zabbix配置文件
[root@web01 /etc/zabbix/zabbix_agentd.d]# cat zbx_tcp.conf
UserParameter=ESTABLISHED,netstat -ant|grep -c 'ESTABLISHED'
UserParameter=SYN_SENT,netstat -ant|grep -c 'SYN_SENT'
UserParameter=SYN_RECV,netstat -ant|grep -c 'SYN_RECV'
UserParameter=FIN_WAIT1,netstat -ant|grep -c 'FIN_WAIT1'
UserParameter=FIN_WAIT2,netstat -ant|grep -c 'FIN_WAIT2'
UserParameter=TIME_WAIT,netstat -ant|grep -c 'TIME_WAIT'
UserParameter=CLOSE,netstat -ant|grep -c 'CLOSE'
UserParameter=CLOSE_WAIT,netstat -ant|grep -c 'CLOSE_WAIT'
UserParameter=LAST_ACK,netstat -ant|grep -c 'LAST_ACK'
UserParameter=LISTEN,netstat -ant|grep -c 'LISTEN'
UserParameter=CLOSING,netstat -ant|grep -c 'CLOSING'
2.重啟zabbix-agent
[root@web01 ~]# systemctl restart zabbix-agent.service
3.測試監(jiān)控項
使用zabbix-get命令測試
[root@m01 ~]# yum install zabbix-get.x86_64 -y
[root@m01 ~]# zabbix_get -s 10.0.1.7 -k ESTABLISHED
2
[root@m01 ~]# zabbix_get -s 10.0.1.7 -k LISTEN
12
3.導入模版文件



4.主機關聯(lián)模版文件


5.查看最新數(shù)據(jù)

6.查看圖形

第x章 自定義模版監(jiān)控nginx狀態(tài)
1.開啟監(jiān)控頁面并訪問測試
[root@web01 ~]# cat /etc/nginx/conf.d/status.conf
server {
listen 80;
server_name localhost;
location /nginx_status {
stub_status on;
access_log off;
}
}
[root@web01 ~]# curl 127.0.0.1/nginx_status/
Active connections: 1
server accepts handled requests
6 6 6
Reading: 0 Writing: 1 Waiting: 0
2.準備nginx監(jiān)控狀態(tài)腳本
[root@web01 /etc/zabbix/zabbix_agentd.d]# cat nginx_monitor.sh
#!/bin/bash
NGINX_COMMAND=$1
CACHEFILE="/tmp/nginx_status.txt"
CMD="/usr/bin/curl http://127.0.0.1/nginx_status/"
if [ ! -f $CACHEFILE ];then
$CMD >$CACHEFILE 2>/dev/null
fi
# Check and run the script
TIMEFLM=`stat -c %Y $CACHEFILE`
TIMENOW=`date +%s`
if [ `expr $TIMENOW - $TIMEFLM` -gt 60 ]; then
rm -f $CACHEFILE
fi
if [ ! -f $CACHEFILE ];then
$CMD >$CACHEFILE 2>/dev/null
fi
nginx_active(){
grep 'Active' $CACHEFILE| awk '{print $NF}'
exit 0;
}
nginx_reading(){
grep 'Reading' $CACHEFILE| awk '{print $2}'
exit 0;
}
nginx_writing(){
grep 'Writing' $CACHEFILE | awk '{print $4}'
exit 0;
}
nginx_waiting(){
grep 'Waiting' $CACHEFILE| awk '{print $6}'
exit 0;
}
nginx_accepts(){
awk NR==3 $CACHEFILE| awk '{print $1}'
exit 0;
}
nginx_handled(){
awk NR==3 $CACHEFILE| awk '{print $2}'
exit 0;
}
nginx_requests(){
awk NR==3 $CACHEFILE| awk '{print $3}'
exit 0;
}
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 'Invalid credentials';
exit 2;
esac
3.編寫zabbix監(jiān)控配置文件
[root@web01 ~]# cat /etc/zabbix/zabbix_agentd.d/nginx_status.conf
UserParameter=nginx_status[*],/bin/bash /etc/zabbix/zabbix_agentd.d/nginx_monitor.sh $1
[root@web01 ~]# systemctl restart zabbix-agent.service
4.使用zabbix_get取值
[root@m01 ~]# zabbix_get -s 10.0.1.7 -k nginx_status[accepts]
7
5.導入模版

6.鏈接模版

7.查看數(shù)據(jù)

第x章 自定義模版監(jiān)控php狀態(tài)
1.開啟監(jiān)控頁面
[root@web01 ~]# tail -1 /etc/php-fpm.d/www.conf
pm.status_path = /php_status
[root@web01 ~]# cat /etc/nginx/conf.d/status.conf
server {
listen 80;
server_name localhost;
location /nginx_status {
stub_status on;
access_log off;
}
location /php_status {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME html$fastcgi_script_name;
include fastcgi_params;
}
}
[root@web01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web01 ~]# systemctl restart nginx.service php-fpm.service
2.訪問測試
[root@web01 ~]# curl 127.0.0.1/php_status
pool: www
process manager: dynamic
start time: 08/Aug/2019:22:31:27 +0800
start since: 37
accepted conn: 1
listen queue: 0
max listen queue: 0
listen queue len: 128
idle processes: 4
active processes: 1
total processes: 5
max active processes: 1
max children reached: 0
slow requests: 0
3.準備訪問腳本
[root@web01 ~]# cat /etc/zabbix/zabbix_agentd.d/fpm.sh
#!/bin/bash
##################################
# Zabbix monitoring script
#
# php-fpm:
# - anything available via FPM status page
#
##################################
# Contact:
# vincent.viallet@gmail.com
##################################
# ChangeLog:
# 20100922 VV initial creation
##################################
# Zabbix requested parameter
ZBX_REQ_DATA="$1"
ZBX_REQ_DATA_URL="$2"
# Nginx defaults
NGINX_STATUS_DEFAULT_URL="http://localhost/fpm/status"
WGET_BIN="/usr/bin/wget"
#
# Error handling:
# - need to be displayable in Zabbix (avoid NOT_SUPPORTED)
# - items need to be of type "float" (allow negative + float)
#
ERROR_NO_ACCESS_FILE="-0.91"
ERROR_NO_ACCESS="-0.92"
ERROR_WRONG_PARAM="-0.93"
ERROR_DATA="-0.94" # either can not connect / bad host / bad port
# Handle host and port if non-default
if [ ! -z "$ZBX_REQ_DATA_URL" ]; then
URL="$ZBX_REQ_DATA_URL"
else
URL="$NGINX_STATUS_DEFAULT_URL"
fi
# save the nginx stats in a variable for future parsing
NGINX_STATS=$($WGET_BIN -q $URL -O - 2>/dev/null)
# error during retrieve
if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then
echo $ERROR_DATA
exit 1
fi
#
# Extract data from nginx stats
#
#RESULT=$(echo "$NGINX_STATS" | awk 'print $0;match($0, "^'"$ZBX_REQ_DATA"':[[:space:]]+(.*)", a) { print a[1] }')
#RESULT=$(echo "$NGINX_STATS" | grep "$ZBX_REQ_DATA" | awk -F : '{print $2}')
RESULT=$(echo "$NGINX_STATS" | awk -F : "{if(\$1==\"$ZBX_REQ_DATA\") print \$2}")
if [ $? -ne 0 -o -z "$RESULT" ]; then
echo $ERROR_WRONG_PARAM
exit 1
fi
echo $RESULT
exit 0
[root@web01 ~]# bash /etc/zabbix/zabbix_agentd.d/fpm.sh "total processes" http://127.0.0.1/php_status
5
4.準備zabbix配置文件
[root@web01 ~]# cat /etc/zabbix/zabbix_agentd.d/fpm.conf
UserParameter=php-fpm[*],/etc/zabbix/zabbix_agentd.d/fpm.sh "$1" "$2"
[root@web01 ~]# systemctl restart zabbix-agent.service
4.使用zabbix_get取值
[root@m01 ~]# zabbix_get -s 10.0.1.7 -k php-fpm["total processes",http://127.0.0.1/php_status]
5
5.導入模版
導入之后需要修改一下模版里的宏配置

第x章 WEB監(jiān)控
需求,監(jiān)控頁面狀態(tài)碼



第x章 故障記錄
故障1
故障現(xiàn)象:
提示zabbix-server is not running

報錯日志:
34983:20190807:202215.171 database is down: reconnecting in 10 seconds
34983:20190807:202225.172 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO)
故障原因:
zabbix-server的配置文件里配有配置數(shù)據(jù)庫密碼
故障解決:
添加正確的數(shù)據(jù)庫賬號密碼信息
[root@m01 ~]# grep "^DB" /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
故障2
故障現(xiàn)象:微信報警失敗
報錯日志:
[root@m01 ~]# tail -f /var/log/zabbix/zabbix_server.log
Problem name: TIME_WAIT過多
Host: web01
Severity: Average
Original problem ID: 51
'": Traceback (most recent call last):
File "/usr/lib/zabbix/alertscripts/weixin.py", line 7, in <module>
import requests
ImportError: No module named requests
問題原因:
缺少模塊 requests
問題解決:
安裝缺失的依賴包
[root@m01 ~]# yum install python-pip
[root@m01 ~]# pip install --upgrade pip
[root@m01 ~]# pip install requests
故障3
故障現(xiàn)象:
在server端使用zabbix_get命令測試鍵值命令時提示警告
[root@m01 ~]# zabbix_get -s 10.0.1.7 -k ESTABLISHED
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
2
問題原因:
zabbix_agent是以普通用戶zabbix運行的,而普通用戶執(zhí)行netstat -antp時會有警告,網上查找發(fā)現(xiàn)只要不是用p參數(shù)就可以以普通用戶運行
解決方案:
監(jiān)控腳本里的命令修改為netstat -ant
作者:被運維耽誤的廚子
鏈接:http://www.itdecent.cn/p/c0baba52c442
來源:簡書
著作權歸作者所有。商業(yè)轉載請聯(lián)系作者獲得授權,非商業(yè)轉載請注明出處。