zabbix监控nginx 待补充

监听端口

1.cat /usr/local/zabbix/bin/ports.py

#!/usr/bin/python

#coding=utf-8

import commands

import os,sys

##########返回命令执行结果

def getComStr(comand):

try:

stat, proStr = commands.getstatusoutput(comand)

except:

print "command %s execute failed, exit" % comand

#将字符串转化成列表

#proList = proStr.split("\n")

return proStr

##########获取系统服务名称和监听端口

def filterList():

tmpStr = getComStr("netstat -tpln")

tmpList = tmpStr.split("\n")

del tmpList[0:2]

newList = []

for i in tmpList:

val = i.split()

del val[0:3]

del val[1:3]

#提取端口号

valTmp = val[0].split(":")

val[0] = valTmp[1]

#提取服务名称

valTmp = val[1].split("/")

val[1] = valTmp[-1]

if val[1] != ‘-‘ and val not in newList:

newList.append(val)

return newList

def main():

netInfo = filterList()

#格式化成适合zabbix lld的json数据

json_data = "{\n" + "\t" + ‘"data":[‘ + "\n"

#print netInfo

for net in netInfo:

if net != netInfo[-1]:

json_data = json_data + "\t\t" + "{" + "\n" + "\t\t\t" + ‘"{#PPORT}":"‘ + str(net[0]) + "\",\n" + "\t\t\t" + ‘"{#PNAME}":"‘ + str(net[1]) + "\"},\n"

else:

json_data = json_data + "\t\t" + "{" + "\n" + "\t\t\t" + ‘"{#PPORT}":"‘ + str(net[0]) + "\",\n" + "\t\t\t" + ‘"{#PNAME}":"‘ + str(net[1]) + "\"}]}"

print json_data

if __name__ == "__main__":

main()

2.cat ports_discovery.conf

UserParameter=ports.discovery,sudo /usr/bin/python  /usr/local/zabbix/bin/ports.py

3.模板

All TCP Ports discovery

ports.discovery

Listen Port $1

net.tcp.listen[{#PPORT}]

{Ports Monitoring:net.tcp.listen[{#PPORT}].last()}=0

如果是监听tomcat

cat /usr/local/zabbix/bin/tcp_services.py

#/usr/bin/python

#This script is used to discovery disk on the server

import subprocess

import os

import socket

import json

import glob

java_names_file=‘java_names.txt‘

javas=[]

if os.path.isfile(java_names_file):

#   print ‘java_names_file exists!‘

#####

##### here should use % (java_names_file) instead of using the python variable java_names_file directly inside the ‘‘‘   ‘‘‘ quotes

#####

args=‘‘‘awk -F‘:‘ ‘{print $1‘:‘$2}‘ %s‘‘‘  % (java_names_file)

t=subprocess.Popen(args,shell=True,stdout=subprocess.PIPE).communicate()[0]

elif glob.glob(‘/opt/xx/*_tomcat‘) and not os.path.isdir(‘/opt/logs/logstash‘) and not os.path.isdir(‘/opt/app/elasticsearch/config‘):

t=subprocess.Popen(‘cd /opt/xx && ls *|grep xx_tomcat‘,shell=True,stdout=subprocess.PIPE)

for java in t.stdout.readlines():

if len(java) != 0:

S=java.strip(‘\n‘).strip(‘:‘)

args="cat /opt/xx/%s/conf/server.xml|grep port|sed -n ‘2p‘|awk ‘{print $2}‘|awk -F ‘=‘ ‘{print $2}‘|tr -d ‘\"‘" % S

port=subprocess.Popen(args,shell=True,stdout=subprocess.PIPE).communicate()[0].strip(‘\n‘)

STR1={‘{#PROCNAME}‘:S}

STR2={‘{#PORT}‘:port}

STR3=dict(STR1, **STR2)

javas.append(STR3)

print json.dumps({‘data‘:javas},indent=4,separators=(‘,‘,‘:‘))

监听tcp状态

cat /usr/local/zabbix/bin/tcp_status_ss.sh

#!/bin/bash

#scripts for tcp status

function SYNRECV {

/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘SYN-RECV‘ | awk ‘{print $2}‘

}

function ESTAB {

/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘ESTAB‘ | awk ‘{print $2}‘

}

function FINWAIT1 {

/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘FIN-WAIT-1‘ | awk ‘{print $2}‘

}

function FINWAIT2 {

/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘FIN-WAIT-2‘ | awk ‘{print $2}‘

}

function TIMEWAIT {

/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘TIME-WAIT‘ | awk ‘{print $2}‘

}

function LASTACK {

/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘LAST-ACK‘ | awk ‘{print $2}‘

}

function LISTEN {

/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘LISTEN‘ | awk ‘{print $2}‘

}

$1

cat tcp_status_ss.conf

UserParameter=tcp[*],/usr/local/zabbix/bin/tcp_status_ss.sh $1

时间: 2024-10-14 08:12:50

zabbix监控nginx 待补充的相关文章

Zabbix监控nginx服务进程状态

zabbix监控nginx需要开启nginx status,要确认nginx编译http_sub_module模块! 1.检查当前nginx是否安装配置http_sub_module模块 # nginx -V Tengine version: Tengine/1.5.2 (nginx/1.2.9) built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) TLS SNI support enabled configure arguments: --p

zabbix监控nginx

上一篇介绍了zabbix安装,这里接着说说zabbix监控nginx 安装zabbix-agent 在实际应用中,我们server和agent部在同一机器上,所以需要分开安装,其实上一篇已经说了,在编译安装zabbix-server的时候也安装了zabbix-agent,如果只安装zabbix-agent # 切换到zabbix解压目录 cd zabbix-3.0.3 # 编译配置 ./configure --prefix=/usr/local/zabbix-agent --enable-age

Zabbix 监控 Nginx 状态

1.获取 Nginx 状态条件( 需要nginx安装模块) [localhost]#/usr/local/nginx/sbin/nginx -V nginx version: nginx/1.8.0built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_sta

zabbix监控nginx性能状态

nginx在生产环境中的应用越来越广泛,所以需要对nginx的性能状态做一些监控,来发现出来出现的问题.nginx处理流程图具体如下: 注释:Accepts(接受).Handled(已处理).Requests(请求数)是一直在增加的计数器.Active(活跃).Waiting(等待).Reading(读).Writing(写)随着请求量而增减 名称 描述 指标类型 Accepts(接受) NGINX 所接受的客户端连接数 资源: 功能 Handled(已处理) 成功的客户端连接数 资源: 功能

zabbix监控nginx连接状态

zabbix学习笔记:zabbix监控nginx连接状态 zabbix监控nginx zabbix可以监控nginx的状态,关于一个服务的状态可以查看服务本身的状态(版本号.是否开启),还应该关注服务能力(例如以nginx的负载效果:连接数.请求数和句柄数).下面我们使用zabbix监控nginx. nginx的安装 如果想要查看nginx的服务状态,在对nginx进行源码安装的时候要选中–with-http_stub_status_module模块. 1.解压安装包: [[email prot

zabbix 监控Nginx

一.开启nginx_status页面 server {  \\定义一个虚拟主机     listen 80 default_server;  \\定义监听地址     server_name _;   \\定义主机名     location = /ngx_status {         stub_status on;   \\开启status         access_log off;    \\关闭访问日志         allow 127.0.0.1;   \做访问权限控制    

zabbix监控nginx状态

一.zabbix客户端配置 首先修改一下zabbix客户端的配置,习惯上将zabbix的配置文件拷贝到自建的/etc/zabbix/目录,方便管理: [[email protected] ~]# sed -e '/^$/d;/^#/d'  /etc/zabbix/zabbix_agentd.conf PidFile=/tmp/zabbix_agentd.pid LogFile=/tmp/zabbix_agentd.log Server=192.168.199.79 ServerActive=12

zabbix监控nginx,Mysqld,Php状态

zabbix监控nginx状态 首先,在nginx的配置文件中添加如下一段代码 server  {   listen localhost:80;   server_name localhost; location /nginxstatus {   stub_status on;   access_log off;   allow 127.0.0.1; allow 192.168.1.165;    deny all;   }   } 保存之后重启nginx 在zabbix脚本目录下创建脚本监控z

Zabbix 监控 Nginx(四)

简介: 如何使用 Zabbix 监控 Nginx 状态 ? 1.获取 Nginx 状态( HTTP Stub Status ) [[email protected] ~]# /apps/product/nginx/sbin/nginx -V nginx version: nginx/1.8.1 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI