目录
输入和输出集成概述
Docker 输入插件允许您使用 Docker Engine API 从 Docker 容器收集指标,从而增强容器化应用程序的可见性和监控。
此插件使 Telegraf 能够使用 Prometheus remote write 协议将指标发送到 Cortex,从而实现无缝摄取到 Cortex 的可扩展、多租户时序存储中。
集成详细信息
Docker
Telegraf 的 Docker 输入插件从 Docker Engine API 收集有价值的指标,从而提供对正在运行的容器的洞察。此插件利用官方 Docker 客户端与 Engine API 交互,允许用户监控各种容器状态、资源分配和性能指标。凭借按名称和状态过滤容器的选项,以及可自定义的标签,此插件支持在各种环境中监控容器化应用程序的灵活性,无论是在本地系统上还是在 Kubernetes 等编排平台中。此外,它还通过要求访问 Docker 守护程序的权限来解决安全问题,并强调在容器化环境中部署时的正确配置。
Cortex
借助 Telegraf 的 HTTP 输出插件和 prometheusremotewrite
数据格式,您可以将指标直接发送到 Cortex,这是一个水平可扩展的 Prometheus 长期存储后端。Cortex 支持多租户,并使用 Prometheus protobuf 格式接受 remote write 请求。通过使用 Telegraf 作为收集代理和 Remote Write 作为传输机制,组织可以将可观测性扩展到 Prometheus 本身不支持的来源(例如 Windows 主机、支持 SNMP 的设备或自定义应用程序指标),同时利用 Cortex 的高可用性和长保留能力。
配置
Docker
[[inputs.docker]]
## Docker Endpoint
## To use TCP, set endpoint = "tcp://[ip]:[port]"
## To use environment variables (ie, docker-machine), set endpoint = "ENV"
endpoint = "unix:///var/run/docker.sock"
## Set to true to collect Swarm metrics(desired_replicas, running_replicas)
## Note: configure this in one of the manager nodes in a Swarm cluster.
## configuring in multiple Swarm managers results in duplication of metrics.
gather_services = false
## Only collect metrics for these containers. Values will be appended to
## container_name_include.
## Deprecated (1.4.0), use container_name_include
container_names = []
## Set the source tag for the metrics to the container ID hostname, eg first 12 chars
source_tag = false
## Containers to include and exclude. Collect all if empty. Globs accepted.
container_name_include = []
container_name_exclude = []
## Container states to include and exclude. Globs accepted.
## When empty only containers in the "running" state will be captured.
# container_state_include = []
# container_state_exclude = []
## Objects to include for disk usage query
## Allowed values are "container", "image", "volume"
## When empty disk usage is excluded
storage_objects = []
## Timeout for docker list, info, and stats commands
timeout = "5s"
## Whether to report for each container per-device blkio (8:0, 8:1...),
## network (eth0, eth1, ...) and cpu (cpu0, cpu1, ...) stats or not.
## Usage of this setting is discouraged since it will be deprecated in favor of 'perdevice_include'.
## Default value is 'true' for backwards compatibility, please set it to 'false' so that 'perdevice_include' setting
## is honored.
perdevice = true
## Specifies for which classes a per-device metric should be issued
## Possible values are 'cpu' (cpu0, cpu1, ...), 'blkio' (8:0, 8:1, ...) and 'network' (eth0, eth1, ...)
## Please note that this setting has no effect if 'perdevice' is set to 'true'
# perdevice_include = ["cpu"]
## Whether to report for each container total blkio and network stats or not.
## Usage of this setting is discouraged since it will be deprecated in favor of 'total_include'.
## Default value is 'false' for backwards compatibility, please set it to 'true' so that 'total_include' setting
## is honored.
total = false
## Specifies for which classes a total metric should be issued. Total is an aggregated of the 'perdevice' values.
## Possible values are 'cpu', 'blkio' and 'network'
## Total 'cpu' is reported directly by Docker daemon, and 'network' and 'blkio' totals are aggregated by this plugin.
## Please note that this setting has no effect if 'total' is set to 'false'
# total_include = ["cpu", "blkio", "network"]
## docker labels to include and exclude as tags. Globs accepted.
## Note that an empty array for both will include all labels as tags
docker_label_include = []
docker_label_exclude = []
## Which environment variables should we use as a tag
tag_env = ["JAVA_HOME", "HEAP_SIZE"]
## Optional TLS Config
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false
Cortex
[[outputs.http]]
## Cortex Remote Write endpoint
url = "http://cortex.example.com/api/v1/push"
## Use POST to send data
method = "POST"
## Send metrics using Prometheus remote write format
data_format = "prometheusremotewrite"
## Optional HTTP headers for authentication
# [outputs.http.headers]
# X-Scope-OrgID = "your-tenant-id"
# Authorization = "Bearer YOUR_API_TOKEN"
## Optional TLS configuration
# tls_ca = "/path/to/ca.pem"
# tls_cert = "/path/to/cert.pem"
# tls_key = "/path/to/key.pem"
# insecure_skip_verify = false
## Request timeout
timeout = "10s"
输入和输出集成示例
Docker
-
监控容器化应用程序的性能:使用 Docker 输入插件来跟踪 Docker 容器中运行的应用程序的 CPU、内存、磁盘 I/O 和网络活动。通过收集这些指标,DevOps 团队可以主动管理资源分配、排除性能瓶颈并确保跨不同环境的最佳应用程序性能。
-
与 Kubernetes 集成:利用此插件收集由 Kubernetes 编排的 Docker 容器的指标。通过滤除不必要的 Kubernetes 标签并专注于关键指标,团队可以简化其监控解决方案并创建仪表板,以提供对 Kubernetes 集群中运行的微服务的整体运行状况的洞察。
-
容量规划和资源优化:使用 Docker 输入插件收集的指标来执行 Docker 部署的容量规划。分析使用模式有助于识别未充分利用的资源和过度配置的容器,从而指导基于实际使用趋势进行向上或向下扩展的决策。
-
容器异常的自动警报:根据通过 Docker 插件收集的指标设置警报规则,以通知团队资源使用量或服务中断的异常峰值。这种主动监控方法有助于维护服务可靠性并优化容器化应用程序的性能。
Cortex
-
统一的多租户监控:使用 Telegraf 从不同团队或环境收集指标,并将它们推送到带有单独
X-Scope-OrgID
标头的 Cortex。这实现了每个租户的隔离数据摄取和查询,非常适合托管服务和平台团队。 -
将 Prometheus 覆盖范围扩展到边缘设备:在边缘或 IoT 设备上部署 Telegraf 以收集系统指标并将它们发送到集中的 Cortex 集群。这种方法确保了即使在没有本地 Prometheus 抓取器的环境中也能保持一致的可观测性。
-
具有联邦租户的全球服务可观测性:通过配置 Telegraf 代理将数据推送到区域 Cortex 集群(每个集群都标记有租户标识符)来聚合来自全球基础设施的指标。Cortex 处理跨区域的重复数据删除和集中式访问。
-
自定义应用程序遥测管道:通过 Telegraf 的
exec
或http
输入插件收集特定于应用程序的遥测数据,并将其转发到 Cortex。这允许 DevOps 团队以可扩展、查询高效的格式监控特定于应用程序的 KPI,同时保持指标按租户或服务进行逻辑分组。
反馈
感谢您成为我们社区的一份子!如果您有任何一般性反馈或在这些页面上发现了任何错误,我们欢迎并鼓励您提出意见。请在 InfluxDB 社区 Slack 中提交您的反馈。