1/* 2** Zabbix 3** Copyright (C) 2001-2021 Zabbix SIA 4** 5** This program is free software; you can redistribute it and/or modify 6** it under the terms of the GNU General Public License as published by 7** the Free Software Foundation; either version 2 of the License, or 8** (at your option) any later version. 9** 10** This program is distributed in the hope that it will be useful, 11** but WITHOUT ANY WARRANTY; without even the implied warranty of 12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13** GNU General Public License for more details. 14** 15** You should have received a copy of the GNU General Public License 16** along with this program; if not, write to the Free Software 17** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18**/ 19 20package docker 21 22import ( 23 "zabbix.com/pkg/metric" 24 "zabbix.com/pkg/plugin" 25) 26 27type metricMeta struct { 28 path string 29} 30 31const ( 32 keyContainerInfo = "docker.container_info" 33 keyContainerStats = "docker.container_stats" 34 keyContainers = "docker.containers" 35 keyContainersDiscovery = "docker.containers.discovery" 36 keyDataUsage = "docker.data_usage" 37 keyImages = "docker.images" 38 keyImagesDiscovery = "docker.images.discovery" 39 keyInfo = "docker.info" 40 keyPing = "docker.ping" 41) 42 43var metricsMeta = map[string]metricMeta{ 44 keyContainerInfo: {"containers/%s/json"}, 45 keyContainerStats: {"containers/%s/stats?stream=false"}, 46 keyContainers: {"containers/json?all=true"}, 47 keyContainersDiscovery: {"containers/json?all=%s"}, 48 keyDataUsage: {"system/df"}, 49 keyImages: {"images/json"}, 50 keyImagesDiscovery: {"images/json"}, 51 keyInfo: {"info"}, 52 keyPing: {"_ping"}, 53} 54 55var ( 56 paramContainer = metric.NewParam("Container", "Container name for which the information is needed."). 57 SetRequired() 58 paramStatusAll = metric.NewParam("All", "Return all containers (true) or only running (false)."). 59 WithDefault("false"). 60 WithValidator(metric.SetValidator{Set: []string{"true", "false"}, CaseInsensitive: true}) 61) 62 63var metrics = metric.MetricSet{ 64 keyContainerInfo: metric.New("Return low-level information about a container.", 65 []*metric.Param{paramContainer}, false), 66 keyContainerStats: metric.New("Returns near realtime stats for a given container.", 67 []*metric.Param{paramContainer}, false), 68 keyContainers: metric.New("Returns a list of containers.", nil, false), 69 keyContainersDiscovery: metric.New("Returns a list of containers, used for low-level discovery.", 70 []*metric.Param{paramStatusAll}, false), 71 keyDataUsage: metric.New("Returns information about current data usage.", nil, false), 72 keyImages: metric.New("Returns a list of images.", nil, false), 73 keyImagesDiscovery: metric.New("Returns a list of images, used for low-level discovery.", 74 nil, false), 75 keyInfo: metric.New("Returns information about the docker server.", nil, false), 76 keyPing: metric.New("Pings the server and returns 0 or 1.", nil, false), 77} 78 79func init() { 80 plugin.RegisterMetrics(&impl, pluginName, metrics.List()...) 81} 82