Zabbix : store history and trends into `influxdb`

Zabbix : store history and trends into influxdb

zabbix grafana influxdb 20.04 18.04 16.04

I’m not particularly fond of influxdb, but since I know it already and since any time-series database should work better than a standard SQL database for time-series, let’s try to store zabbix history into influxdb.

Setup

  1. Install zabbix.
  2. Install grafana.
  3. Install influxdb and configure authentication.
  4. Install go and pwgen:
    sudo apt-get install golang-go pwgen
    
  5. Follow the chapter about your SQL database on https://github.com/zensqlmonitor/influxdb-zabbix.
  6. Connect to influx, create the zabbix database, with the zabbix user for writing and zabbix_ro user for read-only access (from grafana).
    CREATE database zabbix
    CREATE USER zabbix WITH PASSWORD 'use pwgen for that field and take a note'
    CREATE USER zabbix_ro WITH PASSWORD 'use pwgen for that field and take another note'
    GRANT ALL ON zabbix TO zabbix
    GRANT READ on zabbix TO zabbix_ro
    
  7. Create a user zabbix-influx
    sudo useradd -g zabbix -d /var/lib/zabbix-influx zabbix-influx
    sudo chown -R zabbix-influx:zabbix /var/lib/zabbix-influx
    
  8. Using the zabbix-influx user, install github.com/zensqlmonitor/influxdb-zabbix
    sudo -u zabbix-influx go get github.com/zensqlmonitor/influxdb-zabbix
    sudo -u zabbix-influx cp go/src/github.com/zensqlmonitor/influxdb-zabbix/influxdb-zabbix.conf .
    
  9. Configure influx credentials, and SQL access using sudoedit /var/lib/zabbix-influx/influxdb-zabbix.conf, make sure to configure influx and mysql URLs, databases, users and password.

Testing

  1. This command will run the influxd-zabbix in foreground:
    sudo -u zabbix-influx -i
    go build github.com/zensqlmonitor/influxdb-zabbix
    go install github.com/zensqlmonitor/influxdb-zabbix
    ./go/bin/influxdb-zabbix
    

    In fact, it will take all zabbix history and trends and put then into influx.

  2. Go to grafana, configure a new source using influxdb, database:zabbix, user:zabbix_ro, …
  3. Still in grafana, create a new dashboard and test the new data source.
  4. When all is working, kill influxdb-zabbix using CTRL-C.

Service

Now that the zabbix to influx bridge is working, make sur it runs in background, so data are pushed into influx as soon as they are in zabbix.

  1. Reduce the verbosity and disable coloring for syslog: sudoedit /var/lib/zabbix-influx/influxdb-zabbix.conf and change:
    levelconsole="Warn"
    formatting=false
    
  2. Create the service file, using sudoedit /etc/systemd/system/zabbix-influx.service with the following content:
    [Unit]
    Description=zabbix to influx data pusher
    #
    [Service]
    Type=simple
    Restart=always
    RestartSec=5s
    ExecStart=/var/lib/zabbix-influx/go/bin/influxdb-zabbix
    User=zabbix-influx
    Group=zabbix
    WorkingDirectory=~
    #
    [Install]
    WantedBy=multi-user.target
    
  3. Update systemd services
    sudo systemctl daemon-reload
    
  4. Enable and start the service
    sudo systemctl enable zabbix-influx
    sudo systemctl start zabbix-influx
    
  5. Check
    systemctl status zabbix-influx.service
    

    Should be Active (running).

  6. Have a break, then return to grafana and check if data are up-to date.

~~~

Question, remark, bug? Don't hesitate to contact me or report a bug.