← All Articles

Keep an eye on your servers - Part I

Siavash KhalvatiSiavash Khalvati
Jun 22nd 17Updated Jul 7th 22
Open Source

monitoring-your-apps-with-zabbix-and-cloud66-containers

As you may know, there are thousands of monitoring systems out there which may make it difficult to choose one. Since this is for DIY purpose I've chosen Zabbix for it is light and powerful.

Zabbix is an enterprise open source monitoring software for networks and applications, created by Alexei Vladishev. It is designed to monitor and track the status of various network services, servers, and other network hardware.

Zabbix uses MySQL, PostgreSQL, SQLite, Oracle or IBM DB2 to store data. Its backend is written in C and the web frontend is written in PHP. Zabbix offers several monitoring options:

  • Simple checks can verify the availability and responsiveness of standard services such as SMTP or HTTP without installing any software on the monitored host.
  • A Zabbix agent can also be installed on UNIX and Windows hosts to monitor statistics such as CPU load, network utilization, disk space, etc.
  • As an alternative to installing an agent on hosts, Zabbix includes support for monitoring via SNMP, TCP and ICMP checks, as well as over IPMI, JMX, SSH, Telnet and using custom parameters. Zabbix supports a variety of near-real-time notification mechanisms, including XMPP

Today I'm going to demonstrate how to built Zabbix using our docker stacks to reduce the cost of creating a new stack and having the flexibility of upgrading without having to go through the setup on a new server.

As I mentioned Zabbix can be set up using MySQL, PostgreSQL, SQLite, Oracle or IBM DB2 for its database.

I'm going to simply add the server first, one with MYSQL and one with PostgreSQL, so if you have an already running docker stack with any of those databases you'd be able to add it to your stack, or if you are more familiar with one of them you'll be able to proceed.

MySQL:

These are my assumptions:

  1. Zabbix db is: zabbix
  2. Stack's mysql user has access to this db
  3. The web interface is listening on port 82 for http and 444 on https.

To achieve these assumptions you need to find DB admin username

and run this on the MySQL server:

echo "CREATE DATABASE IF NOT EXISTS zabbix;" | mysql -u -p echo "GRANT ALL PRIVILEGES ON zabbix.* TO $MYSQL_USERNAME;" | mysql -u -p

Note:

there shouldn't be any space between -p and <DB Admin Password>

#...
  #YOUR CURRENT SERVICES
  #...
  zabbix-server-mysql:
    image: zabbix/zabbix-server-mysql:ubuntu-latest
    ports:
    - container: 10051
      tcp: 10051
    env_vars:
      DB_SERVER_HOST: _env(DOCKER_HOST_IP)
      MYSQL_DATABASE: zabbix
      MYSQL_USER: _env(MYSQL_USERNAME)
      MYSQL_PASSWORD: _env(MYSQL_PASSWORD)
  zabbix-web-nginx-mysql:
    image: zabbix/zabbix-web-nginx-mysql:ubuntu-latest
    ports:
    - container: 80
      http: 83
      https: 444
    env_vars:
      DB_SERVER_HOST: _env(DOCKER_HOST_IP)
      MYSQL_DATABASE: zabbix
      ZBX_SERVER_HOST: zabbix-server-mysql.cloud66.local
      MYSQL_USER: _env(MYSQL_USERNAME)
      MYSQL_PASSWORD: _env(MYSQL_PASSWORD)
databases:
- mysql

PostgreSQL:

  1. Zabbix db is: zabbix
  2. Stack's PostgreSQL user has access to this db
  3. The web interface is listening on port 82 for http and 444 on https.

To achieve these assumptions you need to create the zabbix database first:

so please run this on the PostgreQSL server:

first check if zabbix db exist by running:
echo "\l" | sudo -u postgres psql

and then if not, run the following command to create one:
sudo -u postgres createdb zabbix

#...
    #YOUR CURRENT SERVICES
    #...
    zabbix-server-pgsql:
      image: zabbix/zabbix-server-pgsql:ubuntu-latest
      ports:
      - container: 10051
        tcp: 10051
      env_vars:
        DB_SERVER_HOST: _env(POSTGRESQL_ADDRESS)
        POSTGRES_USER: _env(POSTGRESQL_USERNAME)
        POSTGRES_PASSWORD: _env(POSTGRESQL_PASSWORD)
        POSTGRES_DB: zabbix
    zabbix-web-nginx-pgsql:
      image: zabbix/zabbix-web-nginx-pgsql:ubuntu-latest
        ports:
        - container: 80
          http: 83
          https: 444
      env_vars:
        ZBX_SERVER_HOST: zabbix-server-pgsql.cloud66.local
        DB_SERVER_HOST: _env(POSTGRESQL_ADDRESS)
        POSTGRES_USER: _env(POSTGRESQL_USERNAME)
        POSTGRES_PASSWORD: _env(POSTGRESQL_PASSWORD)
        POSTGRES_DB: zabbix
    databases:
    - postgresql

This is now only to install Zabbix and not how to use it. I'll cover that gradually.


Try Cloud 66 for Free, No credit card required