Шаблон speedtest для мониторинга в Zabbix

Задача:
---------------------------------------------------------------Создать мониторинг скорости интернета с графиками и тригерами. В заключении у нас должен быть получиться готовый для импорта шаблон
Отличие от статьи “Мониторинг скорости интернет канала в Zabbix” в том, что всё будет настроено на основе шаблона и при необходимости, с предварительной настройке агента забикса, мониторинг можно развернуть за несколько минут.
Устанавливаем speedtest. Конечно можно скачать speedtest-cli и использовать без установки, но меня интересует поддержка speedtest в актуальном состоянии. Для примера буду использовать CentOS.
Инструкция с официального сайта, для установки speedtest на centos
## If migrating from prior bintray install instructions please first... # sudo rm /etc/yum.repos.d/bintray-ookla-rhel.repo # sudo yum remove speedtest ## Other non-official binaries will conflict with Speedtest CLI # Example how to remove using yum # rpm -qa | grep speedtest | xargs -I {} sudo yum -y remove {} curl -s https://install.speedtest.net/app/cli/install.rpm.sh | sudo bash sudo yum install speedtest
Устанавливаем
[root@localhost ~]# curl -s https://install.speedtest.net/app/cli/install.rpm.sh | sudo bash Detected operating system as centos/8. Checking for curl... Detected curl... Downloading repository file: https://packagecloud.io/install/repositories/ookla/speedtest-cli/config_file.repo?os=centos&dist=8&source=script done. Installing yum-utils... ookla_speedtest-cli-source 282 B/s | 833 B 00:02 ookla_speedtest-cli-source 4.8 kB/s | 3.9 kB 00:00 Importing GPG key 0xE723ACAA: Userid : "https://packagecloud.io/ookla/speedtest-cli (https://packagecloud.io/docs#gpg_signing) <support@packagecloud.io>" Fingerprint: C525 F88F CF3A 7E56 CE2C F591 31EB 3981 E723 ACAA From : https://packagecloud.io/ookla/speedtest-cli/gpgkey ookla_speedtest-cli-source 71 B/s | 296 B 00:04 Dependencies resolved. ======================================================================================================================================================================================= Package Architecture Version Repository Size ======================================================================================================================================================================================= Installing: yum-utils noarch 4.0.18-4.el8 baseos 71 k Transaction Summary ======================================================================================================================================================================================= Install 1 Package Total download size: 71 k Installed size: 22 k Downloading Packages: yum-utils-4.0.18-4.el8.noarch.rpm 1.3 MB/s | 71 kB 00:00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 225 kB/s | 71 kB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : yum-utils-4.0.18-4.el8.noarch 1/1 Running scriptlet: yum-utils-4.0.18-4.el8.noarch 1/1 Verifying : yum-utils-4.0.18-4.el8.noarch 1/1 Installed: yum-utils-4.0.18-4.el8.noarch Complete! Generating yum cache for ookla_speedtest-cli... Importing GPG key 0xE723ACAA: Userid : "https://packagecloud.io/ookla/speedtest-cli (https://packagecloud.io/docs#gpg_signing) <support@packagecloud.io>" Fingerprint: C525 F88F CF3A 7E56 CE2C F591 31EB 3981 E723 ACAA From : https://packagecloud.io/ookla/speedtest-cli/gpgkey Generating yum cache for ookla_speedtest-cli-source... The repository is setup! You can now install packages. [root@localhost ~]# yum install speedtest Last metadata expiration check: 0:00:04 ago on Fri 10 Sep 2021 10:06:11 PM UTC. Dependencies resolved. ======================================================================================================================================================================================= Package Architecture Version Repository Size ======================================================================================================================================================================================= Installing: speedtest x86_64 1.0.0.2_1.5ae238b-1 ookla_speedtest-cli 910 k Transaction Summary ======================================================================================================================================================================================= Install 1 Package Total download size: 910 k Installed size: 2.2 M Is this ok [y/N]: y Downloading Packages: speedtest-1.0.0.2_1.5ae238b-1.x86_64.rpm 928 kB/s | 910 kB 00:00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 924 kB/s | 910 kB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : speedtest-1.0.0.2_1.5ae238b-1.x86_64 1/1 Running scriptlet: speedtest-1.0.0.2_1.5ae238b-1.x86_64 1/1 Verifying : speedtest-1.0.0.2_1.5ae238b-1.x86_64 1/1 Installed: speedtest-1.0.0.2_1.5ae238b-1.x86_64 Complete! [root@localhost ~]#
После установки проверяем работу speedtest. Первый запуск speedtest потребует подтверждения лицензии
[root@localhost ~]# speedtest ============================================================================== You may only use this Speedtest software and information generated from it for personal, non-commercial use, through a command line interface on a personal computer. Your use of this software is subject to the End User License Agreement, Terms of Use and Privacy Policy at these URLs: https://www.speedtest.net/about/eula https://www.speedtest.net/about/terms https://www.speedtest.net/about/privacy ============================================================================== Do you accept the license? [type YES to accept]: yes License acceptance recorded. Continuing. ============================================================================== Ookla collects certain data through Speedtest that may be considered personally identifiable, such as your IP address, unique device identifiers or location. Ookla believes it has a legitimate interest to share this data with internet providers, hardware manufacturers and industry regulators to help them understand and create a better and faster internet. For further information including how the data may be shared, where the data may be transferred and Ookla's contact details, please see our Privacy Policy at: http://www.speedtest.net/privacy ============================================================================== Do you accept the license? [type YES to accept]: Yes License acceptance recorded. Continuing. Speedtest by Ookla Server: teliko GmbH - Limburg (id = 40489) ISP: 1&1 Internet AG Latency: 4.45 ms (0.23 ms jitter) Download: 401.06 Mbps (data used: 190.8 MB) Upload: 418.18 Mbps (data used: 204.0 MB) Packet Loss: 0.0% Result URL: https://www.speedtest.net/result/c/53194017-00e8-4464-a1e3-eb327eed64cd [root@localhost ~]#
последующие запуски, подтверждения лицензионного соглашения не требуют
[root@appliance zabbix]# speedtest Speedtest by Ookla Server: xTom GmbH - Düsseldorf (id = 40138) ISP: Deutsche Telekom AG Latency: 8.85 ms (0.25 ms jitter) Download: 68.78 Mbps (data used: 57.4 MB) Upload: 25.83 Mbps (data used: 11.6 MB) Packet Loss: 0.0% Result URL: https://www.speedtest.net/result/c/593e0a41-86b4-410c-9429-4b26b3feaefc [root@appliance zabbix]#
Добавляем задание в cron, в интересах безопасности, лучше выполнять от пользователя zabbix. Если не будет работать замените zabbix на root
root@appliance zabbix]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed */30 * * * * zabbix /usr/bin/speedtest > /tmp/speedtest.txt [root@appliance zabbix]#
Создаём конфиг speedtest.conf для агента zabbix
vi /etc/zabbix/zabbix_agentd.d/speedtest.conf
со следующим содержимым
UserParameter=speedtest.upload[*],cat /tmp/speedtest.txt | grep Upload | sed 's/ //g' | cut -d ':' -f2 | grep -o '^[^M]*' UserParameter=speedtest.download[*],cat /tmp/speedtest.txt | grep Download | sed 's/ //g' | cut -d ':' -f2 | grep -o '^[^M]*' UserParameter=speedtest.ping[*],cat /tmp/speedtest.txt | grep Latency | sed 's/ //g' | cut -d ':' -f2 | grep -o '^[^m]*'
перезапускаем агента и проверяем работу
[root@appliance zabbix]# systemctl restart zabbix-agent [root@appliance zabbix]# [root@appliance zabbix]# /usr/bin/speedtest > /tmp/speedtest.txt [root@appliance zabbix]# [root@appliance zabbix]# zabbix_get -s 127.0.0.1 -k speedtest.ping 4.52 [root@appliance zabbix]# zabbix_get -s 127.0.0.1 -k speedtest.upload 25.77 [root@appliance zabbix]# zabbix_get -s 127.0.0.1 -k speedtest.download 66.01 [root@appliance zabbix]#
настраиваем веб-интерфейс забикса. Создаём новый шаблон

