文档文档

StatsD 输入插件

此服务插件从 Statsd 服务器收集指标。

引入于: Telegraf v0.2.0 标签: applications 操作系统支持: all

服务输入

此插件是服务输入。普通插件收集由 interval 设置确定的指标。服务插件启动一个服务来监听并等待指标或事件发生。服务插件与普通插件的两个主要区别是:

  1. 全局或插件特定的 interval 设置可能不适用
  2. --test--test-wait--once 的 CLI 选项可能不会为此插件生成输出

全局配置选项

插件支持其他全局和插件配置设置,用于修改指标、标签和字段,创建别名以及配置插件顺序等任务。更多详情请参阅 CONFIGURATION.md

配置

# Statsd Server
[[inputs.statsd]]
  ## Protocol, must be "tcp", "udp4", "udp6" or "udp" (default=udp)
  protocol = "udp"

  ## MaxTCPConnection - applicable when protocol is set to tcp (default=250)
  max_tcp_connections = 250

  ## Enable TCP keep alive probes (default=false)
  tcp_keep_alive = false

  ## Specifies the keep-alive period for an active network connection.
  ## Only applies to TCP sockets and will be ignored if tcp_keep_alive is false.
  ## Defaults to the OS configuration.
  # tcp_keep_alive_period = "2h"

  ## Address and port to host UDP listener on
  service_address = ":8125"

  ## The following configuration options control when telegraf clears it's cache
  ## of previous values. If set to false, then telegraf will only clear it's
  ## cache when the daemon is restarted.
  ## Reset gauges every interval (default=true)
  delete_gauges = true
  ## Reset counters every interval (default=true)
  delete_counters = true
  ## Reset sets every interval (default=true)
  delete_sets = true
  ## Reset timings & histograms every interval (default=true)
  delete_timings = true

  ## Enable aggregation temporality adds temporality=delta or temporality=commulative tag, and
  ## start_time field, which adds the start time of the metric accumulation.
  ## You should use this when using OpenTelemetry output.
  # enable_aggregation_temporality = false

  ## Percentiles to calculate for timing & histogram stats.
  percentiles = [50.0, 90.0, 99.0, 99.9, 99.95, 100.0]

  ## separator to use between elements of a statsd metric
  metric_separator = "_"

  ## Parses extensions to statsd in the datadog statsd format
  ## currently supports metrics and datadog tags.
  ## http://docs.datadoghq.com/guides/dogstatsd/
  datadog_extensions = false

  ## Parses distributions metric as specified in the datadog statsd format
  ## https://docs.datadoghq.com/developers/metrics/types/?tab=distribution#definition
  datadog_distributions = false

  ## Keep or drop the container id as tag. Included as optional field
  ## in DogStatsD protocol v1.2 if source is running in Kubernetes
  ## https://docs.datadoghq.com/developers/dogstatsd/datagram_shell/?tab=metrics#dogstatsd-protocol-v12
  datadog_keep_container_tag = false

  ## Statsd data translation templates, more info can be read here:
  ## https://github.com/influxdata/telegraf/blob/master/docs/TEMPLATE_PATTERN.md
  # templates = [
  #     "cpu.* measurement*"
  # ]

  ## Number of UDP messages allowed to queue up, once filled,
  ## the statsd server will start dropping packets
  allowed_pending_messages = 10000

  ## Number of worker threads used to parse the incoming messages.
  # number_workers_threads = 5

  ## Number of timing/histogram values to track per-measurement in the
  ## calculation of percentiles. Raising this limit increases the accuracy
  ## of percentiles but also increases the memory usage and cpu time.
  percentile_limit = 1000

  ## Maximum socket buffer size in bytes, once the buffer fills up, metrics
  ## will start dropping.  Defaults to the OS default.
  # read_buffer_size = 65535

  ## Max duration (TTL) for each metric to stay cached/reported without being updated.
  # max_ttl = "10h"

  ## Sanitize name method
  ## By default, telegraf will pass names directly as they are received.
  ## However, upstream statsd now does sanitization of names which can be
  ## enabled by using the "upstream" method option. This option will a) replace
  ## white space with '_', replace '/' with '-', and remove characters not
  ## matching 'a-zA-Z_\-0-9\.;='.
  #sanitize_name_method = ""

  ## Replace dots (.) with underscore (_) and dashes (-) with
  ## double underscore (__) in metric names.
  # convert_names = false

  ## Convert all numeric counters to float
  ## Enabling this would ensure that both counters and guages are both emitted
  ## as floats.
  # float_counters = false

  ## Emit timings `metric_<name>_count` field as float, the same as all other
  ## histogram fields
  # float_timings = false

  ## Emit sets as float
  # float_sets = false

