Querying data that the Zabbix agent doesn't support

One thing we might be interested in is the number of open TCP connections. We can get this data using the netstat command (chances are netstat isn't installed on your distribution out of the box, but it should be possible to install this util from the net-tools package. If not, check out the following tip). Execute the following on the Zabbix server:

$ netstat -t

The -t switch tells netstat to list TCP connections only. As a result, we get a list of connections (trimmed here):

Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 localhost:zabbix-trapper localhost:52932 TIME_WAIT tcp 0 0 localhost:zabbix-agent localhost:59779 TIME_WAIT tcp 0 0 localhost:zabbix-agent localhost:59792 TIME_WAIT
In modern distributions, the ss utility might be a better option. It'll also perform better, especially when there are many connections. An alternative command for ss, matching the aforementioned netstat command, would be ss -tstate connect.

To get the number of connections, we'll use the following command:

netstat -nt | grep -c ^tcp

Here, grep first filters out connection lines and then just counts them. We could have used many other approaches, but this one is simple enough. Additionally, the -n flag is passed to netstat, which instructs it to perform no resolving on hosts, hence giving a performance boost.

Edit zabbix_agentd.conf and add the following line near the other user parameters:

UserParameter=net.tcp.conn,netstat -nt | grep -c ^tcp 

In the frontend, go to Configuration | Hosts, click on Items next to A test host, then click on Create item and fill in the following values:

  • Name: Open connections
  • Type: Zabbix agent (active)
  • Key: net.tcp.conn

When you're done, click on the Add button at the bottom. Did you notice that we didn't restart the agent daemon after modifying its configuration file? Do that now. Using such an ordering of events will give us values faster, because the agent queries the active items list immediately after startup, and this way the server already has the item configured when the agent is restarted. Feel free to check Monitoring | Latest values:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset