Hi all,
I'm new to the forum so please forgive me if I break any rules.
Currently we are in effort to monitor microservices using Zabbix. The scenario is that many instance of same application(Java) can run in same machine and when these instance comes up this has to be monitored by Zabbix without manually creating host in Zabbix. Our Java application runs in docker container, this application also have metrics that will be exposed through JMX and monitored in Zabbix.
We tried with Low Level Discovery but this would just allow me to have dynamic items/triggers but really what we would need is another JMX interface for each port to be created for each instance. There could be scenarios where we will run multiple instance on same host.
Below is one of the way which I tried, and it worked. Although it worked I haven't tested in all cases and I am not sure if this is perfect solution to deal this scenario since I started learning Zabbix few weeks back also I am looking for a more generic way from Zabbix side for doing this. If someone have any idea better than this please help me out.
Zabbix version - 3.0
Create a discovery shell script that will monitor with (ps -ef | grep ${SEARCH_PAT} | grep -Po ${REGEXP_PAT} | tail) command to check if any process comes up. This script will ouput service name and service port(JMX port) in JSON. I have item prototype attached to this discovery script which will create actual item. This item will call user defined script in the monitored host and creates host and apply given template to it. By this way I will create discovery rule for each service.
Discovery script : Key : discover.services[ProcessName]
//arg1 - process name to search
UserParameter.conf : UserParameter=discover.services[*],/var/lib/zabbix/discover_services.sh "$1"
Output of userparameter script: {"data":[ {"{#SERVICE_NAME}":"ItemName","{#SERVICE_SEARCH_PA TTERN1}":"ProcessName","{#SERVICE_PORT}":"10051"} ]}
Item prototype : create.host[{HOST.IP},{HOST.NAME},{#SERVICE_PORT},DMP_Servers, DMP_HTTP_Receiver1,HTTPReceiver]
// arg1 - hostip for jmx interface in newly created host
// arg2 - hostname - going to be the newly created hostname. Hostname format - Hostname+"_"+ProcessName+"_"Port
// arg3 - jmx interface port for monitoring
// arg4 - groupname
// arg5 - templatename that has to be applied for the newly created host
// arg6 - Process Name
UserParameter.conf : UserParameter=create.host[*],python /var/lib/zabbix/bin/hostadd.py "$1" "$2" "$3" "$4" "$5" "$6"
/var/lib/zabbix/bin/hostadd.py python script will first authenticate itself and gets a authorization key which will be used for following API calls.
Get the group id from given group name.
Get the template id from given template name and create new host with groupid and templateid.
*This python script uses Zabbix API to get all details required and to add host.
*It seems we can't have multiple requests in single api call to fetch all details. So each api call will be called seperately.
I'm new to the forum so please forgive me if I break any rules.
Currently we are in effort to monitor microservices using Zabbix. The scenario is that many instance of same application(Java) can run in same machine and when these instance comes up this has to be monitored by Zabbix without manually creating host in Zabbix. Our Java application runs in docker container, this application also have metrics that will be exposed through JMX and monitored in Zabbix.
We tried with Low Level Discovery but this would just allow me to have dynamic items/triggers but really what we would need is another JMX interface for each port to be created for each instance. There could be scenarios where we will run multiple instance on same host.
Below is one of the way which I tried, and it worked. Although it worked I haven't tested in all cases and I am not sure if this is perfect solution to deal this scenario since I started learning Zabbix few weeks back also I am looking for a more generic way from Zabbix side for doing this. If someone have any idea better than this please help me out.
Zabbix version - 3.0
Create a discovery shell script that will monitor with (ps -ef | grep ${SEARCH_PAT} | grep -Po ${REGEXP_PAT} | tail) command to check if any process comes up. This script will ouput service name and service port(JMX port) in JSON. I have item prototype attached to this discovery script which will create actual item. This item will call user defined script in the monitored host and creates host and apply given template to it. By this way I will create discovery rule for each service.
Discovery script : Key : discover.services[ProcessName]
//arg1 - process name to search
UserParameter.conf : UserParameter=discover.services[*],/var/lib/zabbix/discover_services.sh "$1"
Output of userparameter script: {"data":[ {"{#SERVICE_NAME}":"ItemName","{#SERVICE_SEARCH_PA TTERN1}":"ProcessName","{#SERVICE_PORT}":"10051"} ]}
Item prototype : create.host[{HOST.IP},{HOST.NAME},{#SERVICE_PORT},DMP_Servers, DMP_HTTP_Receiver1,HTTPReceiver]
// arg1 - hostip for jmx interface in newly created host
// arg2 - hostname - going to be the newly created hostname. Hostname format - Hostname+"_"+ProcessName+"_"Port
// arg3 - jmx interface port for monitoring
// arg4 - groupname
// arg5 - templatename that has to be applied for the newly created host
// arg6 - Process Name
UserParameter.conf : UserParameter=create.host[*],python /var/lib/zabbix/bin/hostadd.py "$1" "$2" "$3" "$4" "$5" "$6"
/var/lib/zabbix/bin/hostadd.py python script will first authenticate itself and gets a authorization key which will be used for following API calls.
Get the group id from given group name.
Get the template id from given template name and create new host with groupid and templateid.
*This python script uses Zabbix API to get all details required and to add host.
*It seems we can't have multiple requests in single api call to fetch all details. So each api call will be called seperately.
Comment