zabbix monitoring nginx and tomcat

Please revert to "zabbix monitoring and alarm messages" snapshot https://blog.51cto.com/14320361/2448847

Monitoring Tomcat
zabbix_java_gateway: the introduction of a function after zabbix2.0. As the name suggests: Java gateway, similar agentd, but only for the Java side. Of particular note is that it can only take the initiative to get the data, but not passively acquired data. Its data will eventually be submitted to the server or proxy.
If you need to open the process monitoring tomcat need to be compiled in zabbix added --enable_java parameter
a. Zabbix_server side configuration
mounted zabbix_java_gateway program
(1) View ports
284 -anpt the netstat | grep 9000
285 -anpt the netstat | grep MySQL
286 -anpt the netstat | grep 80
287 -anpt the netstat | grep 10050
zabbix monitoring nginx and tomcat

(2) Installation zabbix_java_gateway program
288 rz (Java-uploaded-Gateway-ZABBIX 3.2.1-1.el7.x86_64.rpm)
292 RPM -ivh ZABBIX-Java-Gateway-3.2.1-1.el7.x86_64.rpm
( 3) modify zabbix profile
293 Vim /etc/zabbix/zabbix_java_gateway.conf
LISTEN_IP = "0.0.0.0" # Java-Gateway address to listen
LISTEN_PORT = 10052 # listening port
PID_FILE = "/ var / run / zabbix / zabbix_java.pid "#pid file storage path
zabbix monitoring nginx and tomcat
(4) to open and view zabbix port
294 systemctl Start the Java-gateway.service zabbix-
295 netstat -anpt | grep 10052

Vim /etc/zabbix/zabbix_java_gateway.conf 296
(. 5) to modify the configuration files zabbixserver default java zabbix not start monitor program
297 Vim /usr/local/zabbix/etc/zabbix_server.conf
JavaGateway = local IP 192.168.1.10 # 215
JavaGatewayPort = 10052 # 223 Notes to
StartJavaPollers # = 231. 5
(. 6) to restart zabbixserver end
298 /etc/init.d/zabbix_server restart

two. Configuring Tomcat
20 rpm -qa | grep the JDK # check whether the installation of java environment rpm
21 rpm -e java-1.8.0-openjdk-headless java-1.7.0-openjdk-headless - nodeps
## built-in uninstall java environment
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
19 rz (upload jdk and tomcat installation package)
23 is the tar-8u211 zxf jdk-Linux-x64.tar.gz -C / usr / local /
24 zxf the tar-8.5.35.tar.gz tomcat Apache-
25 Apache-tomcat Music Videos -8.5.35 / usr / local / Tomcat
26 is Vim / etc / Profile (added to the end)
Export JAVA_H0ME = / usr / local / jdk1.8.0_211
Export the JRE_HOME = / usr / local / jdk1.8.0_211
Export the JAVA_HOME the CLASSPATH = $ / lib / the tools.jar: $ JAVA_H0ME / lib / Dt.jar
Export the JAVA_HOME $ the PATH = / bin: $ the JRE_HOME / bin: $ the PATH

27 source / etc / profile (execute it)
28 the Java -version (jdk check whether the installation was successful)
zabbix monitoring nginx and tomcat
Tomcat open the jmx remote debugging
29 cd / usr / local / Tomcat /
31 vim bin / catalina.sh (about 300 lines added)
= CATALINA_OPTS "$ CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port = 8888 -Dcom.sun.management.jmxremote.ssl = false -Djava.rmi.server.hostname = 192.168.1.20
- Dcom.sun.management.jmxremote.authenticate = flase "
start tomcat and view port
32 /usr/local/tomcat/bin/startup.sh
33 -anput netstat | grep 8888
zabbix monitoring nginx and tomcat

Service terminal test

zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbixserver end configuration (operation on the browser)
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat

三.监控nginx服务器
1.安装依赖包
49 yum -y install pcre-devel openssl-devel
2.安装nginx
48 rz (上传nginx和zabbix安装包)
50 tar zxf nginx-1.14.0.tar.gz
51 cd nginx-1.14.0/
52 ./configure && make && make install (编译安装)
53 ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ (链接命令目录)
54 nginx (开启nginx)
56 netstat -anpt | grep nginx (查看nginx端口)
zabbix monitoring nginx and tomcat
3.安装zabbix
21 tar zxf zabbix-3.2.1.tar.gz
22 cd zabbix-3.2.1/
23 ./configure --prefix=/usr/local/zabbix --enable-agent
24 make && make install
26 cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/ (复制zabbix启动文件)
27 vim /etc/init.d/zabbix_agentd (修改zabbix启动文件)
BASEDIR=/usr/local/Zabbix #22
PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid #31
29 cd /usr/local/Zabbix
30 vim etc/zabbix_agentd.conf (修改zabbix配置文件)
PidFile=/usr/local/zabbix/logs/zabbix_agentd.pid #11 (需要创建所需目录)
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log #30
Server=192.168.1.10 #91 服务端IP
ListenPort=10050 #99
ListenIP=0.0.0.0 #107
ServerActive=192.168.1.10 #132 服务端IP
Hostname=192.168.1.20 #143 客户端IP
Timeout=3 #232
UnsafeUserParameters=1 #278
#287 修改添加
UserParameter=nginx.info[],/usr/local/zabbix/scripts/nginx.sh $1 (需要创建所需目录)
UserParameter=nginx.ping[
],netstat -anput | grep -w 80 | grep -w LISTEN | wc -l

