Graphite
Graphite 采集器可以接收以 Graphite plaintext protocol 格式的指标数据,转换并供例如 Prometheus 等使用,只要配置相应的 Exporter 地址,就可以将指标数据接入
配置¶
进入 DataKit 安装目录下的 conf.d/graphite
目录,复制 graphite.conf.sample
并命名为 graphite.conf
。示例如下:
[[inputs.graphite]]
## Address to open UDP/TCP, default 9109
address = ":9109"
# Whether to open StrictMatch
# strict_match = false
## Example Mapping Configuration
#[inputs.graphite.metric_mapper]
# name = "test"
# [[inputs.graphite.metric_mapper.mappings]]
# match = "test.dispatcher.*.*.*"
# name = "dispatcher_events_total"
# measurement_name = "dispatcher_test"
# [inputs.graphite.metric_mapper.mappings.labels]
# action = "$2"
# job = "test_dispatcher"
# outcome = "$3"
# processor = "$1"
# [[inputs.graphite.metric_mapper.mappings]]
# match = "*.signup.*.*"
# name = "signup_events_total"
# measurement_name = "signup_set"
# [inputs.graphite.metric_mapper.mappings.labels]
# job = "${1}_server"
# outcome = "$3"
# provider = "$2"
# Regex Mapping Example
# [[inputs.graphite.metric_mapper.mappings]]
# match = '''servers\.(.*)\.networking\.subnetworks\.transmissions\.([a-z0-9-]+)\.(.*)'''
# match_type = "regex"
# name = "servers_networking_transmissions_${3}"
# measurement_name = "servers_networking"
# [inputs.graphite.metric_mapper.mappings.labels]
# hostname = "${1}"
# device = "${2}"
配置好后,重启 Datakit 即可。
可通过 ConfigMap 方式注入采集器配置 或 配置 ENV_DATAKIT_INPUTS 开启采集器。
指标映射配置¶
Graphite 采集器可以通过在配置文件里配置映射格式将 点格式(例如 testA.testB.testC
)的 Graphite plaintext protocol 转为带标记的指标。这个指标的转换规则类似于 statsd_exporter
的转换规则,但是在这里是 TOML 格式的配置。 在此处进行配置时,需指定指标集的名称 measurement_name
,对应映射的指标将归为指标集内,如果未设置指标集名或没有配置映射规则,则默认在 graphite
指标集下。
没有配置映射规则的指标,会把除 _
, :
之外的符号的非字母数字符号都替换为 _
。
一个示例的映射规则如下:
[inputs.graphite.metric_mapper]
name = "test"
[[inputs.graphite.metric_mapper.mappings]]
match = "test.dispatcher.*.*.*"
name = "dispatcher_events_total"
measurement_name = "dispatcher_test"
[inputs.graphite.metric_mapper.mappings.labels]
action = "$2"
job = "test_dispatcher"
outcome = "$3"
processor = "$1"
[[inputs.graphite.metric_mapper.mappings]]
match = "*.signup.*.*"
name = "signup_events_total"
measurement_name = "signup_set"
[inputs.graphite.metric_mapper.mappings.labels]
job = "${1}_server"
outcome = "$3"
provider = "$2"
[[inputs.graphite_metric_mapper.mappings]]
match = "servers\\.(.*)\\.networking\\.subnetworks\\.transmissions\\.([a-z0-9-]+)\\.(.*)"
match_type = "regex"
name = "servers_networking_transmissions_${3}"
measurement_name = "servers_networking"
[inputs.graphite.metric_mapper.mappings.labels]
hostname = "${1}"
device = "${2}"
以上规则会把 Graphite 指标转为以下的格式:
test.dispatcher.FooProcessor.send.success
=> dispatcher_events_total{processor="FooProcessor", action="send", outcome="success", job="test_dispatcher"}
foo_product.signup.facebook.failure
=> signup_events_total{provider="facebook", outcome="failure", job="foo_product_server"}
test.web-server.foo.bar
=> test_web__server_foo_bar{}
servers.rack-003-server-c4de.networking.subnetworks.transmissions.eth0.failure.mean_rate
=> servers_networking_transmissions_failure_mean_rate{device="eth0",hostname="rack-003-server-c4de"}
支持的映射规则说明¶
全局映射(Glob mapping)¶
默认的全局映射规则使用 *
去代表指标中动态的部分。
注意:此时使用的是 点格式 指标,例如
test.a.b.c.d
。
类似的配置如下:
[inputs.graphite.metric_mapper]
name = "test"
[[inputs.graphite.metric_mapper.mappings]]
match = "test.dispatcher.*.*.*"
name = "dispatcher_events_total"
[inputs.graphite.metric_mapper.mappings.labels]
action = "$2"
job = "test_dispatcher"
outcome = "$3"
processor = "$1"
[[inputs.graphite.metric_mapper.mappings]]
match = "*.signup.*.*"
name = "signup_events_total"
[inputs.graphite.metric_mapper.mappings.labels]
job = "${1}_server"
outcome = "$3"
provider = "$2"
转换得到的内容如下:
test.dispatcher.FooProcessor.send.success
=> dispatcher_events_total{processor="FooProcessor", action="send", outcome="success", job="test_dispatcher"}
foo_product.signup.facebook.failure
=> signup_events_total{provider="facebook", outcome="failure", job="foo_product_server"}
test.web-server.foo.bar
=> test_web_server_foo_bar{}
注意: 每个映射规则都必须有
name
字段,用$n
来匹配行中的第n
个替换。
[[inputs.graphite.metric_mapper.mappings]]
match = "test.*.*.counter"
name = "${2}_total"
measurement_name = "test_counter"
[inputs.graphite.metric_mapper.mappings.labels]
provider = "$1"
例如 test.a.b.counter
,对应的 $1$
则为 a
,对应的 $2
则为 b
,以此类推。
正则匹配规则¶
正则匹配规则使用常规的正则匹配来匹配指标名。需指定 match_type = regex
注意: 正则匹配相较于全局规则较慢
示例如下:
[[inputs.graphite_metric_mapper.mappings]]
match = "servers\.(.*)\.networking\.subnetworks\.transmissions\.([a-z0-9-]+)\.(.*)"
match_type = "regex"
name = "servers_networking_transmissions_${3}"
measurement_name = "servers_networking"
[inputs.graphite.metric_mapper.mappings.labels]
hostname = "${1}"
device = "${2}"
注意: 在 TOML 里,在字符串中反斜杠 (
\
) 需要被转义才能使用,因此需要使用\\
更多规则¶
请参照 statsd_exporter
严格匹配¶
如果在 配置了映射规则的前提下,只想要配置了映射规则的指标而忽略掉所以未配置规则的指标,可以通过设置 strict_match
来实现。