Zabbix Ruby Client

Gem Version Code Climate

This tool is designed to make easy to install zabbix reporter on monitored servers using zabbix-sender rather than zabbix-agent. It targets on monitoring mainly linux servers and is built on a plugin system so that you can decide what is going to be reported.

The development is still in progress but it produces results and works in my case. Use at your own risk and read the code first. It is developed under ruby 2 but should work on 1.9.3 as well.

Check the Changelog for recent changes, code is still under huge development and is likely to move a lot until version 0.1.

Installation

Install it yourself as:

gem install zabbix-ruby-client

Usage

zrc init [name]
# will create a directory [name] (default: zabbix-ruby-client) for
# storing configuration and temporary files

cd [name]
bundle
# makes the zabbix-ruby-client [name] ready to run
# then edit config.yml according to your needs

bundle exec zrc
# to list available commands

bundle exec zrc show
# to test the data collection

Setting up cronjobs

When ready just install a cron task according to your environment

echo '* * * * * /bin/bash -lc "cd /path/to/zrc && bundle exec zrc upload"' | crontab
# or
echo '* * * * * /bin/zsh -c ". $HOME/.rvm/scripts/rvm && cd /path/to/zrc && bundle exec zrc upload"' | crontab
# or
echo '* * * * * /bin/zsh -c "export RBENV_ROOT=/usr/local/var/rbenv && eval \"$(rbenv init - zsh)\" && cd /path/to/zrc && bundle exec zrc upload"' | crontab

By default zrc show and zrc upload will read config.yml (for the general config) and minutely.yml (for the list of plugins to run).

You can use -c to specify another config file, and -t to use another list of plugins. The zrc init command will create sample minutely.yml, hourly.yml and monthly.yml but you can create any arbitrary list of plugins, that can be used in your cronjobs.

Here is an example setup using the files generated by the init:

* * * * * /bin/zsh -c ". $HOME/.rvm/scripts/rvm && cd $HOME/zrc && bundle exec zrc upload"
0 0/6 * * * /bin/zsh -c ". $HOME/.rvm/scripts/rvm && cd $HOME/zrc && bundle exec zrc upload -t hourly.yml"
0 0 1 * * /bin/zsh -c ". $HOME/.rvm/scripts/rvm && cd $HOME/zrc && bundle exec zrc upload -t monthly.yml"

plugins

There are a set of standart plugins included in the package, aimed at linux systems.

  • ubuntu system stats (system_tpl includes the following)
    • load (uses /proc/loadavg) load_tpl
    • cpu (uses /proc/stat) cpu_tpl
    • memory (uses /proc/meminfo) memory_tpl
    • disk (uses /proc/diskstats) disk_tpl
    • args [ "md-0", "/", "vgebs" ] = group identifier, mountpoint, groupname where identifier is what is found in /proc/diskstats, and groupname is something found in df command. The mount point will be used as label.
    • network (uses /proc/net/dev) network_tpl
    • args [ eth0 ] is just the interface identifier
    • apt (uses ubuntu /usr/lib/update-notifier/apt-check) this one will populate the 'tag' field in host info, and is supposed to run every few hours or at least not every minute apt_tpl
    • sysinfo (uses uname -a) is populating the host info in the inventory, and should be ran at setup and/or monthly sysinfo_tpl
  • apache (depends on mod_status with status_extended on) apache_tpl
  • mysql (uses mysqladmin extended-status) mysql_tpl
  • nginx (requires httpStubStatus nginx module) nginx_tpl

You can add extra plugins in a plugins/ dir in the working dir, just by copying one of the existing plugins in the repo and change to your need. All plugins present in plugins/ will be loaded if present in the config file you use. That can be convenient to test by using the -t flag, for example bundle exec zrc -t testplugin.yml where testplugin.yml only contains the name and args for yoiur plugin.

Todo

  • read /proc rather than rely on installed tools
  • write tests
  • add more plugins
    • memcache
    • redis
    • mysql master/slave
    • monit
    • passenger
    • nginx
    • logged users
    • denyhosts
    • postfix
    • sendgrid
    • airbrake
    • disk occupation (done)
  • try to work out a way to create host/graphs/alerts from the client using Zabbix API
  • verify compatibility with ruby 1.9

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Contributors

License

Copyright 2013 Faria Systems - MIT license - created by mose at mose.com