Java&&snmp&&custom monitoring of zabbix monitoring

1. The client enables the remote monitoring function of java jmxremote

Upload the tomcat package to the /opt directory
cd /opt
tar zxvf apache-tomcat-9.0.16.tar.gz
mv apache-tomcat-9.0.16 /usr/local/tomcat

#Configure java jmxremote remote monitoring function
vim /usr/local/tomcat/bin/catalina.sh
...... #The location is before cygwin=false
CATALINA_OPTS="$CATALINA_OPTS \
-Dcom.sun.management.jmxremote \
-Dcom .sun.management.jmxremote.port=12345 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Djava.rmi.server.hostname=192.168.50.22" #tomcat server address
 

#Start the service, check the port
/usr/local/tomcat/bin/startup.sh 

netstat -lntp | grab 12345


2. Install zabbix-java-gateway on the server side

yum install -y zabbix-java-gateway

systemctl enable --now zabbix-java-gateway.service

netstat -lntp | grep 10052 #zabbix-java-gateway listens to port 10052 by default
 

3. Modify the server zabbix-server configuration

vim /etc/zabbix/zabbix_server.conf
......
JavaGateway=127.0.0.1 # Line 317, specify the IP address of zabbix-java-gateway
StartJavaPollers=5 # Line 333, start the poller process used to collect java data quantity

systemctl restart zabbix-server

ps -ef | grep zabbix_server | grabbed java


4. Add the host on the server web page and associate the template

Click [Host] in [Configuration] on the left menu bar, click zbx-agent01
[Template] to search for JMX, select Generic Java JMX
[Interfaces] and click Add JMX, [IP Address] enter 192.168.80.30, [Port] enter 12345 and
click [ Update]
Zabbix server availability added JXM monitoring method after waiting for a while

Custom monitoring———Monitoring nginx concurrency
Custom monitoring operation process
1. Clearly obtain commands or scripts for monitoring indicator data
2. Write .conf in the monitored host configuration file directory /etc/zabbix/zabbix_agent2.d/ The monitoring item configuration file at the end customizes the command/script
   format for obtaining the KEY and value of the monitoring data: UserParameter=<KEY>,command/script path
3. Add template->monitoring item->trigger- in the server management page > Figure
4, associating the monitoring template with the monitored host

Example 1: Nginx concurrent monitoring
requires nginx to install the --with-http_stub_status_module module

Vim /etc/nginx/conf.d/default.conf

Systemctl restart nginx

Create a monitoring script

#!/bin/bash
nginx_active() {
  /usr/bin/curl -s http://127.0.0.1/nginx_status | awk '/Active/ {print $NF}'
}
 
nginx_reading() {
  /usr/bin/curl -s http://127.0.0.1/nginx_status | awk '/Reading/ {print $2}'
}
 
nginx_writing() {
  /usr/bin/curl -s http://127.0.0.1/nginx_status | awk '/Writing/ {print $4}'
}
 
nginx_waiting() {
  /usr/bin/curl -s http://127.0.0.1/nginx_status | awk '/Waiting/ {print $6}'
}
 
nginx_accepts() {
  /usr/bin/curl -s http://127.0.0.1/nginx_status | awk 'NR==3 {print $1}'
}
 
nginx_handled() {
  /usr/bin/curl -s http://127.0.0.1/nginx_status | awk 'NR==3 {print $2}'
}
 
nginx_requests() {
  /usr/bin/curl -s http://127.0.0.1/nginx_status | awk 'NR==3 {print $3}'
}
 
nginx_check() {
  pro_num=$(ps aux | grep -v grep | grep -c "nginx:")
  if [ $pro_num -le 0 ];then
    echo 0
  else
    echo $pro_num
  fi
}
 
######main######
cmd=$1
 
case $cmd in
check)
  nginx_check
  ;;
active)
  nginx_active
  ;;
reading)
  nginx_reading
  ;;
writing)
  nginx_writing
  ;;
waiting)
  nginx_waiting
  ;;
accepts)
  nginx_accepts
  ;;
handled)
  nginx_handled
  ;;
requests)
nginx_requests
  ;;
*)
  echo "$USAGE: $0 {check|active|reading|writing|waiting|accepts|handled|requests}"
esac
 
 
 
 
 
 
 
 
 
 

chmod +x zbx_nginx.sh

cd /etc/zabbix/zabbix_agent2.d/

vim userparameter_nginx.conf

UserParameter=nginx.status[*],/opt/zbx_nginx.sh $1

systemctl restart zabbix-agent2 

Enter the WEB to set up
and add a template

After the test is ok, click Add

Zabbix monitors SNMP 
SNMP, a simple network management protocol, is often used to monitor network devices, and can also monitor devices that support SNMP functions (windows, linux, printers, etc.).

1. The server installs the snmp monitoring program
yum install -y net-snmp net-snmp-utils


2. Modify the snmp configuration file and start the service

vim /etc/snmp/snmpd.conf
......
view systemview included .1 #57 line, add this configuration

systemctl start snmpd

  

3. Use the snmpwalk command to test
snmpwalk -v 2c -c public 127.0.0.1 sysname
SNMPv2-MIB::sysName.0 = STRING: zbx-server
------------------- ------------------------------------
–v 1|2c|3: Specifies the SNMP protocol version, v2c The community name is used as authentication, v3 is authenticated by user name and password
– c: specify the community name (password between devices)
sysname: the key of snmp, used to view the system name; SysDesc is used to view system information
------- ------------------------------------------------

4. Configure snmp monitoring on the web page


Click [Host] in [Configuration] on the left menu bar, click Zabbix server
[Template] to cancel the link and clear the existing template Linux by Zabbix agent
        Search for Generic, select Generic by SNMP
[Group] Search for net, select net(new)
[ Interfaces] Click [Add] to select SNMP, [IP address] to enter 127.0.0.1, [Port] to enter 161
[SNMP version] to select SNMPv2
[SNMP community] to enter {$SNMP_COMMUNITY}

Click [Macro] on the upper menu bar
and select [Host Macro]
[Macro] enter {$SNMP_COMMUNITY}, [Value] enter public (to be consistent with the community name set by the network device), [Description] enter the team name of the network device snmp and click
[ Update]
After waiting for a while, the availability of Zabbix server becomes SNMP monitoring method

Guess you like

Origin blog.csdn.net/zl965230/article/details/131043296