前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >zabbix自动发现模板编写

zabbix自动发现模板编写

作者头像
@凌晨
发布2022-08-28 14:06:38
3950
发布2022-08-28 14:06:38
举报
文章被收录于专栏:Man_Docker

1、监控服务端口配置文件:

UserParameter=im.port.discovery,/bin/bash /data/scripts/process_discovery.sh

代码语言:javascript
复制
监控端口的脚本:
cat /data/scripts/process_discovery.sh

#!/bin/bash
process_discovery () {
  process=($(cat /data/scripts/process.txt))
  printf '{\n'
  printf '\t"data":[\n'
  for((i=0;i<${#process[@]};++i))
  {
    num=$(echo $((${#process[@]}-1)))
    if [ "$i" != ${num} ];then
      printf "\t\t{ \n"
      port=`echo ${process[$i]}|awk -F "," '{print $2}'`
      process_name=`echo ${process[$i]}|awk -F "," '{print $1}'`
      printf "\t\t\t\"{#PORT}\":\"$port\",\n"
      printf "\t\t\t\"{#PROCESS_NAME}\":\"$process_name\"\n"
      printf "\t\t},\n"
    else
      printf "\t\t{ \n"
      port=`echo ${process[$i]}|awk -F "," '{print $2}'`
      process_name=`echo ${process[$i]}|awk -F "," '{print $1}'`
      printf "\t\t\t\"{#PORT}\":\"$port\",\n"
      printf "\t\t\t\"{#PROCESS_NAME}\":\"$process_name\"\n"
      printf "\t\t}\n"
      printf "]\n"
      printf "}\n"
    fi
  }
}
process_discovery

cat /data/scripts/process.txt
jenkins,8080

执行结果:
/bin/bash /data/scripts/process_discovery.sh

{
  "data":[
    { 
      "{#PORT}":"8080",
      "{#PROCESS_NAME}":"jenkins"
    }
]
}

2、监控服务端置文件:

UserParameter=process.discovery,/bin/bash /data/scripts/pro_discovery.sh

UserParameter=pro.check[*],ps -ef|grep -w $1|grep -v grep|wc -l

代码语言:javascript
复制
监控服务的脚本:
cat /data/scripts/pro_discovery.sh

#!/bin/bash
process_discovery () {
  process=($(cat /data/scripts/pro.config))
  printf '{\n'
  printf '\t"data":[\n'
  for((i=0;i<${#process[@]};++i))
  {
    num=$(echo $((${#process[@]}-1)))
    if [ "$i" != ${num} ];then
      printf "\t\t{ \n"
      printf "\t\t\t\"{#PROCESS}\":\"${process[$i]}\"},\n"
    else
      printf "\t\t{ \n"
      #printf "\t\t \n"
      printf "\t\t\t\"{#PROCESS}\":\"${process[$i]}\"}\n"
      printf "]\n"
      printf "}\n"
    fi
  }
}
process_discovery $1

cat /data/scripts/pro.config
/data2/java/servers/web_newuploadsystem_9070/conf/logging.properties

zabbix配置截图:

   =====

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档