# Zabbix Monitoring Stack

> Zabbix monitoring with PostgreSQL and web frontend.

- Category: Monitoring & Observability
- Difficulty: intermediate
- Components: zabbix-server, zabbix-web, zabbix-agent, postgresql
- Tags: zabbix, monitoring, alerting, infrastructure, postgresql
- Source: https://docker.recipes/monitoring/zabbix-monitoring

## Overview

Zabbix is an enterprise-class open-source monitoring solution that has been actively developed since 2001, designed to monitor networks, servers, virtual machines, and cloud services. It provides real-time monitoring, alerting, and visualization capabilities with support for thousands of devices and metrics, making it a comprehensive infrastructure monitoring platform used by organizations worldwide. This deployment creates a complete Zabbix monitoring environment using four interconnected containers: a PostgreSQL database for storing configuration and metrics data, the Zabbix server daemon for data collection and processing, a web frontend with embedded Nginx for the user interface, and a Zabbix agent for monitoring the Docker host itself. The stack uses PostgreSQL as the backend database, providing robust data integrity and performance for storing the extensive monitoring data that Zabbix collects. This configuration is ideal for system administrators and DevOps teams who need a professional-grade monitoring solution that can scale from small environments to enterprise infrastructures, offering both agentless and agent-based monitoring with flexible alerting mechanisms and comprehensive reporting capabilities.

## Features

- Real-time monitoring with customizable data collection intervals from seconds to hours
- Multi-tier alerting system with escalation policies and multiple notification channels
- Template-based configuration system for rapid deployment of monitoring across similar hosts
- Network discovery capabilities for automatic detection and monitoring of network devices
- Built-in graphing engine with trend analysis and forecasting functions
- Low-level discovery rules for automatic monitoring of dynamic resources like filesystems and network interfaces
- Web-based administration interface with role-based access control and user management
- PostgreSQL backend providing ACID compliance and efficient storage of time-series monitoring data

## Use cases

- Enterprise infrastructure monitoring across physical, virtual, and cloud environments
- Network operations center (NOC) deployments requiring centralized monitoring dashboards
- DevOps teams implementing comprehensive observability for application and infrastructure stacks
- Managed service providers offering monitoring services to multiple clients with tenant isolation
- IT departments transitioning from legacy monitoring tools to a unified open-source solution
- Compliance-driven environments requiring detailed audit trails and performance documentation
- High-availability service monitoring with automatic failover detection and alerting

## Prerequisites

- Docker and Docker Compose installed with at least 2GB available RAM for optimal performance
- Port 8080 available for web interface and port 10051 for Zabbix server communication
- Basic understanding of monitoring concepts like hosts, items, triggers, and templates
- Network access from monitored systems to the Zabbix server on port 10051
- Understanding of PostgreSQL basics for database maintenance and backup procedures
- Familiarity with SNMP, SSH, or agent-based monitoring depending on your target systems

## docker-compose.yml

```yaml
services:
  postgres:
    image: postgres:16-alpine
    container_name: zabbix-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-zabbix}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-zabbix}
      POSTGRES_DB: ${POSTGRES_DB:-zabbix}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - zabbix-network

  zabbix-server:
    image: zabbix/zabbix-server-pgsql:latest
    container_name: zabbix-server
    restart: unless-stopped
    ports:
      - "10051:10051"
    environment:
      - DB_SERVER_HOST=postgres
      - POSTGRES_USER=${POSTGRES_USER:-zabbix}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-zabbix}
      - POSTGRES_DB=${POSTGRES_DB:-zabbix}
    depends_on:
      - postgres
    networks:
      - zabbix-network

  zabbix-web:
    image: zabbix/zabbix-web-nginx-pgsql:latest
    container_name: zabbix-web
    restart: unless-stopped
    ports:
      - "${WEB_PORT:-8080}:8080"
    environment:
      - DB_SERVER_HOST=postgres
      - POSTGRES_USER=${POSTGRES_USER:-zabbix}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-zabbix}
      - POSTGRES_DB=${POSTGRES_DB:-zabbix}
      - ZBX_SERVER_HOST=zabbix-server
      - PHP_TZ=${TZ:-UTC}
    depends_on:
      - postgres
      - zabbix-server
    networks:
      - zabbix-network

  zabbix-agent:
    image: zabbix/zabbix-agent:latest
    container_name: zabbix-agent
    restart: unless-stopped
    environment:
      - ZBX_SERVER_HOST=zabbix-server
    depends_on:
      - zabbix-server
    networks:
      - zabbix-network

volumes:
  postgres_data:

networks:
  zabbix-network:
    driver: bridge
```

## .env

```bash
# Zabbix
WEB_PORT=8080
POSTGRES_USER=zabbix
POSTGRES_PASSWORD=zabbix
POSTGRES_DB=zabbix
TZ=UTC
```

## Usage notes

- Zabbix at http://localhost:8080
- Default login: Admin/zabbix
- Change password on first login
- Deploy agents on monitored hosts

## Troubleshooting

- Zabbix server container fails to start: Check PostgreSQL container is healthy and database credentials match between postgres and zabbix-server services
- Web interface shows database connection errors: Verify POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DB environment variables are consistent across zabbix-web and postgres services
- Cannot access web interface at localhost:8080: Ensure WEB_PORT environment variable is set correctly and no other service is using the configured port
- Zabbix agent not appearing in web interface: Check that zabbix-agent container can resolve zabbix-server hostname and verify ZBX_SERVER_HOST environment variable
- High memory usage in postgres container: Monitor postgres_data volume size and implement data housekeeping policies in Zabbix administration settings
- Zabbix server reports database connection timeouts: Increase PostgreSQL max_connections setting and ensure adequate resources are allocated to postgres container

