├── CHANGELOG.txt ├── README.md ├── docker_template.conf └── docker_template_agent1.xml /CHANGELOG.txt: -------------------------------------------------------------------------------- 1 | ----- 1.1.0 2 | 3 | * Fix number of CPUs detected on API v1.27+ (Frank Wall) 4 | 5 | This uses the `cpu_stats.online_cpus` field added in docker docker v17.03.1 (API v1.27) from 2017. 6 | Remain at v1.0.0 if you are monitoring older hosts. 7 | 8 | ----- 1.0.0 9 | 10 | Initial version 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # zabbix-docker-template 2 | Zabbix 5.x docker template for Zabbix Agent ver.1, with containers and images LLD 3 | 4 | _This should be able to run on older versions of Zabbix too, at least all the functionality required by the template is there on v4.x, but it is only tested on 5.0. 5 | I was notified of at least one failed attempt to import the template on v4.4.10, probably due to incompatibility of the XML format exported by v5.0_ 6 | 7 | This doesn't use any external scripts or modules to collect data, the only dependencies are `curl` and read access to docker's API. 8 | 9 | *Intended setup:* Running Zabbix Agent alongside Docker on the same host, access API by UNIX socket. 10 | 11 | *Possible:* Run Zabbix Agent separately and point the template to docker host, access API by HTTP. 12 | 13 | ## Setup 14 | - `cp docker_template.conf /etc/zabbix/zabbix_agentd.d/` 15 | - `sudo usermod -a -G docker zabbix` 16 | - restart Zabbix Agent 17 | - import `docker_template_agent1.xml` into Zabbix templates 18 | 19 | This will create a template named **Template App Docker - Agent 1** 20 | 21 | - attach the new template to hosts to start monitoring 22 | - configure macros as needed 23 | 24 | `{$DOCKER.SOCKET}` has to point to docker's unix socket (default is `/var/run/docker.sock`) 25 | 26 | ( NOTE: If you are having problems with items staying in the unsupported state and your docker host is runing with SELinux kernel, you might need to allow access for curl to docker's socket. See: https://github.com/vivanov-dp/zabbix-docker-template/issues/3, solution: https://github.com/vivanov-dp/zabbix-docker-template/issues/3#issuecomment-709324778 ) 27 | 28 | ## Details 29 | The `Docker overview` host screen will be added to monitored hosts - it contains all data, including discovered containers and their stats: 30 | 31 | ![Alt text](/../screenshots/screens/docker_images.png?raw=true "General Docker Data") 32 | ![Alt text](/../screenshots/screens/containers_networking.png?raw=true "Containers Networking") 33 | ![Alt text](/../screenshots/screens/containers_io_cpu_mem.png?raw=true "Containers Size, IO rate, CPU, Memory") 34 | 35 | 36 | This template uses Docker's API to fetch data and accesses it locally via docker's UNIX socket. 37 | 38 | By changing the items in the `docker_template.conf` file it is possible to set it up to access the API via http - example items are provided as a comment in the file - if you use them, the `{DOCKER.SOCKET}` macro should contain the name of the host to contact. 39 | 40 | Unlike the built-in Docker template for Agent v2, this template doesn't extract every possible item from the stats that Docker API returns, but (with few exceptions) only the ones that can be reasonably put into graphs. If you need more - it is trivial to extend by cloning new items. 41 | 42 | ## Performance 43 | The template relies on local JS preprocessing in the Zabbix Server for the low-level discovery. 44 | 45 | This is certainly not the most effective way to fetch and prepare data and if you have a really big setup you might need to look at other solutions. 46 | 47 | But to put **really big** into perspective: I have about 20 docker hosts with 4-5 containers each and one with 20 containers and I monitor them with this template running on a pretty modest vhost with 2 vcpu's and 4G RAM. 48 | 49 | This amounts to about 80 values per second on the server, CPU load and network traffic is negligible - about 4% and 100Kbit/s respectively. The Zabbix front-end generates more load than that when it renders the graphs. 50 | 51 | ## Contributions 52 | 53 | If you find anything fishy or have a feature request, add a new issue and I'll take a look. 54 | 55 | Pull requests appreciated. 56 | -------------------------------------------------------------------------------- /docker_template.conf: -------------------------------------------------------------------------------- 1 | UserParameter=docker.api[*],curl --unix-socket $1 -s http://latest/$2 2 | UserParameter=docker.containers.list[*],curl --unix-socket $1 -s http://latest/containers/json?size=true 3 | UserParameter=docker.containers.stats[*],curl --unix-socket $1 -s http://latest/containers/$2/stats?stream=false 4 | 5 | # Replace the above with these to access docker's API via HTTP. 6 | # Change {DOCKER.SOCKET} macro on the template in Zabbix to point to the host that serves the API. 7 | # Configure access to Docker accordingly. 8 | 9 | # UserParameter=docker.api[*],curl -s http://$1/latest/$2 10 | # UserParameter=docker.containers.list[*],curl -s http://$1/latest/containers/json?size=true 11 | # UserParameter=docker.containers.stats[*],curl -s http://$1/latest/containers/$2/stats?stream=false 12 | -------------------------------------------------------------------------------- /docker_template_agent1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5.0 4 | 2022-03-28T08:43:18Z 5 | 6 | 7 | Templates/Applications 8 | 9 | 10 | 11 | 1792 | 1793 | 1794 | 1795 | Docker: Containers 1796 | 1797 | 1798 | GRADIENT_LINE 1799 | 1A7C11 1800 | 1801 | Template App Docker - Agent 1 1802 | docker.containers.running 1803 | 1804 | 1805 | 1806 | 1 1807 | BOLD_LINE 1808 | 2774A4 1809 | 1810 | Template App Docker - Agent 1 1811 | docker.containers.paused 1812 | 1813 | 1814 | 1815 | 2 1816 | BOLD_LINE 1817 | F63100 1818 | 1819 | Template App Docker - Agent 1 1820 | docker.containers.stopped 1821 | 1822 | 1823 | 1824 | 3 1825 | BOLD_LINE 1826 | A54F10 1827 | 1828 | Template App Docker - Agent 1 1829 | docker.containers.total 1830 | 1831 | 1832 | 1833 | 1834 | 1835 | Docker: Resources 1836 | 1837 | 1838 | 1A7C11 1839 | 1840 | Template App Docker - Agent 1 1841 | docker.goroutines 1842 | 1843 | 1844 | 1845 | 1 1846 | F63100 1847 | 1848 | Template App Docker - Agent 1 1849 | docker.nfd 1850 | 1851 | 1852 | 1853 | 1854 | 1855 | Docker: Sizes 1856 | 1857 | 1858 | BOLD_LINE 1859 | 1A7C11 1860 | 1861 | Template App Docker - Agent 1 1862 | docker.images_size 1863 | 1864 | 1865 | 1866 | 1 1867 | BOLD_LINE 1868 | 2774A4 1869 | 1870 | Template App Docker - Agent 1 1871 | docker.layers_size 1872 | 1873 | 1874 | 1875 | 2 1876 | BOLD_LINE 1877 | F63100 1878 | 1879 | Template App Docker - Agent 1 1880 | docker.containers_size 1881 | 1882 | 1883 | 1884 | 3 1885 | BOLD_LINE 1886 | A54F10 1887 | 1888 | Template App Docker - Agent 1 1889 | docker.volumes_size 1890 | 1891 | 1892 | 1893 | 1894 | 1895 | 1896 | 1897 | Docker flag 1898 | 1899 | 1900 | 0 1901 | False 1902 | 1903 | 1904 | 1 1905 | True 1906 | 1907 | 1908 | 1909 | 1910 | Service state 1911 | 1912 | 1913 | 0 1914 | Down 1915 | 1916 | 1917 | 1 1918 | Up 1919 | 1920 | 1921 | 1922 | 1923 | 1924 | --------------------------------------------------------------------------------