31 mkdir /usr/local/zabbix/scripts (创建所需目录)
32 cd /usr/local/zabbix/scripts/
4.安装nginx
33 rz
34 vim nginx.sh (修改ip)
编写监控nginx脚本
#!/bin/bash
#This is a scripts for checking nginx
case $1 in
index)
RS=curl -s -I 192.168.83.7/index.html |head -n1 |awk '{print $2}'
echo $RS
;;

WorkerProcesses)
RS=ps aux |grep nginx | grep -w worker |wc -l
echo $RS
;;

bps)
RS=ab -q -n 1000 -c 1000 http://192.168.83.7/index.html |grep Request | awk '{print $4}'
echo $RS
;;

Current)
LINES=cat /usr/local/nginx/logs/access.log |wc -l
sleep 1
NOW_LINES=cat /usr/local/nginx/logs/access.log |wc -l
echo $NOW_LINES $LINES | awk '{print $1 -$2}'
;;
IP)
RS=cat /usr/local/nginx/logs/access.log | awk '{print $1}' |sort -u | wc -l
echo $RS
;;

VirtualHost)
RS=cat /usr/local/nginx/conf/nginx.conf |grep -v '#' | grep server_name | wc -l
echo $RS
;;

MD5)
RS=md5sum /usr/local/nginx/conf/nginx.conf |awk '{print $1}'
echo $RS
;;

PV)
RS=wc -l /usr/local/nginx/logs/access.log | awk '{print $1}'
echo $RS
;;
esac
37 yum -y install httpd-tools (ab压力测试需要)
41 ab -q -n 1000 -c 1000 http://192.168.1.20/index.html
42 chmod +x nginx.sh (改nginx.sh可执行权限)
43 useradd Zabbix (创建所需用户)
44 mkdir /usr/local/zabbix/logs (创建所需目录)
45 chown -R zabbix:zabbix /usr/local/zabbix/ (给配置目录zabbix用户拥有)
49 /etc/init.d/zabbix_agentd start (开启zabbix)
50 netstat -anpt | grep Zabbix (查看zabbix端口)
zabbix monitoring nginx and tomcat

服务端测试
zabbix_get -s 192.168.1.20 -p 10050 -k nginx.info[index]
zabbix monitoring nginx and tomcat
zabbix_get -s 192.168.1.20 -p 10050 -k nginx.ping
zabbix monitoring nginx and tomcat
客户端给予权限
chmod +s /usr/bin/netstat
再次在服务端测试
zabbix_get -s 192.168.1.20 -p 10050 -k nginx.ping

zabbix monitoring nginx and tomcat

四.回到浏览器zabbixserver端创建nginx监控模板
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
1、 监控nginx运行状态
zabbix monitoring nginx and tomcat
2、 监控nginx总访问量
zabbix monitoring nginx and tomcat
3、 独立IP数
zabbix monitoring nginx and tomcat

4、 nginx主页的状态
zabbix monitoring nginx and tomcat

  1. nginx当前并发数
    zabbix monitoring nginx and tomcat

6、配置文件MD5值用来监控nginx配置文件是否被更改

zabbix monitoring nginx and tomcat

7、当前吞吐量bps,并且让其更新时间为60秒
zabbix monitoring nginx and tomcat

8、nginx工作进程的个数
zabbix monitoring nginx and tomcat
9、nignx虚拟主机的个数

zabbix monitoring nginx and tomcat
五.创建触发器
创建nginx服务意外停止工作!触发器,表达式格式{}
{Temlate App Nginx Service:nginx.ping.last(0)} = 0
Template App Nginx Service 模板名
nginx.ping 键名
last(0) 方法:表示当前的。。 last(1)表示上一个。。
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
创建“Nginx主页不可访问”的触发器
{Temlate App Nginx Service:nginx.ping.last(0)} > 400
zabbix monitoring nginx and tomcat

创建“Nginx文件被修改”的触发器
{Temlate App Nginx Service:nginx.info[MD5].last(0)} <> {Temlate App Nginx Service:nginx.info[MD5].last(1)}
zabbix monitoring nginx and tomcat

zabbix monitoring nginx and tomcat

六.在客户端主机中添加创建的nginx模板
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
查看zabbix监控的数据
zabbix monitoring nginx and tomcat
给监控nginx状态添加映射(更加友好)
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
关联到监控项
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat

Nginx create graphical monitoring
zabbix monitoring nginx and tomcat
zabbix monitoring nginx and tomcat
view monitoring
zabbix monitoring nginx and tomcat
experiment is completed

Guess you like

Origin blog.51cto.com/14320361/2449419