Monitoring Applications and Services on Linux with Zabbix Agent

Zabbix application provides lots of templates to integrate those popular software into their monitoring system.  https://www.zabbix.com/integrations privides the list and in this post, I will show a detailed steps regarding how to integrate some Linux popular services or applications into Zabbix. 

 

MySQL

Add mysql related template based on your agent type, either agent or agent 2 or agent active:

After added it in, then click the template "MySQL by Zabbix agent" to get more info:

Template info:

Here is the copy of Requirements for template operation:

1. Install Zabbix agent and MySQL client. If necessary, add the path to the 'mysql' and 'mysqladmin' utilities to the global environment variable PATH.
2. Copy the 'template_db_mysql.conf' file with user parameters into folder with Zabbix agent configuration (/etc/zabbix/zabbix_agentd.d/ by default). Don't forget to restart Zabbix agent.
3. Create the MySQL user that will be used for monitoring ('<password>' at your discretion). For example:
CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY '<password>';
GRANT REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%';
For more information, please see MySQL documentation (https://dev.mysql.com/doc/refman/8.0/en/grant.html).
NOTE: In order to collect replication metrics, MariaDB Enterprise Server 10.5.8-5 and above and MariaDB Community Server 10.5.9 and above require the SLAVE MONITOR privilege to be set for the monitoring user:
GRANT REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW,SLAVE MONITOR ON *.* TO 'zbx_monitor'@'%';
For more information, please read the MariaDB documentation (https://mariadb.com/docs/server/ref/mdb/privileges/SLAVE_MONITOR/).
4. Create '.my.cnf' configuration file in the home directory of Zabbix agent for Linux distributions (/var/lib/zabbix by default) or 'my.cnf' in c:/ for Windows. For example:
[client]
protocol=tcp
user='zbx_monitor'
password='<password>'
For more information, please see MySQL documentation (https://dev.mysql.com/doc/refman/8.0/en/option-files.html).
NOTE: Linux distributions that use SELinux may require additional steps for access configuration.
You can discuss this template or leave feedback on our forum https://www.zabbix.com/forum/zabbix-suggestions-and-feedback/384189-discussion-thread-for-official-zabbix-template-db-mysql
Generated by official Zabbix template tool "Templator"

This description of template also can be found from :

  • https://www.zabbix.com/integrations/mysql

or Github page: 

  • https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/db/mysql_agent?at=refs%2Fheads%2Frelease%2F7.4

mysqladmin -h <remote_host_ip_or_hostname> -u <username> -p<password> <command>
  • -h <remote_host_ip_or_hostname>
    Specifies the hostname or IP address of the remote MySQL server.
  • -u <username>
    Specifies the username to connect to the MySQL server. This user must have the necessary privileges on the remote server to perform the desired operations and must be configured to allow remote connections.
  • -p<password>
    Specifies the password for the given username. Note that there is no space between -p and the password. If you omit the password after -pmysqladmin will prompt you for it interactively, which is generally more secure.
  • <command>
    This is the mysqladmin command you want to execute on the remote server, such as statusversionpingshutdown, etc.

Monitor Services guacd

Make sure you have this line exactly in your Zabbix agent config file (/etc/zabbix/zabbix_agentd.conf):

text
UserParameter=service.status.guacd,systemctl is-active guacd.service
  1. Restart Zabbix agent

After editing the config, restart the agent to apply changes:

bash
sudo systemctl restart zabbix-agent
  1. Test the key locally

Run the key test on the monitored Linux host to make sure the agent can execute it properly:

bash
zabbix_agentd -t service.status.guacd

You should see output like:

text
service.status.guacd [t|active]
Step Example
UserParameter UserParameter=service.status.guacd,systemctl is-active guacd.service
Item key service.status.guacd
Trigger expression {hostname:service.status.guacd.str()}<>"active"
Process monitoring key proc.num[guacd]

CPU usage

Create item:

  • Name: guacd: CPU usage

  • Type: Zabbix agent

  • Key:

    proc.cpu.util[guacd,,]
  • Units: %

  • Type of information: Float


Memory usage

Create item:

  • Name: guacd: Memory usage

  • Key:

    proc.mem[guacd]
  • Units: B (or bytes)

  • Type: Numeric


Process count

proc.num[guacd]

Troubleshooting

 

The "Unsupported item key" message for your service.status.guacd item means Zabbix agent does not recognize the key as configured. This usually happens when:

  1. The UserParameter was not correctly added or the agent was not restarted.

  2. The key was mistyped or not listed in the agent config.

  3. The command in the UserParameter returns no output or errors.

Troubleshooting Steps

  1. Verify UserParameter in agent config

Make sure you have this line exactly in your Zabbix agent config file (/etc/zabbix/zabbix_agentd.conf):

text
UserParameter=service.status.guacd,systemctl is-active guacd.service
  1. Restart Zabbix agent

After editing the config, restart the agent to apply changes:

bash
sudo systemctl restart zabbix-agent
  1. Test the key locally

Run the key test on the monitored Linux host to make sure the agent can execute it properly:

bash
zabbix_agentd -t service.status.guacd

You should see output like:

text
service.status.guacd [t|active]

If you get an error or no output, fix the UserParameter command or permissions.

  1. Check command permissions

If the agent runs as a non-root user, ensure it has permissions to run systemctl is-active guacd.service. You might need to allow the command without a password in sudoers or adjust permissions.

Example if sudo is required, modify UserParameter:

text
UserParameter=service.status.guacd,sudo systemctl is-active guacd.service

And configure /etc/sudoers accordingly:

text
zabbix ALL=NOPASSWD: /bin/systemctl is-active guacd.service
  1. Validate item key in Zabbix

Ensure the item key in Zabbix frontend matches service.status.guacd exactly, including no trailing spaces.

These should resolve the Unsupported item key issue for your guacd service status check.

Videos

 

References

版权声明:
作者:玉兰
链接:https://www.techfm.club/p/226795.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>