描述

Statsd 插件是一种特殊类型的插件,它在 telegraf 运行时运行一个后台 statsd 监听服务。

Statsd 消息的格式基于原始 etsy statsd 实现中描述的格式。简而言之,telegraf statsd 监听器将接受

  • Gauge (量规)
    • users.current.den001.myapp:32|g <- 标准
    • users.current.den001.myapp:+10|g <- 加法
    • users.current.den001.myapp:-10|g
  • Counter (计数器)
    • deploys.test.myservice:1|c <- 增量 1
    • deploys.test.myservice:101|c <- 增量 101
    • deploys.test.myservice:1|c|@0.1 <- 带有采样率,增量 10
  • Set (集合)
    • users.unique:101|s
    • users.unique:101|s
    • users.unique:102|s <- 会导致 `users.unique` 的计数为 2
  • Timing (计时) & Histogram (直方图)
    • load.time:320|ms
    • load.time.nanoseconds:1|h
    • load.time:200|ms|@0.1 <- 以 1/10 的频率采样
  • Distribution (分布)
    • load.time:320|d
    • load.time.nanoseconds:1|d
    • load.time:200|d|@0.1 <- 以 1/10 的频率采样

可以通过添加额外的冒号来省略重复的名称并将单个统计数据合并到一行中

  • users.current.den001.myapp:32|g:+10|g:-10|g
  • deploys.test.myservice:1|c:101|c:1|c|@0.1
  • users.unique:101|s:101|s:102|s
  • load.time:320|ms:200|ms|@0.1

这还允许在单行中混合不同类型

  • foo:1|c:200|ms

字符串 foo:1|c:200|ms 在内部被拆分为两个独立的度量 foo:1|cfoo:200|ms,它们被分别添加到聚合器中。

Influx Statsd

为了利用 InfluxDB 的标签系统,我们对标准的 statsd 协议进行了几项补充。首先,您可以采用类似于行协议的方式指定标签,如下所示

users.current,service=payroll,region=us-west:32|g

Metrics

Meta

  • tags: metric_type=<gauge|set|counter|timing|histogram>

输出的度量值将完全取决于用户发送的度量值,但以下是您可以从每种度量类型中预期找到的内容的简要概述

  • Gauge (量规)
    • Gauge (量规) 是一种恒定数据类型。它们不受平均值的影响,除非您更改它们,否则它们不会改变。也就是说,一旦您设置了一个量规值,它将在图表上显示为一条直线,直到您再次更改它。
  • Counter (计数器)
    • Counter (计数器) 是最基本类型。它们被视为事件类型的计数。除非您设置 delete_counters=true,否则它们将持续增加。
  • Set (集合)
    • Set (集合) 计算传递给键的唯一值的数量。例如,您可以使用 users:<user_id>|s 来计算访问您系统的用户数量。无论相同的 user_id 发送多少次,计数只会增加 1。
  • Timing (计时) & Histogram (直方图)
    • Timer (计时器) 用于跟踪某项任务花费了多长时间。它们是跟踪应用程序性能的宝贵工具。
    • 为计时器进行的聚合度量如下
      • statsd_<name>_lower:下限是 statsd 在该时间间隔内看到的该统计数据的最低值。
      • statsd_<name>_upper:上限是 statsd 在该时间间隔内看到的该统计数据的最高值。
      • statsd_<name>_mean:平均值是 statsd 在该时间间隔内看到的该统计数据的 averages。
      • statsd_<name>_median:中位数是 statsd 在该时间间隔内看到的该统计数据的中间值。
      • statsd_<name>_stddev:标准差是 statsd 在该时间间隔内看到的该统计数据的 samples。
      • statsd_<name>_sum:总和是 statsd 在该时间间隔内看到的该统计数据的 samples。
      • statsd_<name>_count:计数是 statsd 在该时间间隔内看到的该统计数据的数量。它不进行平均。
      • statsd_<name>_percentile_<P> P 百分位数是值 x,使得在此时间段内 statsd 看到的 P% 的值都小于 x。人们最常用于 P 的值是 90,这是一个很好的优化目标。
  • Distribution (分布)
    • Distribution (分布) 度量表示在单个时间间隔内跨整个分布式基础架构计算的一组值的全局统计分布。分布可用于独立于底层主机来 instrument 逻辑对象,例如服务。
    • 与在给定时间间隔内聚合的 Agent 上的 Histogram (直方图) 度量类型不同,Distribution (分布) 度量在时间间隔内发送所有原始数据。

