LogQL 输入插件
此插件通过 HTTP API 使用 LogQL 查询从 Loki 端点收集指标。
引入于: Telegraf v1.37.0 标签: datastore 操作系统支持: all
全局配置选项
插件支持其他全局和插件配置设置,用于修改指标、标签和字段,创建别名以及配置插件顺序等任务。更多详情请参阅 CONFIGURATION.md。
Secret-store 支持
此插件支持从 secret-stores 中获取 username、password 和 token 选项的密钥。有关如何使用它们的更多详细信息,请参阅 secret-store 文档。
配置
# Query Loki endpoints using LogQL
[[inputs.logql]]
## URL of the Loki endpoint
# url = "https://:3100"
## Basic authentication properties
# username = ""
# password = ""
## Bearer token based authentication
# token = ""
## Organization IDs for the queries in multi-tenant setups
# organizations = []
## Timeout for executing queries with zero meaning no timeout
# timeout = "5s"
## HTTP connection settings
# idle_conn_timeout = "0s"
# max_idle_conn = 0
# max_idle_conn_per_host = 0
# response_timeout = "0s"
## Optional proxy settings
# use_system_proxy = false
# http_proxy_url = ""
## Optional TLS settings
## 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
## Instant queries, multiple instances are allowed
# [[inputs.logql.instant]]
# ## Fallback name of the resulting metrics to use as metric name in case
# ## the __name__ property of the query results is empty.
# # name = "logql"
#
# ## Query to execute
# query = 'count_over_time({job="varlogs"}[24h])'
#
# ## Sorting direction of logs, either "forward" or "backward"
# # sorting = "backward"
#
# ## Limit for the number of results returned by the server with zero
# ## meaning no limit
# # limit = 0
## Range queries, multiple instances are allowed
# [[inputs.logql.range]]
# ## Fallback name of the resulting metrics to use as metric name in case
# ## the __name__ property of the query results is empty.
# # name = "logql"
#
# ## Query to execute
# query = '{job="varlogs"}'
#
# ## Range parameters relative to the gathering time with positive values
# ## refer to BEFORE and negative to AFTER the gathering time
# start = "5m"
# # end = "0s"
# # step = "0s"
# # interval = "0s"
#
# ## Sorting direction of logs, either "forward" or "backward"
# # sorting = "backward"
#
# ## Limit for the number of results returned by the server with zero
# ## meaning no limit
# # limit = 0您可以选择不使用身份验证或使用基本身份验证或使用基于 Bearer Token 的身份验证。同时启用基本身份验证和基于 Bearer Token 的身份验证将会失败。
Metrics
此输入插件收集的指标将取决于指定的查询。然而,生成的指标对于返回的结果将具有以下结构。
向量和矩阵结果
向量和指标结果将生成一个或多个指标,指标名称可以是 logql 或查询中指定的 name。如果结果的标签不是内部的(不以双下划线 __<label>__ 开头和结尾),则它们将被保留为标签。每个样本的返回值将存储在名为 value 的字段中,Loki 提供的时间戳将用作指标时间戳。
流式结果
流式结果将生成一个或多个指标,指标名称可以是 logql 或查询中指定的 name。如果结果的标签不是内部的(不以双下划线 __<label>__ 开头和结尾),则它们将被保留为标签。每个样本返回的日志行将存储在名为 message 的字段中,Loki 提供的时间戳将用作指标时间戳。
示例输出
例如,即时查询
sum(rate({job="varlogs"}[5m])) by (detected_level)返回
logql,detected_level=error,host=Hugin value=0.5833333333333334 1762943358000000000
logql,detected_level=info,host=Hugin value=45.8 1762943358000000000
logql,detected_level=unknown,host=Hugin value=741.71 1762943358000000000
logql,detected_level=warn,host=Hugin value=16.566666666666666 1762943358000000000示例范围查询
count by(detected_level) (rate({job="varlogs", filename="/var/log/Xorg.0.log"} [5m]))范围为 30 分钟前到当前,步长为一分钟,结果为
logql,detected_level=error,host=Hugin value=1 1762943220000000000
logql,detected_level=error,host=Hugin value=1 1762943280000000000
logql,detected_level=error,host=Hugin value=1 1762943340000000000
logql,detected_level=error,host=Hugin value=1 1762943400000000000
logql,detected_level=error,host=Hugin value=1 1762943460000000000
logql,detected_level=info,host=Hugin value=1 1762943220000000000
logql,detected_level=info,host=Hugin value=1 1762943280000000000
logql,detected_level=info,host=Hugin value=1 1762943340000000000
logql,detected_level=info,host=Hugin value=1 1762943400000000000
logql,detected_level=info,host=Hugin value=1 1762943460000000000
logql,detected_level=unknown,host=Hugin value=1 1762943220000000000
logql,detected_level=unknown,host=Hugin value=1 1762943280000000000
logql,detected_level=unknown,host=Hugin value=1 1762943340000000000
logql,detected_level=unknown,host=Hugin value=1 1762943400000000000
logql,detected_level=unknown,host=Hugin value=1 1762943460000000000当查询原始日志条目(流式结果)时,例如
{job="varlogs", filename="/var/log/Xorg.0.log"}使用 sorting = "forward" 和 limit = 5,插件返回以下内容
logql,detected_level=unknown,filename=/var/log/Xorg.0.log,host=Hugin,job=varlogs,service_name=varlogs message="[ 6.806] (--) Log file renamed from \"/var/log/Xorg.pid-693.log\" to \"/var/log/Xorg.0.log\"" 1762943173000000000
logql,detected_level=unknown,filename=/var/log/Xorg.0.log,host=Hugin,job=varlogs,service_name=varlogs message="[ 6.807] " 1762943173000000000
logql,detected_level=unknown,filename=/var/log/Xorg.0.log,host=Hugin,job=varlogs,service_name=varlogs message="X.Org X Server 1.21.1.14" 1762943173000000000
logql,detected_level=unknown,filename=/var/log/Xorg.0.log,host=Hugin,job=varlogs,service_name=varlogs message="X Protocol Version 11, Revision 0" 1762943173000000000
logql,detected_level=unknown,filename=/var/log/Xorg.0.log,host=Hugin,job=varlogs,service_name=varlogs message="[ 6.807] Current Operating System: Linux Hugin 6.12.1-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 22 Nov 2024 16:04:27 +0000 x86_64" 1762943173000000000此页面是否有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一员!我们欢迎并鼓励您对 Telegraf 和本文档提出反馈和 bug 报告。要获取支持,请使用以下资源
具有年度合同或支持合同的客户可以 联系 InfluxData 支持。