InfluxDB 中的 Graphite 协议支持
此页面记录了早期版本的 InfluxDB OSS。 InfluxDB OSS v2 是最新的稳定版本。 请参阅 InfluxDB v2 文档。
Graphite 输入
关于 UDP/IP 操作系统缓冲区大小的说明
如果您正在使用 UDP 输入并运行 Linux 或 FreeBSD,请调整您的 UDP 缓冲区大小限制,请参阅此处了解更多详情。
配置
每个 Graphite 输入允许设置绑定地址、目标数据库和协议。如果数据库不存在,则会在初始化输入时自动创建。还可以设置 write-consistency-level。如果任何写入操作不满足配置的一致性保证,则会发生错误,并且数据将不会被索引。默认 consistency-level 为 ONE
。
每个 Graphite 输入还对其接收的点执行内部批处理,因为批量写入数据库效率更高。默认批处理大小为 1000,待处理批处理因子为 5,批处理超时为 1 秒。这意味着输入将写入最大大小为 1000 的批次,但如果批次在添加到批次的第一个点后的 1 秒内未达到 1000 个点,则无论大小如何,它都会发出该批次。待处理批处理因子控制一次可以在内存中存在的批次数量,允许输入传输一个批次,同时仍然构建其他批次。
解析指标
Graphite 插件允许使用 Graphite Line Protocol 保存指标。默认情况下,启用 Graphite 插件将允许您收集指标并使用指标名称作为度量来存储它们。如果您发送一个名为 servers.localhost.cpu.loadavg.10
的指标,它将存储完整的指标名称作为度量,而不会提取标签。
虽然此默认设置有效,但这并不是在 InfluxDB 中存储度量的理想方式,因为它没有利用标签。它在大型数据集大小的情况下也不会最佳地执行,因为查询将被迫使用正则表达式,而正则表达式已知无法很好地扩展。
要从指标中提取标签,必须配置一个或多个模板以将指标解析为标签和度量。
模板
模板允许将指标名称的匹配部分用作存储度量中的标签键。它们的格式与 Graphite 指标名称类似。分隔符之间的值用作标签键。与 Graphite 指标部分相同位置匹配的标签键的位置用作值。如果没有值,则跳过 Graphite 部分。
特殊值measurement用于定义度量名称。它可以有一个尾随 *
以指示应使用指标的其余部分。如果未指定measurement,则使用完整的指标名称。
基本匹配
servers.localhost.cpu.loadavg.10
- 模板:
.host.resource.measurement*
- 输出: measurement =
loadavg.10
tags =host=localhost resource=cpu
多重度量和标签匹配
measurement可以在模板中多次指定,以提供对度量名称的更多控制。标签也可以多次匹配。多个值将使用Separator配置变量连接在一起。默认情况下,此值为 .
。
servers.localhost.localdomain.cpu.cpu0.user
- 模板:
.host.host.measurement.cpu.measurement
- 输出: measurement =
cpu.user
tags =host=localhost.localdomain cpu=cpu0
由于 .
要求对度量的查询使用双引号,因此您可能希望将其设置为 _
以简化查询解析的度量。
servers.localhost.cpu.cpu0.user
- 分隔符:
_
- 模板:
.host.measurement.cpu.measurement
- 输出: measurement =
cpu_user
tags =host=localhost cpu=cpu0
添加标签
如果指标上不存在其他标签,则可以将其添加到指标中。您可以通过在模式后指定它们来添加其他标签。标签的格式与 Line Protocol 相同。多个标签用逗号分隔。
servers.localhost.cpu.loadavg.10
- 模板:
.host.resource.measurement* region=us-west,zone=1a
- 输出: measurement =
loadavg.10
tags =host=localhost resource=cpu region=us-west zone=1a
字段
可以通过使用关键字field来指定字段键。默认情况下,如果未指定field关键字,则指标将写入名为value的字段。
字段键也可以通过指定 field*
从输入指标名称的第二个“半部分”派生(例如 measurement.measurement.field*
)。这不能与“measurement*”结合使用!
可以修改带有附加字段的度量指标,例如
输入
sensu.metric.net.server0.eth0.rx_packets 461295119435 1444234982
sensu.metric.net.server0.eth0.tx_bytes 1093086493388480 1444234982
sensu.metric.net.server0.eth0.rx_bytes 1015633926034834 1444234982
sensu.metric.net.server0.eth0.tx_errors 0 1444234982
sensu.metric.net.server0.eth0.rx_errors 0 1444234982
sensu.metric.net.server0.eth0.tx_dropped 0 1444234982
sensu.metric.net.server0.eth0.rx_dropped 0 1444234982
使用模板
sensu.metric.* ..measurement.host.interface.field
变为数据库条目
> select * from net
name: net
---------
time host interface rx_bytes rx_dropped rx_errors rx_packets tx_bytes tx_dropped tx_errors
1444234982000000000 server0 eth0 1.015633926034834e+15 0 0 4.61295119435e+11 1.09308649338848e+15 0 0
多个模板
一个模板可能无法匹配所有指标。例如,将多个插件与 diamond 一起使用将生成不同格式的指标。如果您需要使用多个模板,则需要定义一个前缀过滤器,该过滤器必须匹配才能应用模板。
过滤器
过滤器具有与模板类似的格式,但更像通配符表达式。当多个过滤器将匹配一个指标时,将选择更具体的过滤器。通过在模板之前添加过滤器来配置过滤器。
例如,
servers.localhost.cpu.loadavg.10
servers.host123.elasticsearch.cache_hits 100
servers.host456.mysql.tx_count 10
servers.host789.prod.mysql.tx_count 10
servers.*
将匹配所有值servers.*.mysql
将匹配servers.host456.mysql.tx_count 10
servers.localhost.*
将匹配servers.localhost.cpu.loadavg
servers.*.*.mysql
将匹配servers.host789.prod.mysql.tx_count 10
默认模板
如果未定义模板过滤器,或者您只想拥有一个基本模板,则可以定义默认模板。此模板将应用于尚未匹配过滤器的任何指标。
dev.http.requests.200
prod.myapp.errors.count
dev.db.queries.count
env.app.measurement*
将创建- measurement=
requests.200
tags=env=dev,app=http
- measurement=
errors.count
tags=env=prod,app=myapp
- measurement=
queries.count
tags=env=dev,app=db
- measurement=
全局标签
如果您需要将同一组标签添加到所有指标,则可以在插件级别全局定义它们,而不是在每个模板描述中定义。
最小配置
[[graphite]]
enabled = true
# bind-address = ":2003"
# protocol = "tcp"
# consistency-level = "one"
### If matching multiple measurement files, this string will be used to join the matched values.
# separator = "."
### Default tags that will be added to all metrics. These can be overridden at the template level
### or by tags extracted from metric
# tags = ["region=us-east", "zone=1c"]
### Each template line requires a template pattern. It can have an optional
### filter before the template and separated by spaces. It can also have optional extra
### tags following the template. Multiple tags should be separated by commas and no spaces
### similar to the line protocol format. The can be only one default template.
# templates = [
# "*.app env.service.resource.measurement",
# # Default template
# "server.*",
#]
自定义配置
[[graphite]]
enabled = true
separator = "_"
tags = ["region=us-east", "zone=1c"]
templates = [
# filter + template
"*.app env.service.resource.measurement",
# filter + template + extra tag
"stats.* .host.measurement* region=us-west,agent=sensu",
# filter + template with field key
"stats.* .host.measurement.field",
# default template. Ignore the first Graphite component "servers"
".measurement*",
]
两个 Graphite 监听器,UDP 和 TCP,配置
[[graphite]]
enabled = true
bind-address = ":2003"
protocol = "tcp"
# consistency-level = "one"
[[graphite]]
enabled = true
bind-address = ":2004" # the bind address
protocol = "udp" # protocol to read via
udp-read-buffer = 8388608 # (8*1024*1024) UDP read buffer size
内容来自 GitHub 上的 README。
此页内容是否对您有帮助?
感谢您的反馈!