插件参数

  • protocol string:监听器使用的协议 - tcp 或 udp 选项
  • max_tcp_connections []int:允许的最大并发 TCP 连接数。在 protocol 设置为 tcp 时使用。
  • tcp_keep_alive boolean:启用 TCP keep alive 探测
  • tcp_keep_alive_period duration:指定活动网络连接的 keep-alive 周期
  • service_address string:用于监听 statsd UDP 数据包的地址
  • delete_gauges boolean:在每个收集间隔删除量规
  • delete_counters boolean:在每个收集间隔删除计数器
  • delete_sets boolean:在每个收集间隔删除集合计数器
  • delete_timings boolean:在每个收集间隔删除计时
  • percentiles []int:为计时 & 直方图统计计算的百分位数
  • allowed_pending_messages integer:允许排队等待处理的消息数量。当达到此数量时,消息将被丢弃并记录。
  • percentile_limit integer:计算百分位数时要跟踪的每个度量的计时/直方图值数量。提高此限制会提高百分位数的准确性,但也会增加内存使用量和 CPU 时间。
  • templates []string:用于将 statsd bucket 转换为 influx 度量和标签的模板。
  • parse_data_dog_tags boolean:启用对 DataDog 的 dogstatsd 格式 中标签的解析
  • datadog_extensions boolean:启用对 DataDog 扩展到 dogstatsd 格式 及更多内容的解析
  • datadog_distributions boolean:启用对 DataDog 的分布格式中 Distribution (分布) 度量的解析
  • datadog_keep_container_tag boolean:保留或删除容器 ID 作为标签。如果源在 Kubernetes 中运行,则作为 DogStatsD 协议 v1.2 中的可选字段包含。
  • max_ttl config.Duration:每个度量在未更新的情况下缓存/报告的最大持续时间(TTL)。

Statsd bucket -> InfluxDB 行协议模板

该插件支持指定模板,用于将 statsd bucket 转换为 InfluxDB 度量名称和标签。模板具有一个 measurement 关键字,可用于指定 bucket 中要用于度量名称的部分。模板中的其他词用作标签名称。例如,以下模板

templates = [
    "measurement.measurement.region"
]

将导致以下转换

cpu.load.us-west:100|g
=> cpu_load,region=us-west 100

用户还可以通过 glob 匹配来过滤模板以供使用,如下所示

templates = [
    "cpu.* measurement.measurement.region",
    "mem.* measurement.measurement.host"
]

将导致以下转换

cpu.load.us-west:100|g
=> cpu_load,region=us-west 100

mem.cached.localhost:256|g
=> mem_cached,host=localhost 256

有关更多详细信息,请参阅模板模式文档。

示例输出


此页面是否有帮助?

感谢您的反馈!


InfluxDB 3.8 新特性

InfluxDB 3.8 和 InfluxDB 3 Explorer 1.6 的主要增强功能。

查看博客文章

InfluxDB 3.8 现已适用于 Core 和 Enterprise 版本,同时发布了 InfluxDB 3 Explorer UI 的 1.6 版本。本次发布着重于操作成熟度,以及如何更轻松地部署、管理和可靠地运行 InfluxDB。

更多信息,请查看

InfluxDB Docker 的 latest 标签将指向 InfluxDB 3 Core

在 **2026 年 2 月 3 日**,InfluxDB Docker 镜像的 latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。

如果使用 Docker 来安装和运行 InfluxDB,latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。例如,如果使用 Docker 运行 InfluxDB v2,请将 latest 版本标签替换为 Docker pull 命令中的特定版本标签 — 例如

docker pull influxdb:2