zabbix监控(11)自定义模板 利用模板可以快速添加监控项
zabbix监控(11)
11.自定义模板 利用模板可以快速添加监控项
a.创建模板 b.监控nginx模板 c.监控 php-fpm 模板 d.监控redis模板
11:自定义模板 利用模板可以快速添加监控项: 模板可以分享
Zabbix中,模板就是主机
a.创建模板
1. 7层架构
Pass
2.自定义模板
3.更新应用集
4. 添加触发器
5.添加图形
6.模板的导出/导入以及共享入口
# scp -rp tcp.conf root@192.168.1.91:`pwd
b.监控 nginx 模板
1.开启监控页面
在nginx在添加
location /nginx-status {
stub_status ;
}
2.重启nginx并访问http://ip/nginx-status/
3.编写状态脚本
mkdir /etc/zabbix/scripts
vim /etc/zabbix/scripts/nginx_status.sh
内容如下:
#!/bin/bash
BKUP_DATE=`/bin/date +%Y%m%d`
#LOG="/data/log/zabbix/webstatus.log"
HOST=127.0.0.1
PORT=80
ARGS=1
if [ $# -ne "$ARGS" ];then
echo "Please input one arguement:"
fi
case in
exist)
result=`/sbin/pidof nginx | wc -l`
echo $result
;;
active)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Active' | awk '{print $NF}'`
echo $result
;;
reading)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Reading' | awk '{print }'`
echo $result
;;
writing)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Writing' | awk '{print }'`
echo $result
;;
waiting)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Waiting' | awk '{print }'`
echo $result
;;
accepts)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print }'`
echo $result
;;
handled)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print }'`
echo $result
;;
requests)
result=`/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print }' `
echo $result
;;
*)
echo "Usage:
echo "Usage:$0(active|reading|writing|waiting|accepts|handled|requests)"
(active|reading|writing|waiting|accepts|handled|requests)";;
esac
4.测试脚本
/etc/zabbix/scripts/nginx_status.sh
5.添加键值
UserParameter=nginx.status[*],/etc/zabbix/scripts/nginx_status.sh
6.重启zabbix—agent
7.手动取值测试
zabbix_get -s 172.16.180.11 -k nginx.status[active]
8.创建模板
9.触发器值填写exist
10.链接模板
c.监控 php-fpm 模板
1.开启监控页面
编写php-fpm配置文件
vim /etc/php-fpm.d/www.conf
pm.status_path = /php_status
编写nginx配置文件(通过nginx访问)
vim nginx.conf
location ~ /php_status {
root /usr/local/nginx/html/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
2.导入配置文件
Fpm.conf
UserParameter=php-fpm[*], /bin/bash /etc/zabbix/scripts/php-fpm.sh
Php-fpm.Sh
#!/bin/bash
pool(){
curl -s http://127.0.0.1:8080/php_status|awk '/pool/ {print $NF}'
}
process_manager() {
curl -s http://127.0.0.1:8080/php_status|awk '/process manager/ {print $NF}'
}
start_since(){
curl -s http://127.0.0.1:8080/php_status|awk '/^start since:/ {print $NF}'
}
accepted_conn(){
curl -s http://127.0.0.1:8080/php_status|awk '/^accepted conn:/ {print $NF}'
}
listen_queue(){
curl -s http://127.0.0.1:8080/php_status|awk '/^listen queue:/ {print $NF}'
}
max_listen_queue(){
curl -s http://127.0.0.1:8080/php_status|awk '/^max listen queue:/ {print $NF}'
}
listen_queue_len(){
curl -s http://127.0.0.1:8080/php_status|awk '/^listen queue len:/ {print $NF}'
}
idle_processes(){
curl -s http://127.0.0.1:8080/php_status|awk '/^idle processes:/ {print $NF}'
}
active_processes(){
curl -s http://127.0.0.1:8080/php_status|awk '/^active processes:/ {print $NF}'
}
total_processes(){
curl -s http://127.0.0.1:8080/php_status|awk '/^total processes:/ {print $NF}'
}
max_active_processes(){
curl -s http://127.0.0.1:8080/php_status|awk '/^max active processes:/ {print $NF}'
}
max_children_reached(){
curl -s http://127.0.0.1:8080/php_status|awk '/^max children reached:/ {print $NF}'
}
case "" in
pool)
pool
;;
process_manager)
process_manager
;;
start_since)
start_since
;;
accepted_conn)
accepted_conn
;;
listen_queue)
listen_queue
;;
max_listen_queue)
max_listen_queue
;;
listen_queue_len)
listen_queue_len
;;
idle_processes)
idle_processes
;;
active_processes)
active_processes
;;
total_processes)
total_processes
;;
max_active_processes)
max_active_processes
;;
max_children_reached)
max_children_reached
;;
*)
echo "Usage:
echo "Usage: $0 {pool|process_manager|start_since|accepted_conn|listen_queue|max_listen_queue|listen_queue_len|idle_processes|active_processes|total_processes|max_active_processes|max_children_reached}"
{pool|process_manager|start_since|accepted_conn|listen_queue|max_listen_queue|listen_queue_len|idle_processes|active_processes|total_processes|max_active_processes|max_children_reached}"esac
3.测试取值
zabbix_get -s 127.0.0.1 -k php-fpm[total_processes]
4.导入模板
5.模板变量
用宏传入
6.更新间隔
更新间隔不能太快,容易造成高负载
d.监控 redis 模板
1.配置文件和脚本
配置文件
#监控redis状态,我们可以根据这个参数对应的监控项创建redis状态触发器。
#redis monitor
UserParameter=redis.status,/usr/local/bin/redis-cli -h 127.0.0.1 -p 6379 -a aosatech ping |grep -c PONG
UserParameter=redis_info[*],/etc/zabbix/scripts/redis_zbx.sh
脚本
注意:REDISPATH="/usr/bin/redis-cli"根据redis-cli命令的位置进行调整!
which redis-cli
#!/bin/bash
REDISPATH="/usr/local/bin/redis-cli"
HOST="127.0.0.1"
PORT="6379"
PASSWORD="aosatech"
REDIS_INFO="$REDISPATH -h $HOST -p $PORT -a $PASSWORD info"
if [[ $# == 1 ]];then
case in
cluster)
result=$($REDIS_INFO|/bin/grep cluster|awk -F":" '{print $NF}')
echo "$result"
;;
uptime_in_seconds)
result=$($REDIS_INFO|/bin/grep uptime_in_seconds|awk -F":" '{print $NF}')
echo "$result"
;;
connected_clients)
result=$($REDIS_INFO|/bin/grep connected_clients|awk -F":" '{print $NF}')
echo "$result"
;;
client_longest_output_list)
result=$($REDIS_INFO|/bin/grep client_longest_output_list|awk -F":" '{print $NF}')
echo "$result"
;;
client_biggest_input_buf)
result=$($REDIS_INFO|/bin/grep client_biggest_input_buf|awk -F":" '{print $NF}')
echo "$result"
;;
blocked_clients)
result=$($REDIS_INFO|/bin/grep blocked_clients|awk -F":" '{print $NF}')
echo "$result"
;;
#内存
used_memory)
result=$($REDIS_INFO|/bin/grep used_memory|awk -F":" '{print $NF}'|awk 'NR==1')
echo "$result"
;;
used_memory_human)
result=$($REDIS_INFO|/bin/grep used_memory_human|awk -F":" '{print $NF}')
echo "$result"
;;
used_memory_rss)
result=$($REDIS_INFO|/bin/grep used_memory_rss|awk -F":" '{print $NF}' | awk 'NR==1')
echo "$result"
;;
used_memory_rss_human)
result=$($REDIS_INFO|/bin/grep used_memory_rss_human |awk -F":" '{print $NF}')
echo "$result"
;;
used_memory_peak)
result=$($REDIS_INFO|/bin/grep used_memory_peak|awk -F":" '{print $NF}'|awk 'NR==1')
echo "$result"
;;
used_memory_peak_human)
result=$($REDIS_INFO|/bin/grep used_memory_peak_human|awk -F":" '{print $NF}')
echo "$result"
;;
used_memory_lua)
result=$($REDIS_INFO|/bin/grep used_memory_lua|awk -F":" '{print $NF}'|awk 'NR==1')
echo "$result"
;;
used_memory_lua_human)
result=$($REDIS_INFO|/bin/grep used_memory_luai_human|awk -F":" '{print $NF}')
echo "$result"
;;
mem_fragmentation_ratio)
result=$($REDIS_INFO|/bin/grep mem_fragmentation_ratio|awk -F":" '{print $NF}')
echo "$result"
;;
#rdb
rdb_changes_since_last_save)
result=$($REDIS_INFO|/bin/grep rdb_changes_since_last_save|awk -F":" '{print $NF}')
echo "$result"
;;
rdb_bgsave_in_progress)
result=$($REDIS_INFO|/bin/grep rdb_bgsave_in_progress|awk -F":" '{print $NF}')
echo "$result"
;;
rdb_last_save_time)
result=$($REDIS_INFO|/bin/grep rdb_last_save_time|awk -F":" '{print $NF}')
echo "$result"
;;
rdb_last_bgsave_status)
result=$($REDIS_INFO|/bin/grep -w "rdb_last_bgsave_status" | awk -F':' '{print }' | /bin/grep -c ok)
echo "$result"
;;
rdb_current_bgsave_time_sec)
result=$($REDIS_INFO|/bin/grep -w "rdb_current_bgsave_time_sec" | awk -F':' '{print }')
echo "$result"
;;
#rdbinfo
aof_enabled)
result=$($REDIS_INFO|/bin/grep -w "aof_enabled" | awk -F':' '{print }')
echo "$result"
;;
aof_rewrite_scheduled)
result=$($REDIS_INFO|/bin/grep -w "aof_rewrite_scheduled" | awk -F':' '{print }')
echo "$result"
;;
aof_last_rewrite_time_sec)
result=$($REDIS_INFO|/bin/grep -w "aof_last_rewrite_time_sec" | awk -F':' '{print }')
echo "$result"
;;
aof_current_rewrite_time_sec)
result=$($REDIS_INFO|/bin/grep -w "aof_current_rewrite_time_sec" | awk -F':' '{print }')
echo "$result"
;;
aof_last_bgrewrite_status)
result=$($REDIS_INFO|/bin/grep -w "aof_last_bgrewrite_status" | awk -F':' '{print }' | /bin/grep -c ok)
echo "$result"
;;
#aofinfo
aof_current_size)
result=$($REDIS_INFO|/bin/grep -w "aof_current_size" | awk -F':' '{print }')
echo "$result"
;;
aof_base_size)
result=$($REDIS_INFO|/bin/grep -w "aof_base_size" | awk -F':' '{print }')
echo "$result"
;;
aof_pending_rewrite)
result=$($REDIS_INFO|/bin/grep -w "aof_pending_rewrite" | awk -F':' '{print }')
echo "$result"
;;
aof_buffer_length)
result=$($REDIS_INFO|/bin/grep -w "aof_buffer_length" | awk -F':' '{print }')
echo "$result"
;;
aof_rewrite_buffer_length)
result=$($REDIS_INFO|/bin/grep -w "aof_rewrite_buffer_length" | awk -F':' '{print }')
echo "$result"
;;
aof_pending_bio_fsync)
result=$($REDIS_INFO|/bin/grep -w "aof_pending_bio_fsync" | awk -F':' '{print }')
echo "$result"
;;
aof_delayed_fsync)
result=$($REDIS_INFO|/bin/grep -w "aof_delayed_fsync" | awk -F':' '{print }')
echo "$result"
;;
#stats
total_connections_received)
result=$($REDIS_INFO|/bin/grep -w "total_connections_received" | awk -F':' '{print }')
echo "$result"
;;
total_commands_processed)
result=$($REDIS_INFO|/bin/grep -w "total_commands_processed" | awk -F':' '{print }')
echo "$result"
;;
instantaneous_ops_per_sec)
result=$($REDIS_INFO|/bin/grep -w "instantaneous_ops_per_sec" | awk -F':' '{print }')
echo "$result"
;;
rejected_connections)
result=$($REDIS_INFO|/bin/grep -w "rejected_connections" | awk -F':' '{print }')
echo "$result"
;;
expired_keys)
result=$($REDIS_INFO|/bin/grep -w "expired_keys" | awk -F':' '{print }')
echo "$result"
;;
evicted_keys)
result=$($REDIS_INFO|/bin/grep -w "evicted_keys" | awk -F':' '{print }')
echo "$result"
;;
keyspace_hits)
result=$($REDIS_INFO|/bin/grep -w "keyspace_hits" | awk -F':' '{print }')
echo "$result"
;;
keyspace_misses)
result=$($REDIS_INFO|/bin/grep -w "keyspace_misses" | awk -F':' '{print }')
echo "$result"
;;
pubsub_channels)
result=$($REDIS_INFO|/bin/grep -w "pubsub_channels" | awk -F':' '{print }')
echo "$result"
;;
pubsub_channels)
result=$($REDIS_INFO|/bin/grep -w "pubsub_channels" | awk -F':' '{print }')
echo "$result"
;;
pubsub_patterns)
result=$($REDIS_INFO|/bin/grep -w "pubsub_patterns" | awk -F':' '{print }')
echo "$result"
;;
latest_fork_usec)
result=$($REDIS_INFO|/bin/grep -w "latest_fork_usec" | awk -F':' '{print }')
echo "$result"
;;
connected_slaves)
result=$($REDIS_INFO|/bin/grep -w "connected_slaves" | awk -F':' '{print }')
echo "$result"
;;
master_link_status)
result=$($REDIS_INFO|/bin/grep -w "master_link_status"|awk -F':' '{print }'|/bin/grep -c up)
echo "$result"
;;
master_last_io_seconds_ago)
result=$($REDIS_INFO|/bin/grep -w "master_last_io_seconds_ago"|awk -F':' '{print $2}')
echo "$result"
;;
master_sync_in_progress)
result=$($REDIS_INFO|/bin/grep -w "master_sync_in_progress"|awk -F':' '{print $2}')
echo "$result"
;;
slave_priority)
result=$($REDIS_INFO|/bin/grep -w "slave_priority"|awk -F':' '{print $2}')
echo "$result"
;;
#cpu
used_cpu_sys)
result=$($REDIS_INFO|/bin/grep -w "used_cpu_sys"|awk -F':' '{print $2}')
echo "$result"
;;
used_cpu_user)
result=$($REDIS_INFO|/bin/grep -w "used_cpu_user"|awk -F':' '{print $2}')
echo "$result"
;;
used_cpu_sys_children)
result=$($REDIS_INFO|/bin/grep -w "used_cpu_sys_children"|awk -F':' '{print $2}')
echo "$result"
;;
used_cpu_user_children)
result=$($REDIS_INFO|/bin/grep -w "used_cpu_user_children"|awk -F':' '{print $2}')
echo "$result"
;;
*)
echo "argu error"
;;
esac
#db0:key
elif [[ $# == 2 ]];then
case $2 in
keys)
result=$($REDIS_INFO| /bin/grep -w "db0"| /bin/grep -w "$1" | /bin/grep -w "keys" | awk -F'=|,' '{print $2}')
echo "$result"
;;
expires)
result=$($REDIS_INFO| /bin/grep -w "db0"| /bin/grep -w "$1" | /bin/grep -w "expires" | awk -F'=|,' '{print $4}')
echo "$result"
;;
avg_ttl)
result=$($REDIS_INFO|/bin/grep -w "db0"| /bin/grep -w "$1" | /bin/grep -w "avg_ttl" | awk -F'=|,' '{print $6}')
echo "$result"
;;
*)
echo "argu error" ;;
esac
fi
2.手动取值
zabbix_get -s 192.168.1.91 -k redis_info[blocked_clients]
3.建立/导入模板
Pass
4.加速
Redis可以用来加速网页访问,但是需要下在php-redis进行连接配置
Pass
Zabbix
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。