Setting up HTTP agent monitoring
With the Zabbix HTTP agent, we can monitor a web page or API by retrieving data from it. For instance, if there's a counter on a web page and we want to keep an eye on that counter value, we can do so with Zabbix HTTP monitor.
Getting ready
We are going to need a web page to monitor and we will need our Zabbix server. For your convenience, we've added a page to our own website to retrieve a value from. Here's the page: https://oicts.com/book-page/.
Please also note that your Zabbix server will need an active internet connection for this recipe.
How to do it…
Let's poll this special web page we've created for you for the visitor count that's currently configured on it. This is a real counter for the number of times (unique) visitors have opened the URL:
- Navigate to your Zabbix frontend and navigate to Configuration | Hosts, then click the host called lar-book-agent_simple. Now go to Items; we want to create a new item here by clicking the Create item button. Now we are going to need to create an HTTP agent item as shown in the following screenshot:
Use the following preprocessing steps:
- Now navigate to Monitoring | Hosts and open the Latest data page for our lar-book-agent_simple host. If everything is working as it should, we should now be requesting this page's visitor count every 15 minutes as follows:
How it works…
What we do here is request the complete web page from Zabbix by navigating to the page with the HTTP agent and downloading it. When we have the complete content of the page, in this case, an HTML/PHP page, we can process the data:
We ask our preprocessor via a regex to go through the requested code and only show the number behind where it says Total Page Visits:.
All that's left is the number, ready for us to use in graphs and other types of data visualization.