Zabbix Monitoring: Setup, Custom Metrics, Automation, and Distributed Deployment

Why Monitoring Matters

Monitoring provides early warnings before servers fail, helps diagnose root causes after incidents, and ensures service availability. High availability (HA) is often measured in "nines" – the percentage of uptime over a year.

1 nine  : (1-90%) * 365 = 36.5 days downtime/year
2 nines : (1-99%) * 365 = 3.65 days
3 nines : (1-99.9%) * 365 * 24 = 8.76 hours
4 nines : (1-99.99%) * 365 * 24 = 52.6 minutes
5 nines : (1-99.999%) * 365 * 24 * 60 = 5.26 minutes
6 nines : (1-99.9999%) * 365 * 24 * 60 * 60 ≈ 31 seconds

What to Monitor

Anything measurable via commands can be monitored: hardware, OS resources, network, applications, and services.

Hardware Monitoring

Remote management cards (Dell iDRAC, HP iLO, IBM IMM) and IPMI tools like ipmitool give hardware-level access:

yum install -y OpenIPMI ipmitool
ipmitool sdr type Temperature

CPU, Memory, Disk, Network

  • CPU: lscpu, uptime, top, vmstat, mpstat
  • Memory: free -h
  • Disk: df -h, dd, iotop
  • Network: iftop, nethogs

Monitoring Tools Overview

  • MRTG – traffic graphs
  • Nagios – alerting
  • Cacti – traffic graphing
  • Zabbix – monitoring + graphing (focus of this article)

Zabbix Architecture

Zabbix (developed by Alexei Vladishev) is a server-client monitoring system. It stores data in MySQL, PostgreSQL, SQLite, Oracle, or IBM DB2. The server is written in C, the web frontend in PHP. It supports:

  • Agentless checks (SNMP, TCP, ICMP, IPMI, SSH, telnet)
  • Agent checks (CPU, memory, disk, network on UNIX/Windows)
  • JMX for Java applications
  • Custom user parameters

Components: Zabbix Server, Zabbix Agent, and optional Zabbix Proxy for distributed environments.

Installing Zabbix

Environment Check

cat /etc/redhat-release   # CentOS Linux release 7.4.1708
uname -r                  # 3.10.0-693.el7.x86_64
getenforce                # Disabled
systemctl status firewalld.service  # inactive

Quick Server Install Script

#!/bin/bash
# Add YUM repos
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

# Install server and web
yum install -y zabbix-server-mysql zabbix-web-mysql mariadb-server
systemctl start mariadb.service

# Create database
mysql -e "CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;"
mysql -e "GRANT ALL ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'zabbix';"

# Import schema
zcat /usr/share/doc/zabbix-server-mysql-3.0.13/create.sql.gz | mysql -uzabbix -pzabbix zabbix

# Configure DB password
sed -i.ori '115a DBPassword=zabbix' /etc/zabbix/zabbix_server.conf

# Set timezone
sed -i.ori '18a php_value date.timezone  Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf

# Fix Chinese font issue
yum -y install wqy-microhei-fonts
cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

# Start services
systemctl start zabbix-server httpd

# Enable at boot
chmod +x /etc/rc.d/rc.local
cat >>/etc/rc.d/rc.local <<eof at="" awk="" echo="" eof="" http:="" httpd="" mariadb.service="" start="" systemctl="" zabbix="" zabbix-server=""></eof>

Quick Agent Install Script

#!/bin/bash
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
yum install -y zabbix-agent
sed -i.ori 's#Server=127.0.0.1#Server=172.16.1.61#' /etc/zabbix/zabbix_agentd.conf
systemctl start zabbix-agent
echo "systemctl start zabbix-agent" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local

Verify Connectivity

Install zabbix-get on the server:

yum install -y zabbix-get
zabbix_get -s 172.16.1.61 -p 10050 -k "system.cpu.load[all,avg1]"

Web Interface Setup

  1. Browse to http://<server-ip>/zabbix/setup.php
  2. Follow steps: check pre-requisites, configure DB connecsion, finish.
  3. Login with Admin / zabbix.

Adding Hosts

  • Modify Zabbix server host: Configuration → Hosts → select "Zabbix server", set visible name, enable.
  • Add new host: Create host, assign template "Template OS Linux", check enabled.

Custom Monitoring and Alerts

Custom User Parameter

Example: monitor number of logged-in users. On agent, create /etc/zabbix/zabbix_agentd.d/userparameter_login.conf:

UserParameter=login.users,who | wc -l

Restart agent and test from server:

zabbix_get -s 172.16.1.21 -p 10050 -k "login.users"

