Skip to content

Zabbix

Zabbix is a flexible monitoring solution for networks, servers, virtual machines, and cloud services with advanced alerting and reporting.

Installation

Ubuntu/Debian

# Add Zabbix repository
wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-1+ubuntu$(lsb_release -rs)_all.deb
sudo dpkg -i zabbix-release_6.0-1+ubuntu*.deb
sudo apt update

# Install Zabbix server
sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-agent

# Database setup (MySQL)
sudo mysql -e "CREATE DATABASE zabbix CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;"
sudo mysql -e "CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'password';"
sudo mysql -e "GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';"
sudo zcat /usr/share/zabbix-server-mysql/schema.sql.gz | mysql -uzabbix -p zabbix

# Start services
sudo systemctl start zabbix-server-mysql zabbix-agent apache2
sudo systemctl enable zabbix-server-mysql zabbix-agent apache2

# Access: http://localhost/zabbix
# Default: Admin / zabbix

Docker Deployment

docker run -d \
  --name zabbix-server \
  -p 10051:10051 \
  -p 80:80 \
  -e DB_SERVER_HOST="mysql" \
  -e MYSQL_DATABASE="zabbix" \
  -e MYSQL_USER="zabbix" \
  -e MYSQL_PASSWORD="password" \
  zabbix/zabbix-server-mysql:6.0-latest

Agent Installation

Zabbix Agent (zabbix_agentd)

# Ubuntu/Debian
sudo apt install zabbix-agent

# Edit configuration
sudo vim /etc/zabbix/zabbix_agentd.conf
# Key settings:
# Server=192.168.1.10      # Zabbix server IP
# ListenIP=0.0.0.0
# Hostname=server-name
# EnableRemoteCommands=1

# Start agent
sudo systemctl restart zabbix-agent
sudo systemctl enable zabbix-agent

# Test connectivity
sudo zabbix_agentd -t system.uname

Agent 2 (Newer, modular)

# Install Agent 2
wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix/zabbix-agent2_6.0.0-1+ubuntu20.04_amd64.deb
sudo dpkg -i zabbix-agent2_6.0.0*.deb

# Configuration
sudo vim /etc/zabbix/zabbix_agent2.conf

# Plugins available
sudo zabbix-agent2 -h

Host Management

Add Host via Web Interface

1. Configuration > Hosts > Create Host
2. Name: "web-server-01"
3. Groups: "Web servers"
4. Agent interfaces: 192.168.1.10:10050
5. Create templates

Add Host via API

# Get API token
curl -s -X POST "http://localhost/api_jsonrpc.php" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
      "username": "Admin",
      "password": "zabbix"
    },
    "auth": null,
    "id": 1
  }' | jq '.result'

# Create host
curl -s -X POST "http://localhost/api_jsonrpc.php" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
      "host": "web-server-01",
      "groups": [{"groupid": "2"}],
      "interfaces": [{
        "type": 1,
        "main": 1,
        "useip": 1,
        "ip": "192.168.1.10",
        "dns": "",
        "port": "10050"
      }]
    },
    "auth": "$TOKEN",
    "id": 1
  }' | jq '.'

Items and Metrics

Create Items via Web Interface

1. Configuration > Hosts > Select Host > Items > Create Item
2. Name: "CPU Usage"
3. Type: "Zabbix agent"
4. Key: "processor.load[all,avg1]"
5. Update interval: "30s"
6. Create

Common Item Keys

# System metrics
system.cpu.load             # CPU load
system.cpu.num              # CPU count
system.memory.used          # Memory usage
system.disk.used[/]         # Disk usage
system.uptime               # System uptime
system.hostname             # Hostname

# Agent metrics
agent.ping                  # Agent connectivity
agent.version               # Agent version
net.tcp.listen[port]        # Port listening check

# Process metrics
proc.num[name]              # Process count
proc.mem[name]              # Process memory

Low-Level Discovery (LLD)

{
  "data": [
    {"{#DISKNAME}": "sda1", "{#DISKTYPE}": "ssd"},
    {"{#DISKNAME}": "sdb1", "{#DISKTYPE}": "hdd"}
  ]
}

Triggers and Alerts

Create Trigger

# Trigger for high CPU
Name: "CPU usage > 80%"
Expression: {server:processor.load[all,avg1].last()}>0.8
Severity: Average
Recovery expression: {server:processor.load[all,avg1].last()}<0.7

