Graphite 协议在 InfluxDB 中的支持
此页面记录了 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 行协议保存指标。默认情况下,启用 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
添加标签
如果附加标签在接收到的指标上不存在,则可以将其添加到指标中。您可以通过在模式后指定它们来添加附加标签。标签的格式与行协议相同。多个标签用逗号分隔。
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。
此页面是否对您有帮助?
感谢您的反馈!