Splunk 指标输出数据格式
使用 splunkmetric
输出数据格式(序列化器)以 Splunk 指标索引可以使用的格式输出 Telegraf 指标。
输出数据格式可以使用文件输出写入文件,或者使用标准 Telegraf HTTP 输出将指标发送到 HEC。
如果您正在使用 HTTP 输出,则此序列化器知道如何批量处理指标,因此您不会最终为每个指标发送一个 HTTP POST 请求。
数据以符合此处指定的 Splunk HEC JSON 格式的格式输出:以 JSON 格式发送指标。
示例事件如下所示
{
"time": 1529708430,
"event": "metric",
"host": "patas-mbp",
"fields": {
"_value": 0.6,
"cpu": "cpu0",
"dc": "mobile",
"metric_name": "cpu.usage_user",
"user": "ronnocol"
}
}
在上面的代码片段中,以下键是维度
- cpu
- dc
- user
与 HTTP 输出一起使用
要将此数据发送到 Splunk HEC,您可以使用 HTTP 输出,您需要添加一些自定义标头来管理 HEC 授权,这是一个 HTTP 输出的示例配置
[[outputs.http]]
## URL is the address to send metrics to
url = "https://localhost:8088/services/collector"
## Timeout for HTTP message
# timeout = "5s"
## HTTP method, one of: "POST" or "PUT"
# method = "POST"
## HTTP Basic Auth credentials
# username = "username"
# password = "pa$$word"
## 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
## Data format to output.
## Each data format has it's own unique set of configuration options, read
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
data_format = "splunkmetric"
## Provides time, index, source overrides for the HEC
splunkmetric_hec_routing = true
## Additional HTTP headers
[outputs.http.headers]
# Should be set manually to "application/json" for json data_format
Content-Type = "application/json"
Authorization = "Splunk xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
X-Splunk-Request-Channel = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
覆盖
您可以通过向配置文件添加其他标签来覆盖您正在使用的 HEC 令牌的默认值。
令牌的以下方面可以使用标签覆盖
- index
- source
您可以使用 [global_tags]
或使用更高级的配置,如此处所述。
例如,此示例仅覆盖 cpu 指标上的索引
[[inputs.cpu]]
percpu = false
totalcpu = true
[inputs.cpu.tags]
index = "cpu_metrics"
与文件输出一起使用
在具有 Splunk forwarder 的计算机上运行 Telegraf 时,可以使用文件输出。
当 hec_routing
为 false(或未设置)时的示例事件如下所示
{
"_value": 0.6,
"cpu": "cpu0",
"dc": "mobile",
"metric_name": "cpu.usage_user",
"user": "ronnocol",
"time": 1529708430
}
以这种方式格式化的数据可以使用如下所示的简单 props.conf
文件进行摄取
[telegraf]
category = Metrics
description = Telegraf Metrics
pulldown_type = 1
DATETIME_CONFIG =
NO_BINARY_CHECK = true
SHOULD_LINEMERGE = true
disabled = false
INDEXED_EXTRACTIONS = json
KV_MODE = none
TIMESTAMP_FIELDS = time
TIME_FORMAT = %s.%3N
基于文件的输出的示例配置是
# Send telegraf metrics to file(s)
[[outputs.file]]
## Files to write to, "stdout" is a specially handled file.
files = ["/tmp/metrics.out"]
## Data format to output.
## Each data format has its own unique set of configuration options, read
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
data_format = "splunkmetric"
hec_routing = false
此页面对您有帮助吗?
感谢您的反馈!