目录
输入和输出集成概述
HTTP 插件允许从指定的 HTTP 端点收集指标,处理各种数据格式和身份验证方法。
此插件使 Telegraf 能够使用 Prometheus 远程写入协议将指标发送到 Cortex,从而实现无缝摄取到 Cortex 的可扩展、多租户时序存储中。
集成详情
HTTP
HTTP 插件从一个或多个 HTTP(S) 端点收集指标,这些端点应具有以支持的输入数据格式之一格式化的指标。 它还支持来自 secret-stores 的密钥,用于各种身份验证选项,并包括全局支持的配置设置。
Cortex
借助 Telegraf 的 HTTP 输出插件和 `prometheusremotewrite` 数据格式,您可以将指标直接发送到 Cortex,Cortex 是 Prometheus 的水平可扩展的长期存储后端。 Cortex 支持多租户,并使用 Prometheus protobuf 格式接受远程写入请求。 通过使用 Telegraf 作为收集代理和 Remote Write 作为传输机制,组织可以将可观察性扩展到 Prometheus 本身不支持的来源(例如 Windows 主机、支持 SNMP 的设备或自定义应用程序指标),同时利用 Cortex 的高可用性和长期保留能力。
配置
HTTP
[[inputs.http]]
## One or more URLs from which to read formatted metrics.
urls = [
"http://localhost/metrics",
"http+unix:///run/user/420/podman/podman.sock:/d/v4.0.0/libpod/pods/json"
]
## HTTP method
# method = "GET"
## Optional HTTP headers
# headers = {"X-Special-Header" = "Special-Value"}
## HTTP entity-body to send with POST/PUT requests.
# body = ""
## HTTP Content-Encoding for write request body, can be set to "gzip" to
## compress body or "identity" to apply no encoding.
# content_encoding = "identity"
## Optional Bearer token settings to use for the API calls.
## Use either the token itself or the token file if you need a token.
# token = "eyJhbGc...Qssw5c"
# token_file = "/path/to/file"
## Optional HTTP Basic Auth Credentials
# username = "username"
# password = "pa$$word"
## OAuth2 Client Credentials. The options 'client_id', 'client_secret', and 'token_url' are required to use OAuth2.
# client_id = "clientid"
# client_secret = "secret"
# token_url = "https://indentityprovider/oauth2/v1/token"
# scopes = ["urn:opc:idm:__myscopes__"]
## HTTP Proxy support
# use_system_proxy = false
# http_proxy_url = ""
## Optional TLS Config
## Set to true/false to enforce TLS being enabled/disabled. If not set,
## enable TLS only if any of the other options are specified.
# tls_enable =
## Trusted root certificates for server
# tls_ca = "/path/to/cafile"
## Used for TLS client certificate authentication
# tls_cert = "/path/to/certfile"
## Used for TLS client certificate authentication
# tls_key = "/path/to/keyfile"
## Password for the key file if it is encrypted
# tls_key_pwd = ""
## Send the specified TLS server name via SNI
# tls_server_name = "kubernetes.example.com"
## Minimal TLS version to accept by the client
# tls_min_version = "TLS12"
## List of ciphers to accept, by default all secure ciphers will be accepted
## See https://pkg.go.dev/crypto/tls#pkg-constants for supported values.
## Use "all", "secure" and "insecure" to add all support ciphers, secure
## suites or insecure suites respectively.
# tls_cipher_suites = ["secure"]
## Renegotiation method, "never", "once" or "freely"
# tls_renegotiation_method = "never"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false
## Optional Cookie authentication
# cookie_auth_url = "https://localhost/authMe"
# cookie_auth_method = "POST"
# cookie_auth_username = "username"
# cookie_auth_password = "pa$$word"
# cookie_auth_headers = { Content-Type = "application/json", X-MY-HEADER = "hello" }
# cookie_auth_body = '{"username": "user", "password": "pa$$word", "authenticate": "me"}'
## cookie_auth_renewal not set or set to "0" will auth once and never renew the cookie
# cookie_auth_renewal = "5m"
## Amount of time allowed to complete the HTTP request
# timeout = "5s"
## List of success status codes
# success_status_codes = [200]
## Data format to consume.
## 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_INPUT.md
# data_format = "influx"
Cortex
[[outputs.http]]
## Cortex Remote Write endpoint
url = "http://cortex.example.com/api/v1/push"
## Use POST to send data
method = "POST"
## Send metrics using Prometheus remote write format
data_format = "prometheusremotewrite"
## Optional HTTP headers for authentication
# [outputs.http.headers]
# X-Scope-OrgID = "your-tenant-id"
# Authorization = "Bearer YOUR_API_TOKEN"
## Optional TLS configuration
# tls_ca = "/path/to/ca.pem"
# tls_cert = "/path/to/cert.pem"
# tls_key = "/path/to/key.pem"
# insecure_skip_verify = false
## Request timeout
timeout = "10s"
输入和输出集成示例
HTTP
- 从本地主机收集指标:该插件可以从 HTTP 端点(如 `http://localhost/metrics`)获取指标,从而实现简单的本地监控。
- 使用 Unix 域套接字:您可以使用 http+unix 方案指定从 Unix 域套接字上的服务收集指标,例如 `http+unix:///path/to/service.sock:/api/endpoint`。
Cortex
-
统一的多租户监控:使用 Telegraf 从不同的团队或环境收集指标,并使用单独的 `X-Scope-OrgID` 标头将其推送到 Cortex。 这使得每个租户的隔离数据摄取和查询成为可能,非常适合托管服务和平台团队。
-
将 Prometheus 覆盖范围扩展到边缘设备:在边缘或 IoT 设备上部署 Telegraf 以收集系统指标并将其发送到中央 Cortex 集群。 这种方法即使对于没有本地 Prometheus 抓取器的环境也能确保一致的可观察性。
-
具有联邦租户的全局服务可观察性:通过配置 Telegraf 代理将数据推送到区域 Cortex 集群(每个集群都标记有租户标识符)来聚合来自全局基础设施的指标。 Cortex 处理跨区域的重复数据删除和集中访问。
-
自定义应用程序遥测管道:通过 Telegraf 的 `exec` 或 `http` 输入插件收集特定于应用程序的遥测数据,并将其转发到 Cortex。 这允许 DevOps 团队以可扩展、查询高效的格式监控特定于应用程序的 KPI,同时保持指标按租户或服务进行逻辑分组。
反馈
感谢您成为我们社区的一份子! 如果您有任何一般性反馈或在这些页面上发现了任何错误,我们欢迎并鼓励您提出意见。 请在 InfluxDB 社区 Slack 中提交您的反馈。