Home Cloud & Networking Zabbix 5 IT Infrastructure Monitoring Cookbook

Zabbix 5 IT Infrastructure Monitoring Cookbook

By Nathan Liefting , Brian van Baekel
books-svg-icon Book
Subscription FREE
eBook + Subscription €14.99
eBook €28.99
Print + eBook €37.99
READ FOR FREE Free Trial for 7 days. €14.99 p/m after trial. Cancel Anytime! BUY NOW BUY NOW BUY NOW
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
READ FOR FREE Free Trial for 7 days. €14.99 p/m after trial. Cancel Anytime! BUY NOW BUY NOW BUY NOW
Subscription FREE
eBook + Subscription €14.99
eBook €28.99
Print + eBook €37.99
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
  1. Free Chapter
    Chapter 2: Setting Up Zabbix Monitoring
About this book
Zabbix offers useful insights into your infrastructure performance and issues and enables you to enhance your monitoring setup with its variety of powerful features. This book covers hands-on, easy-to-follow recipes for using Zabbix 5 for effectively monitoring the performance of devices and applications over networks. The book starts by guiding you through the installation of Zabbix and using the Zabbix frontend. You'll then work your way through the most prominent features of Zabbix and make the right design choices for building a scalable and easily manageable environment. The book contains recipes for building items and triggers for different types of monitoring, building templates, and using Zabbix proxies. As you advance, you’ll learn how to use the Zabbix API for customization and manage your Zabbix server and database efficiently. Finally, you'll find quick solutions to the common and not-so-common problems that you may encounter in your everyday Zabbix monitoring work. By the end of this Zabbix book, you’ll have learned how to use Zabbix for all your monitoring needs and be able to build a solid Zabbix setup by leveraging its key functionalities.
Publication date:
February 2021
Publisher
Packt
Pages
428
ISBN
9781800202238

 

Chapter 2: Setting Up Zabbix Monitoring

Zabbix is built to be flexible and should be able to monitor just about anything you could ever require. In this chapter, we will learn more about working with Zabbix to build a lot of different options for monitoring. We'll go over them recipe by recipe, so you'll end up with a solid understanding of how they work. We'll cover the following recipes on the different monitoring types:

  • Setting up Zabbix agent monitoring
  • Working with SNMP monitoring
  • Creating Zabbix simple checks and Zabbix trapper
  • Working with calculated and dependent items
  • Creating external checks
  • Setting up JMX monitoring
  • Setting up database monitoring
  • Setting up HTTP agent monitoring
  • Using Zabbix preprocessing to alter item values
 

Technical requirements

We will need a Zabbix server capable of performing monitoring, with the following requirements:

  • A server with Zabbix server installed on a Linux distribution of your choice, such as CentOS or Ubuntu, but a distribution such as Debian or anything else will suit you just as well
  • MariaDB set up to work with your Zabbix server
  • NGINX or Apache set up to serve the Zabbix frontend

I'll be using the same server as we used in the previous chapter, but any Zabbix server should do.

 

Setting up Zabbix agent 2 monitoring

With the release of Zabbix 5, Zabbix also officially started support for the new Zabbix agent 2. Zabbix agent 2 brings some major improvements and is even written in another coding language, which is Golang instead of C. In this recipe, we will be exploring how to work with Zabbix agent 2 and explore some of the new features introduced by it.

You'll also need a Linux distribution of your choice running Zabbix agent 2.

Getting ready

To get started with Zabbix agent 2, all we need to do is install it to a (Linux) host that we want to monitor. Make sure you have an empty Linux (CentOS 8) host ready to monitor.

How to do it

Let's see how to install Zabbix agent 2 and then move on to actually working with it.

Installing Zabbix agent 2

Let's start by installing Zabbix agent 2 on the Linux host we want to monitor. I'll be using a CentOS 8 machine:

  1. Issue the following command to add the repository:

    For RHEL-based systems:

    rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm

    For Debian-based systems:

    wget https://repo.zabbix.com/zabbix/5.0/debian/pool/main/z/zabbix-release/zabbix-release_5.0-1+buster_all.deb
    dpkg -i zabbix-release_5.0-1+buster_all.deb
  2. Then issue the following command to install Zabbix Agent 2:

    For RHEL-based systems:

    dnf install zabbix-agent2

    For Debian-based systems:

    apt install zabbix-agent2

Congratulations, Zabbix agent 2 is now installed and ready to use.

Using a Zabbix agent in Passive mode

Let's start by building a Zabbix agent with passive checks:

  1. After installing Zabbix agent 2, let's open the Zabbix agent configuration file for editing:
    vim /etc/zabbix/zabbix_agent2.conf

    In this file, we edit all the Zabbix agent configuration values we could need from the server side.

  2. Let's start by editing the following values:
    Server=127.0.0.1
    Hostname=Zabbix server
  3. Change Server to the IP of the Zabbix server that will monitor this passive agent. Change Hostname to the hostname of the monitored server.
  4. Now restart the Zabbix agent 2 process:
    systemctl restart zabbix-agent2.service
  5. Now move to the frontend of your Zabbix server and add this host for monitoring.
  6. Go to Configuration | Hosts in your Zabbix frontend and click Create host in the top-right corner.
  7. To create this host in our Zabbix server, we need to fill in the values seen in the following screenshot:
    Figure 2.1 – The Zabbix host creation page for host lar-book-agent

    Figure 2.1 – The Zabbix host creation page for host lar-book-agent

    It's important to add the following:

    • Host name: To identify this host.
    • Groups: To logically group hosts.
    • Interfaces: To monitor this host on a specific interface. No interface means no communication.
  8. It is also important to add a template to this host. As this is a Linux server monitored by a Zabbix agent, let's add the correct out-of-the-box template as shown in the following screenshot:
    Figure 2.2 – The Zabbix host template page for host lar-book-agent

    Figure 2.2 – The Zabbix host template page for host lar-book-agent

  9. Click the Add button and you're done creating this agent host. Now that you've got this host, make sure the ZBX icon turns green, indicating that this host is up and being monitored with the passive Zabbix agent:
    Figure 2.3 – The Zabbix configuration hosts page, host lar-book-agent

    Figure 2.3 – The Zabbix configuration hosts page, host lar-book-agent

  10. You can now see the values received on this host by going to Monitoring | Hosts and checking the Latest data button. Please note that the values could take a while to show up:
