zabbix监控nginx的进程和7种状态

1、编写shell脚本,传递参数,根据参数返回结果,和之前的tcp的脚本类似。


#!/bin/bash
#this script is used to get nginx connetion status
#nginx status

HOST="10.10.252.211"
PORT="8080"
 

metric=$1
tmp_file=/tmp/nginx_status.txt
  /usr/bin/curl -s http://$HOST:$PORT/status > $tmp_file
 
case $metric in
   pid)
          output=`/sbin/pidof nginx | wc -l`
          if [ "$output" == "" ];then
             echo 0
          else
             echo $output
          fi
        ;;
   active)
          output=$(awk 'NR==1{print $3}' $tmp_file)
          if [ "$output" == "" ];then
             echo 0
          else
             echo $output
          fi
        ;;
   accepts)
          output=$(awk 'NR==3{print $1}' $tmp_file)
          if [ "$output" == "" ];then
             echo 0
          else
             echo $output
          fi
        ;;
   handled)
          output=$(awk 'NR==3{print $2}' $tmp_file)
          if [ "$output" == "" ];then
             echo 0
          else
             echo $output
          fi
        ;;
   requests)
          output=$(awk 'NR==3{print $3}' $tmp_file)
          if [ "$output" == "" ];then
             echo 0
          else
             echo $output
          fi
        ;;
   reading)
          output=$(awk 'NR==4{print $2}' $tmp_file)
          if [ "$output" == "" ];then
             echo 0
          else
             echo $output
          fi
        ;;
   writing)
          output=$(awk 'NR==4{print $4}' $tmp_file)
          if [ "$output" == "" ];then
             echo 0
          else
             echo $output
          fi
        ;;
   waiting)
          output=$(awk 'NR==4{print $6}' $tmp_file)
          if [ "$output" == "" ];then
             echo 0
          else
             echo $output
          fi
        ;;
         *)
          echo -e "\e[033mUsage: sh  $0 [pid|active|accepts|handled|requests|reading|writing|waiting]\e[0m"
   
esac

2、在zabbix_agent文件中配置自定义item,自定义监控tcp的item的key

[root@wyl01 zabbix_agentd.d]# cat nginx_status.conf 
UserParameter=nginx.status[*],/usr/bin/sh /etc/zabbix/shell/nginx_status.sh $1

3、配置graph图表,将所有的监控项添加到一个图中,方便观察。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值