zabbix
```bash
# 容器版特定场景测试用 无关紧要
[root@master ~]# crontab -l
*/1 * * * * /etc/zabbix/watch_zb_conf.sh
[root@master ~]# cat /etc/zabbix/watch_zb_conf.sh
#!/usr/bin/bash
conf_file="/etc/zabbix/zabbix_agentd.conf"
zb_cluster_ip=`kubectl get pod -o wide |grep zabbix-ser|awk '{print $6}'`
zb_conf_ip=`cat ${conf_file} |grep Server= |awk -F= '{print $2}'`
if [[ $zb_cluster_ip != $zb_conf_ip ]];then
echo "[`date +%F_%X`] sed cluster ip ..."
sed -r -i "s#(Server=)(.*)#\1${zb_cluster_ip}#" ${conf_file}
sed -r -i "s#(ServerActive=)(.*)#\1${zb_cluster_ip}#" ${conf_file}
systemctl restart zabbix-agent && echo "[`date +%F_%X`] restart zabbix-agent complete"
else
echo "[`date +%F_%X`] skip ..."
fi
```
## zabbix添加监控项
1.命令行手动取值
```bash
[root@master images_dir]# iostat
Linux 5.4.144-1.el7.elrepo.x86_64 (master) 02/23/2024 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
14.16 0.00 14.21 0.04 0.00 71.59
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 32.88 361.95 522.01 3849104 5551144
scd0 0.00 0.10 0.00 1050 0
[root@master images_dir]# iostat |awk '/sda/'
sda 32.59 344.52 506.16 3852684 5660224
[root@master images_dir]# iostat |awk '$1 ~/sda/'
sda 32.59 343.90 505.66 3852972 5665311
[root@master images_dir]# iostat |awk '$1 ~/sda/'
sda 32.58 343.67 505.43 3852972 5666494
[root@master images_dir]# iostat |awk '$1 ~/sda/{print $2}'
32.57
[root@master images_dir]# iostat |awk '$1 ~/sda/ {print $2}'
32.57
```
2. 修改zabbix_agent配置文件
```
vim /etc/zabbix/zabbix_agentd.conf
...
# 写入上方取值命令
UserParameter=sda_tps,iostat |awk '$1 ~/sda/ {print $2}'
# 固定写法 = 自定义监控名称 , 取值命令或脚本
#UserParameter=sda_tps,iostat |awk '$1 ~/sda/ {print $2}'
# 重启生效
systemctl restart zabbix-agent
```
3. zabbix-server测试监控项取值
```
# k对应配置文件中的“#UserParameter=sda_tps,iostat |awk '$1 ~/sda/ {print $2}' ”key值
[root@zabbix-server-74d574c65d-5jtwz zabbix]# zabbix_get -s 192.168.111.128 -k sda_tps
32.10
[root@zabbix-server-74d574c65d-5jtwz zabbix]#
```
4.创建自定义监控项


## grafana添加zabbix数据源
```bash
sudo yum install -y http://mirrors.aliyun.com/grafana/yum/rpm/Packages/grafana-8.2.7-1.x86_64.rpm
# 启动 Grafana 服务
sudo systemctl start grafana-server
# 设置开机自启
sudo systemctl enable grafana-server
```