Traceroute with Zabbix and MTR

At the company I work for, we are using Zabbix to monitor our infrastructure and in some case we are using “traceroute” to keep an eye on our network from different locations.

By keeping a traceroute history, it can help you to understand some networking problem by example when you are facing packet loss from some location.

To keep this history in Zabbix, we are using “MTR” instead of the traditional “traceroute” command.

Here is a small explanation of what MTR is, taken from the Github page of the project :

mtr combines the functionality of the ‘traceroute’ and ‘ping’ programs
in a single network diagnostic tool.

As mtr starts, it investigates the network connection between the host
mtr runs on and a user-specified destination host. After it
determines the address of each network hop between the machines,
it sends a sequence of ICMP ECHO requests to each one to determine the
quality of the link to each machine. As it does this, it prints
running statistics about each machine. 

Here is an example of the command output :

MTR is installed on our Zabbix proxies and on the main server.

Under Debian, the command to install MTR is :

sudo aptitude install mtr

As we are using proxies and active agents, the remote commands are not supported. So we have deployed a local script on the server and proxies.

Here is the local script :

#!/usr/bin/env bash
IP=$1
mtr -r -c3 -w -b $IP

This local script is named “mtrtrace.sh” and is saved under the “externalscripts” directory of Zabbix. The path can be found in the proxy or server configuration file under the following configuration key : “ExternalScripts“. Under Debian it’s “/usr/lib/zabbix/externalscripts“.

Once you have created the file, you have to allow Zabbix to execute it by using the following commands :

chmod +x mtrtrace.sh
chown zabbix:zabbix mtrtrace.sh

Then import the following template in Zabbix web interface and link it to a host :

If you prefer to add it in an existing template, here are the settings :

It will use the first ” IP address” in the “Agent interfaces” part of the host configuration.

You will find the history of data under the application “Traceroute” and in the item ” MTR Trace” on the “Latest data” tab of the configured host.

Here is an example of data from this tab :

Please note that, it’s recommended to increase the “Timeout” value in the Zabbix Server and Proxies configuration files to use this script. On my side it takes 10 seconds in average to be completely executed.

18 thoughts on “Traceroute with Zabbix and MTR”

  1. I liked your zabbix and mtr article. Very helpful!

    With the version of mtr that comes with CentOS 6.x, I found that I needed to alter the script parameters slightly:

    #!/usr/bin/env bash
    IP=$1
    mtr -r -c3 -w -showips $IP

    (The “-b” switch you used doesn’t work with this particular version of MTR.)

    I found you’ll also need to make some permission changes on the mtr binary:

    chmod 4755 /usr/sbin/mtr
    chown root:zabbix mtrtrace.sh

    1. Hi,

      Thanks for your feedback.
      As I work with Debian I did not make the test with CentOS.
      I will try to check with the 7.x if there is the same problem.

      Jérémy

  2. Hi,I test it with CentOS7,but error happened:
    9599:20170808:120012.616 item “website1:mtrtrace.sh[{HOST.IP}]” became not supported: Timeout while executing a shell script.

  3. Hello kkxue,

    I’m glad you solved this problem.
    I will move the warning about that because, the end of the post, it’s not the best place to be put it.

    I hope that this template will help you.

  4. Hi,

    I’ve accepted your PR.
    Thanks for your work. It’s a strange problem because it was exported from Zabbix 3.2 directly and not modified after.

  5. Hi Jeremy,

    thanks for posting, it’s been quite useful. I’m also on debian and didn’t have any problems setting it all up, but what i have now isn’t quite what i expected. What i see in zabbix is simply the output of the shell script, there’s no parsing of the actual information and certainly no graphs. I wonder how you could even use this data in production as theres no thresholds there or anything. What’s the go?

    Kind regards, Hoolio

    1. Hello,

      Currently we are not using the output of mtr like an alerting value but rather like an history value when we face a packet loss or latency issue. All our latency and packet loss check are coupled with MTR.
      It help us to see if there is some change in the routing by checking the history and allow us to send the traceroute output to our provider from several location without having to do it in live from several locations.

      This solution comes from an issue we faced where I had to send a dashboard to one of our provider where they could have all the value in nearly realtime from several locations : traceroute, latency, packet loss.

      But I must admit that it could enhanced with some alerting value with some parsing of the value.
      If you have any idea of what you would like or any modification to the script and template I will be more than happy to discuss about it with you.

      Regards,

  6. Hi, i need use this but i don’t have an IP Addres. I have a Domain, we have a site on aws, but i don’t have access to the plataform. So, i only could check the site (with 200 status code) and i want check all nodes with this external script.

    1. Hello,

      Sorry for the late answer but I was on holiday.

      If in the template, you change the key “mtrtrace.sh[{HOST.IP}]” to “mtrtrace.sh[{HOST.DNS}]” and then on the host set the agent interface DNS to your website DNS it should work.

      You won’t have any change to make to the script.

      Let me know if it helps you.

  7. Hello, I have it running but it is only showing in latest data, one hop, also it is only saying local host? My version of zabbix is appliance 4.03 and ubuntu.

    2019-09-19 06:50:14
    Start: Thu Sep 19 13:50:07 2019
    HOST: zabbix Loss% Snt Last Avg Best Wrst StDev
    1.|– localhost (::1) 0.0% 3 0.1 0.1 0.1 0.1 0.0

    1. Hello,

      Can you check that the first IP address of the Zabbix Agent on your host configuration is not 127.0.0.1 ?
      Which IP do you want to check?

  8. Wow brother I am honored for a response. it probably is, I’m trying to monitor external hosts.
    But when I set one of for test and I go to where you have instructed that is all i see. I setup MTR and time out and all of that on the Zabbix server which is behind NAT.

    1. Hello,

      Can you check that the Agent Interfaces “IP address” of the host is not 127.0.0.1 ?
      Please see the following capture : https://imgur.com/a/BIE4fUV
      If not can you tell me if the ouput is the same using this command directly from Zabbix Server : mtr -r -c3 -w -b 1.1.1.1

  9. It was 127.0.0.1, for host “Zabbix Server” in GUI, I just changed it. How long for the changes to take effect you think? I am testing with a remote host, running “Check Now” still says same thing.

  10. Sorry for the late answer.
    If it’s executed directly from your Zabbix server, it should be ok on the next scheduled run.
    If the problem still exists, could you send me some screenshot of your configuration?

  11. I am such a dodo, the issue was because I did not have the $ip capitalized.
    #!/usr/bin/env bash
    IP=$1
    mtr -r -c3 -w -b $IP

    I had , “mtr -r c3 -w -b $ip, and not $IP”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.