Use Grafana and Zabbix containers

create zabbix and grafana containers

hrk1l2x

3 minute read

Use Grafana and Zabbix container

this time, launch Zabbix and Grafana container and Grafana cooperate with Zabbix.

env

  • MacOS X
  • Docker version 18.06.1-ce, build e68fc7a
  • Grafana v5.2.4 (commit: 0bbac5c)

realization

  • launch Zabbix and Grafana container.
  • Grafana use MySQL not Sqlite3 (Volume)
  • the datasource, dashboard, plugin files can be set at build time to pass container.

SQLite3

  • dashboard files which registered with SQLite3 are stored on /var/lib/grafana. configuration files are stored in /etc/grafana.

docker-compose.yaml

    .
    ├── data
    │   ├── mysql
    │   └── zabbix
    ├── docker-compose.yaml
    ├── grafana
    │   ├── grafana.ini
    │   ├── ldap.toml
    │   └── provisioning
    │       └── dashboards
    │           └── zabbix.yaml
    │       └── datasources
    │           └── zabbix.yaml
    ├── grafana-data
    │   ├── grafana.db
    │   ├── plugins
    │   ├── png
    │   └── sessions
    ├── Dockerfile
    └── plugin.json

Grafana plugin are alexanderzobnin-zabbix-app.

    version: "3"
    services:
      zabbix_db:
        image: mysql:5.7
        restart: always
        command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci
        expose:
          - "3306"
        environment:
          - MYSQL_DATABASE=${DB_NAME}
          - MYSQL_USER=${DB_USER}
          - MYSQL_PASSWORD=${DB_USER_PASSWORD}
          - MYSQL_ROOT_PASSWORD=${DB_USER_PASSWORD}
        volumes:
          - ./data/mysql:/var/lib/mysql

      zabbix_server:
        image: zabbix/zabbix-server-mysql:centos-latest
        restart: always
        volumes:
          - ./data/zabbix:/var/lib/zabbix
        environment:
          - DB_SERVER_HOST=zabbix_db
          - MYSQL_DATABASE=${DB_NAME}
          - MYSQL_USER=${DB_USER}
          - MYSQL_PASSWORD=${DB_USER_PASSWORD}
          - MYSQL_ROOT_PASSWORD=${DB_USER_PASSWORD}
          - ZBX_DEBUGLEVEL=${LOG_LEVEL}
        ports:
          - "10051:10051"
        links:
          - zabbix_db

      zabbix_web:
        image: zabbix/zabbix-web-apache-mysql:centos-latest
        restart: always
        environment:
          - ZBX_SERVER_HOST=zabbix_server
          - DB_SERVER_HOST=zabbix_db
          - MYSQL_DATABASE=${DB_NAME}
          - MYSQL_USER=${DB_USER}
          - MYSQL_PASSWORD=${DB_USER_PASSWORD}
          - MYSQL_ROOT_PASSWORD=${DB_USER_PASSWORD}
          - PHP_TZ=${TIME_ZONE}
        ports:
          - "80:80"

      zabbix_agent:
        image: zabbix/zabbix-agent:centos-latest
        privileged: true
        restart: always
        environment:
          - ZBX_SERVER_HOST=zabbix_server
        expose:
          - "10050"
        links:
          - zabbix_server

      grafana:
        build: .
        restart: always
        environment:
          - GF_INSTALL_PLUGINS=alexanderzobnin-zabbix-app
        container_name: grafana
        volumes:
          # dashborad.yml is recommended to export from grafana GUI
          - ./grafana/:/etc/grafana/
        command: /bin/sh curl -v --basic -XPOST "admin:admin@localhost:3000/api/plugins/alexanderzobnin-zabbix-app/settings?enabled=true" -d ''
        ports:
          - "3000:3000"
        links:
          - zabbix_db
          - zabbix_server

.val

DB_NAME=zabbix
DB_USER=zabbix
DB_USER_PASSWORD=zabbix
DB_ROOT_PASSWORD=zabbix
HTTP_PORT=80
TIME_ZONE=Asia/Tokyo
LOG_LEVEL=3

Datasource Config File

  • yaml which manage datasource
  • grafana-zabbix configuration
  • i thought type is zabbix or datasource which can be seen from GUI and API, but it was alexanderzobnin-zabbix-datasource.
    apiVersion: 1

    datasources:
    - name: Zabbix
      type: alexanderzobnin-zabbix-datasource
      access: proxy
      url: http://localhost/zabbix/api_jsonrpc.php
      isDefault: true
      jsonData:
        # Zabbix API credentials
        username: zabbix
        password: zabbix
        # Trends options
        trends: true
        trendsFrom: "7d"
        trendsRange: "4d"
        # Cache update interval
        cacheTTL: "1h"
        # Alerting options
        alerting: true
        addThresholds: false
        alertingMinSeverity: 3
        # Disable acknowledges for read-only users
        disableReadOnlyUsersAck: true
        # Direct DB Connection options
        dbConnectionEnable: true
        # Name of existing SQL datasource
        dbConnectionDatasourceName: MySQL Zabbix
      version: 1
      editable: false

    - name: MySQL Zabbix
      type: mysql
      url: localhost:3306
      database: zabbix
      user: grafana
      password: password

Dashboard Config File

you can export from GUI.

Direct DB Connection

  • create DB and user for grafana.
    CREATE DATABASE grafana;
    CREATE USER 'grafana'@'%' IDENTIFIED BY "zabbix";
    SHOW GRANTS FOR 'zabbix'@'%' \G

    // for grafana graph
    GRANT SELECT ON zabbix.* TO 'grafana'@'%' identified by 'zabbix';

    // for grafana data
    GRANT ALL ON grafama.* to 'grafana'@'%' identified by 'zabbix';
    GRANT ALL PRIVILEGES ON `grafana`.* to 'grafana'@'%' with grant option;
    flush privileges;

command memo

i am liable to forget so take a note.

    # start and stop
    docker-compose stop
    docker-compose up -d

    # logged in container and search something.
    $ docker exec -it --user root {container_id} /bin/bash

    # you can clear cache which tend to be a problem
    $ docker-compose build --no-cache

    # check logs
    $ docker-compose logs -f
    $ docker-compose logs {container_name}

official website

comments powered by Disqus