Добавляем шаблон кнопкой “Add”

Если всё хорошо, должны в zabbix увидеть “Template added“

находим только созданный шаблон и открываем

Переходим во вкладку “Items” и создаём новый

Создаём item для Download

cоздаём item для Upload

cоздаём item для Ping

При желании можно каждый item проверить. Проверю один для примера

Добавляем график

Нажав вкладку “Preview” можно посмотреть что получится

Настраиваем “Triggers“. Согласно тарифного плана, имеем следующее
- 100 MBit/s Download
- 40 MBit/s Upload
настрою Download не меньше 50 MBit/s

Должно получиться

В итоге получаем для тригера

Экспортируем шаблон

Вот какой xml получился
<?xml version="1.0" encoding="UTF-8"?> <zabbix_export> <version>5.4</version> <date>2021-09-14T23:13:22Z</date> <groups> <group> <uuid>aca01e2ac20d48018dff9348e949d465</uuid> <name>speedtest</name> </group> </groups> <templates> <template> <uuid>37577fb8b5d048b4bad99c5ed184d7b7</uuid> <template>speedtest</template> <name>speedtest</name> <groups> <group> <name>speedtest</name> </group> </groups> <items> <item> <uuid>f5b155816a054a38a4ccac4c32fc9dcf</uuid> <name>Speedtest - Download</name> <key>speedtest.download</key> <delay>15m</delay> <value_type>FLOAT</value_type> <units>Mbit/s</units> <triggers> <trigger> <uuid>f420baf93a0d43d8b76b1f427fe675f6</uuid> <expression>last(/speedtest/speedtest.download,#3)<50</expression> <name>{HOST.HOST} Download speed < 50 Mb/s</name> <priority>WARNING</priority> </trigger> </triggers> </item> <item> <uuid>d8cc12a7c55e461eb5b1b84f55f93a57</uuid> <name>Speedtest - Ping</name> <key>speedtest.ping</key> <delay>15m</delay> <value_type>FLOAT</value_type> <units>ms</units> </item> <item> <uuid>d24099fd8bb547b58b1c46efaaa6a001</uuid> <name>Speedtest - Upload</name> <key>speedtest.upload</key> <delay>15m</delay> <value_type>FLOAT</value_type> <units>Mbit/s</units> <triggers> <trigger> <uuid>e4780bbd5e9e4f81af64cf5d97ba8278</uuid> <expression>last(/speedtest/speedtest.upload,#3)<20</expression> <name>{HOST.HOST} Upload speed < 20 Mb/s</name> <priority>WARNING</priority> </trigger> </triggers> </item> </items> </template> </templates> <graphs> <graph> <uuid>ce3c0feb81cd4475a70238c758fd87a7</uuid> <name>Speedtest</name> <ymin_type_1>FIXED</ymin_type_1> <graph_items> <graph_item> <sortorder>1</sortorder> <drawtype>GRADIENT_LINE</drawtype> <color>1A7C11</color> <item> <host>speedtest</host> <key>speedtest.download</key> </item> </graph_item> <graph_item> <sortorder>2</sortorder> <drawtype>GRADIENT_LINE</drawtype> <color>2774A4</color> <item> <host>speedtest</host> <key>speedtest.upload</key> </item> </graph_item> <graph_item> <sortorder>3</sortorder> <color>FC6EA3</color> <item> <host>speedtest</host> <key>speedtest.ping</key> </item> </graph_item> </graph_items> </graph> </graphs> </zabbix_export>
Для тестирования, я удалил созданный шаблон и попробуем его добавить

В пятой версии забикса появилась возможность предварительно просматривать добавляемое

можно назначать шаблон к ранее настроенному хосту, так где мы устанавливали speedtest, и пользоваться
Свежие комментарии