帮我写一个 centos 7 zabbix 监控nginx的脚本
时间: 2024-05-15 13:14:46 浏览: 185
cetbos 7 搭建zabbix.docx
好的,我可以帮你写一个监控nginx的脚本,请问你已经安装了zabbix及其相关插件吗?如果还没有,请先安装好。下面是一个简单的监控nginx负载的脚本示例:
```bash
#!/bin/bash
# Author: your name
# Date: YYYY-MM-DD
# Description: Monitor Nginx status for Zabbix
# Nginx status page URL
URL="http://localhost/nginx_status"
# Get nginx active connections
active_connections=$(curl -s $URL | awk '/Active/{print $NF}')
# Get nginx accepted connections
accepted_connections=$(curl -s $URL | awk 'NR==3{print $1}')
# Get nginx handled connections
handled_connections=$(curl -s $URL | awk 'NR==3{print $2}')
# Get nginx total requests
total_requests=$(curl -s $URL | awk 'NR==3{print $3}')
# Get nginx reading connections
reading=$(curl -s $URL | awk '/Reading/{print $2}')
# Get nginx writing connections
writing=$(curl -s $URL | awk '/Writing/{print $4}')
# Get nginx waiting connections
waiting=$(curl -s $URL | awk '/Waiting/{print $6}')
# Send data to zabbix
echo "nginx.active_connections $active_connections $(date +%s)" | zabbix_sender -z zabbix_server_ip -s nginx_server_name -i -
echo "nginx.accepted_connections $accepted_connections $(date +%s)" | zabbix_sender -z zabbix_server_ip -s nginx_server_name -i -
echo "nginx.handled_connections $handled_connections $(date +%s)" | zabbix_sender -z zabbix_server_ip -s nginx_server_name -i -
echo "nginx.total_requests $total_requests $(date +%s)" | zabbix_sender -z zabbix_server_ip -s nginx_server_name -i -
echo "nginx.reading_connections $reading $(date +%s)" | zabbix_sender -z zabbix_server_ip -s nginx_server_name -i -
echo "nginx.writing_connections $writing $(date +%s)" | zabbix_sender -z zabbix_server_ip -s nginx_server_name -i -
echo "nginx.waiting_connections $waiting $(date +%s)" | zabbix_sender -z zabbix_server_ip -s nginx_server_name -i -
```
你需要将脚本中的$URL替换为你实际的nginx状态页面URL,并将$zabbix_server_ip和$nginx_server_name替换为你的zabbix服务器IP和nginx服务器名称。该脚本可以使用zabbix_sender命令将收集的数据发送到zabbix服务器,以便在zabbix监控界面中查看nginx的实时状态和趋势。
阅读全文