# Disk space alert
Name: "Low disk space"
Expression: {server:vfs.fs.used[/].last()}/{server:vfs.fs.total[/].last()}*100>80
Severity: Critical

# Service down alert
Name: "HTTP service down"
Expression: {server:net.tcp.listen[80].last()}=0
Severity: Critical

Trigger Severity Levels

  • Not classified (gray)
  • Information (blue)
  • Warning (yellow)
  • Average (orange)
  • High (red)
  • Disaster (dark red)

Templates

Using Templates

1. Configuration > Templates > Select Template
2. Link to Host: select hosts to apply template
3. Apply

# Common templates:
- Template OS Linux
- Template App HTTP Service
- Template App MySQL
- Template App Redis

Create Custom Template

# Template structure
Name: "Template App Custom"
Groups: "Application templates"

Items:
- Name: "Custom metric 1"
  Key: "custom.metric"
  Type: "Zabbix agent"
  Update interval: "30s"

Triggers:
- Name: "Metric threshold exceeded"
  Expression: {Template App Custom:custom.metric.last()}>100

Notifications

Configure Email Notifications

1. Administration > Media types > Email
2. SMTP server: mail.example.com
3. SMTP port: 587
4. From address: zabbix@example.com
5. Test email

6. Administration > Users > Admin > Media
7. Add media type: Email
8. Send to: admin@example.com

Action Configuration

1. Configuration > Actions > Event source: Triggers
2. Create action:
   - Name: "Alert on trigger"
   - Enabled: Yes
   - Conditions: Trigger severity >= Average
   - Operations:
     * Send to user group: "Administrators"
     * Default message: Problem notification
     * Recovery operations: Recovery notification

Dashboards & Visualization

Create Dashboard

1. Dashboards > Create dashboard
2. Name: "Operations Dashboard"
3. Add widgets:
   - Graph: CPU Usage
   - Graph: Memory Usage
   - Map: Network topology
   - Top Hosts: By CPU
   - Problems: Unresolved

Graphs and Charts

# Graph configuration
Name: "Server Performance"
Width: 900
Height: 200
Graph items:
- Item: processor.load[all,avg1] (line)
- Item: system.memory.pused (area)
- Item: vfs.fs.used[/,pused] (bar)

API Examples

Get Problems (Alerts)

curl -s -X POST "http://localhost/api_jsonrpc.php" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "problem.get",
    "params": {
      "output": ["eventid", "clock", "severity"],
      "filter": {"severity": [4, 5]},
      "sortfield": ["clock"],
      "limit": 100
    },
    "auth": "$TOKEN",
    "id": 1
  }' | jq '.result'

Get Host Data

curl -s -X POST "http://localhost/api_jsonrpc.php" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
      "output": ["hostid", "name", "status"],
      "search": {"name": "web-server"}
    },
    "auth": "$TOKEN",
    "id": 1
  }' | jq '.result'

Get Latest Item Values

curl -s -X POST "http://localhost/api_jsonrpc.php" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "history.get",
    "params": {
      "output": "extend",
      "itemids": "23456",
      "limit": 10,
      "sortfield": "clock",
      "sortorder": "DESC"
    },
    "auth": "$TOKEN",
    "id": 1
  }' | jq '.result'

Maintenance & Troubleshooting

Service Management

# Check service status
sudo systemctl status zabbix-server-mysql

# View logs
sudo tail -f /var/log/zabbix/zabbix_server.log

# Database maintenance
sudo mysql -uzabbix -p zabbix < /usr/share/zabbix-server-mysql/schema.sql

# Test agent
zabbix_get -s 192.168.1.10 -k system.uptime

Performance Tuning

# /etc/zabbix/zabbix_server.conf
CacheSize=32M
HistoryCacheSize=16M
TrendCacheSize=4M
TextLogRotationSize=104857600
MaxHousekeeperDelete=5000

Best Practices

  • Use templates to standardize monitoring across hosts
  • Set appropriate update intervals (critical: 10s, standard: 30-60s)
  • Configure maintenance windows for planned downtime
  • Use host groups and templates for scalability
  • Enable problem acknowledgement and comments
  • Archive old data to manage database size
  • Configure backup/redundancy for high availability
  • Monitor Zabbix server itself
  • Use maps and dashboards for visualization
  • Implement role-based access control