Figure 2.4 – The Zabbix latest data page for host lar-book-agent

Figure 2.4 – The Zabbix latest data page for host lar-book-agent

Using a Zabbix agent in Active mode

Now let's check out how to configure the Zabbix agent with active checks. We need to change some values on the monitored Linux server host side:

  1. Start by executing the following command:
    vim /etc/zabbix/zabbix_agent2.conf
  2. Now let's edit the following value to change this host to an active agent:
    ServerActive=127.0.0.1
  3. Change ServerActive to the IP of the Zabbix server that will monitor this passive agent and also change Hostname to lar-book-agent:
    Hostname=lar-book-agent
  4. Now restart the Zabbix agent 2 process:
    systemctl restart zabbix-agent2.service
  5. Now move to the frontend of your Zabbix server and let's add another host with a template to do active checks instead of passive ones.
  6. First, let's rename our passive host. To do that, go to Configuration | Hosts in your Zabbix frontend and click the host we just created. Change Host name as follows:
    Figure 2.5 – The Zabbix host configuration page for host lar-book-agent_passive

    Figure 2.5 – The Zabbix host configuration page for host lar-book-agent_passive

    We are doing this because for an active Zabbix agent, the hostname in the file needs to match our Zabbix server.

  7. Go to Configuration | Hosts in your Zabbix frontend and click Create host in the top-right corner.
  8. Now let's create the host as follows:
    Figure 2.6 – The Zabbix host configuration page for host lar-book-agent

    Figure 2.6 – The Zabbix host configuration page for host lar-book-agent

  9. Also, make sure to add the correct template, named Template OS Linux by Zabbix agent active:
Figure 2.7 – The Zabbix host template page for host lar-book-agent

Figure 2.7 – The Zabbix host template page for host lar-book-agent

Please note that the ZBX icon won't turn green for an active agent. But when we navigate to Monitoring | Hosts and check Latest data, we can see our active data coming in.

Tip

As you might have noticed just now, a Zabbix agent can run in both passive and active mode. Keep this in mind when creating your Zabbix agent templates, as you might want to combine the check types.

How it works…

Now that we have configured our Zabbix agents and know how they should be set up, let's see how the different modes work.

Passive agent

The passive agent works by collecting data from our host with the Zabbix agent. Every time an item on our host reaches its interval, the Zabbix server asks the Zabbix agent what the value is now:

Figure 2.8 – Communication diagram between server and passive agent

Figure 2.8 – Communication diagram between server and passive agent

Active agent

The active agent works by sending data from the Zabbix agent to Zabbix server. Every time an item on our agent reaches its update interval, the agent will send the value to our server. We can also use this to send a notification to our server faster when something goes wrong:

Figure 2.9 – Communication diagram between server and active agent

Figure 2.9 – Communication diagram between server and active agent

As mentioned, we can use both types of checks at the same time, giving us the freedom to configure every type of check we could possibly need. Our setup would then look like this:

Figure 2.10 – Communication diagram between server and both agent types

Figure 2.10 – Communication diagram between server and both agent types

See also

There's a lot of new stuff going on under the hood of Zabbix agent 2; if you're interested in learning more about the core of Zabbix agent 2, check out this cool blog post by Alexey Petrov: https://blog.zabbix.com/magic-of-new-zabbix-agent/8460/.

               
About the Authors
  • Nathan Liefting

    Nathan Liefting, also known as Larcorba, is an IT consultant, trainer, and content creator (artist). He has more than 6 years of professional experience in IT. His experience ranges from managing networks running EVPN/VXLAN to Linux environments and programming. Nathan started working with Zabbix in 2016 when it was still at Zabbix 2 and Zabbix 3 was just released. He now works for Opensource ICT Solutions BV in the Netherlands as a Zabbix trainer and consultant, designing and building professional Zabbix environments and Zabbix components for some of the biggest companies around the world.

    Browse publications by this author
  • Brian van Baekel

    Brian van Baekel quickly discovered how powerful Zabbix is during his career as a network engineer. Ever since, he has been working with Zabbix in various (large) environments, leading to his official Zabbix Certified Trainer certification in early 2017. In 2018, Brian founded Opensource ICT Solutions BV in the Netherlands and Opensource ICT Solutions LLC in the US. Both companies primarily focus on building Zabbix environments all over the world. In 2021, further expansion of the business was established by opening a subsidiary in the United Kingdom with a full focus on the Zabbix product. All companies provide support, training, and consultancy services, which means Brian works with the Zabbix product 24/7. Fun fact: Even his cat is named Zabbix.

    Browse publications by this author
Zabbix 5 IT Infrastructure Monitoring Cookbook
Unlock this book and the full library FREE for 7 days
Start now