Web Configuration Steps

  1. Create Template: Configuration → Templates → Create template (e.g., "Template Login Users").
  2. Create Application Set: Inside template, create application set (e.g., "Login").
  3. Create Item: Key = "login.users", link to application set.
  4. Create Trigger: Expression like {Template Login Users:login.users.last()}>3 for alarm when more than 3 users.
  5. Create Graph: Display the item history visually.
  6. Link Template to Host: Configuration → Hosts → select host → link this template.

Alerting with OneAlert

  1. Register at OneAlert, create a Zabbix application.
  2. Download agent on server:
cd /usr/local/zabbix-server/share/zabbix/alertscripts
wget http://www.onealert.com/agent/release/oneitsm_zabbix_release-1.0.1.tar.gz
tar -zxf oneitsm_zabbix_release-1.0.1.tar.gz
cd oneitsm/bin
bash install.sh   # follow prompts for Zabbix URL, admin credentials

Once installed, alerts will be sent via WeChat, SMS, etc.

Visualization

  • Screens: Combine multiple graphs into a single screen (Monitoring → Screens).
  • Slide shows: Automatically cycle through screens.

Full Network Monitoring

To 100+ servers, use auto-discovery or auto-registration, and Zabbix API.

Auto-Discovery (Passive)

  1. Configuration → Discovery → Edit "Local network" rule: set IP range, delay.
  2. Create an action: Configuration → Actions → Event source "Discovery". Add condition (e.g., "Service type = Zabbix agent") and operations: Add host, link template.

Auto-Registration (Active)

  1. On agent, set ServerActive=172.16.1.61 and HostnameItem=system.hostname.
  2. On server, create action with event source "Auto registration". Operations: Add host, link template.

Zabbix API for Bulk Operations

# Login
curl -i -X POST -H 'Content-Type:application/json' -d '{
  "jsonrpc":"2.0",
  "method":"user.login",
  "params":{"user":"Admin","password":"zabbix"},
  "auth":null,
  "id":0
}' "http://10.0.0.61/zabbix/api_jsonrpc.php"

# Get hosts
curl -i -X POST -H 'Content-Type:application/json' -d '{
  "jsonrpc":"2.0",
  "method":"host.get",
  "params":{"output":["hostid","host"],"selectInterfaces":["interfaceid","ip"]},
  "id":2,
  "auth":"<AUTH_TOKEN>"
}' "http://10.0.0.61/zabbix/api_jsonrpc.php"

Monitoring Specific Services

Service Method Key Example
Backup (rsync) Port check net.tcp.port[,873]
NFS Process count proc.num[nfsd]
MySQL Port or custom key net.tcp.port[,3306]
Web (HTTP) Port or web scenario net.tcp.port[,80] or Zabbix web monitoring
Nginx status Custom keys (stub_status) Parse curl 127.0.0.1/status
Keepalived VIP Custom key ip a | grep 10.0.0.3 | wc -l

Distributed Monitoring with Proxy

Use Zabbix Proxy to offload the server and monitor remote sites.

Setup Proxy (cache01)

yum install -y zabbix-proxy-mysql mariadb-server
systemctl start mariadb.service
mysql -e "CREATE DATABASE zabbix_proxy CHARACTER SET utf8 COLLATE utf8_bin;"
mysql -e "GRANT ALL ON zabbix_proxy.* TO zabbix@localhost IDENTIFIED BY 'zabbix';"
zcat /usr/share/doc/zabbix-proxy-mysql-3.0.13/schema.sql.gz | mysql -uzabbix -pzabbix zabbix_proxy
sed -i.ori '162a DBPassword=zabbix' /etc/zabbix/zabbix_proxy.conf
sed -i 's#Server=127.0.0.1#Server=172.16.1.61#' /etc/zabbix/zabbix_proxy.conf
sed -i 's#Hostname=Zabbix proxy#Hostname=cache01#' /etc/zabbix/zabbix_proxy.conf
systemctl restart zabbix-proxy

Point agents to proxy by changing Server and ServerActive in agent config to proxy IP. Add proxy in Zabbix web: Administration → Proxies → Create proxy (name must match Hostname).

SNMP Monitoring

For devices that cannot run Zabbix agent (switches, routers), use SNMP.

yum install -y net-snmp net-snmp-utils
sed -i.ori '57a view systemview included .1' /etc/snmp/snmpd.conf
systemctl start snmpd.service

# Test
snmpwalk -v 2c -c public 127.0.0.1 sysname

In Zabbix web, add host with SNMP interface and link SNMP-related templates (e.g., "Template SNMP OS").

Tags

Zabbix, monitoring, SNMP, distributed monitoring, auto-discovery, auto-registration, user parameter, alerting

Tags: Zabbix monitoring SNMP distributed monitoring auto-discovery

Posted on Mon, 01 Jun 2026 18:30:40 +0000 by Cheap Commercial