目录
输入和输出集成概述
HTTP 插件允许从指定的 HTTP 端点收集指标,处理各种数据格式和身份验证方法。
Loki 插件允许用户将日志发送到 Loki 进行聚合和查询,从而利用 Loki 的高效存储能力。
集成详情
HTTP
HTTP 插件从一个或多个 HTTP(S) 端点收集指标,这些端点应具有以受支持的输入数据格式之一格式化的指标。它还支持来自 secret-store 的密钥,用于各种身份验证选项,并包括全局支持的配置设置。
Loki
此 Loki 插件与 Grafana Loki 集成,Grafana Loki 是一个强大的日志聚合系统。通过以与 Loki 兼容的格式发送日志,此插件可以高效地存储和查询日志。每个日志条目都以键值格式结构化,其中键表示字段名称,值表示相应的日志信息。按时间戳对日志进行排序可确保通过 Loki 查询时,日志流保持时间顺序。此插件对密钥的支持使安全管理身份验证参数变得更加容易,而 HTTP 标头、gzip 编码和 TLS 配置的选项增强了日志传输的适应性和安全性,从而满足各种部署需求。
配置
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"
Loki
[[outputs.loki]]
## The domain of Loki
domain = "https://loki.domain.tld"
## Endpoint to write api
# endpoint = "/loki/api/v1/push"
## Connection timeout, defaults to "5s" if not set.
# timeout = "5s"
## Basic auth credential
# username = "loki"
# password = "pass"
## Additional HTTP headers
# http_headers = {"X-Scope-OrgID" = "1"}
## If the request must be gzip encoded
# gzip_request = false
## Optional TLS Config
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem"
## Sanitize Tag Names
## If true, all tag names will have invalid characters replaced with
## underscores that do not match the regex: ^[a-zA-Z_:][a-zA-Z0-9_:]*.
# sanitize_label_names = false
## Metric Name Label
## Label to use for the metric name to when sending metrics. If set to an
## empty string, this will not add the label. This is NOT suggested as there
## is no way to differentiate between multiple metrics.
# metric_name_label = "__name"
输入和输出集成示例
HTTP
- 从本地主机收集指标: 该插件可以从 HTTP 端点(如
http://localhost/metrics
)获取指标,从而实现简单的本地监控。 - 使用 Unix 域套接字: 您可以通过使用 http+unix 方案来指定从 Unix 域套接字上的服务收集指标,例如,
http+unix:///path/to/service.sock:/api/endpoint
。
Loki
-
微服务的集中式日志记录:利用 Loki 插件收集在 Kubernetes 集群中运行的多个微服务的日志。通过将日志定向到集中的 Loki 实例,开发人员可以在一个地方监控、搜索和分析来自所有服务的日志,从而更轻松地进行故障排除和性能监控。此设置简化了操作,并支持对分布式应用程序中问题的快速响应。
-
实时日志异常检测:将 Loki 与监控工具结合使用,以实时分析日志输出中可能表明系统错误或安全威胁的异常模式。在日志流上实施异常检测使团队能够主动识别和响应事件,从而提高系统可靠性并增强安全态势。
-
通过 Gzip 压缩增强日志处理:配置 Loki 插件以利用 gzip 压缩进行日志传输。这种方法可以减少带宽使用并提高传输速度,这在网络带宽可能受到限制的环境中尤其有利。它对于每字节都很重要且性能至关重要的大容量日志记录应用程序尤其有用。
-
通过自定义标头支持多租户:利用添加自定义 HTTP 标头的功能,在多租户应用程序环境中隔离来自不同租户的日志。通过使用 Loki 插件为每个租户发送不同的标头,运营商可以确保正确的日志管理并符合数据隔离要求,使其成为 SaaS 应用程序的通用解决方案。
反馈
感谢您成为我们社区的一份子!如果您有任何一般性反馈或在这些页面上发现任何错误,我们欢迎并鼓励您提出意见。请在 InfluxDB 社区 Slack 中提交您的反馈。