Tail 和 Prometheus 集成

强大的性能和简单的集成,由 InfluxData 构建的开源数据连接器 Telegraf 提供支持。

info

对于大规模实时查询,这不是推荐的配置。 为了实现查询和压缩优化、高速摄取和高可用性,您可能需要考虑 Tail 和 InfluxDB

50 亿+

Telegraf 下载量

#1

时间序列数据库
来源:DB Engines

10 亿+

InfluxDB 下载量

2,800+

贡献者

目录

强大的性能,无限的扩展能力

收集、组织和处理大量高速数据。 当您将任何数据视为时间序列数据时,它会更有价值。 使用 InfluxDB,这是基于 Telegraf 构建的排名第一的时间序列平台,可进行扩展。

查看入门方法

输入和输出集成概述

Tail Telegraf 插件通过 tail 指定的日志文件来收集指标,实时捕获新的日志条目以进行进一步分析。

Prometheus 输出插件使 Telegraf 能够在 HTTP 端点公开指标,以供 Prometheus 服务器抓取。 这种集成允许用户以 Prometheus 可以高效处理的格式从各种来源收集和聚合指标。

集成详情

Tail

tail 插件旨在持续监控和解析日志文件,使其成为实时日志分析和监控的理想选择。 它模仿 Unix tail 命令的功能,允许用户指定文件或模式,并在添加新行时开始读取。 主要功能包括跟踪日志轮换文件、从文件末尾开始读取以及支持日志消息的各种解析格式。 用户可以通过各种配置选项自定义插件,例如指定文件编码、监视文件更新的方法以及处理日志数据的过滤器设置。 在日志数据对于监控应用程序性能和诊断问题至关重要的环境中,此插件尤其有价值。

Prometheus

此插件有助于与 Prometheus 集成,Prometheus 是一种著名的开源监控和警报工具包,专为大规模环境中的可靠性和效率而设计。 通过充当 Prometheus 客户端,它允许用户通过 HTTP 服务器公开一组定义的指标,Prometheus 可以按指定的时间间隔抓取这些指标。 此插件在监控各种系统中发挥着至关重要的作用,它允许这些系统以标准化格式发布性能指标,从而可以广泛了解系统健康状况和行为。 主要功能包括支持配置各种端点、启用 TLS 以实现安全通信以及 HTTP 基本身份验证选项。 该插件还与全局 Telegraf 配置设置无缝集成,支持广泛的自定义以适应特定的监控需求。 这促进了不同系统必须有效通信性能数据的环境中的互操作性。 利用 Prometheus 的指标格式,它可以通过指标到期和收集器控制等高级配置来实现灵活的指标管理,从而为监控和警报工作流程提供完善的解决方案。

配置

Tail

[[inputs.tail]]
  ## File names or a pattern to tail.
  ## These accept standard unix glob matching rules, but with the addition of
  ## ** as a "super asterisk". ie:
  ##   "/var/log/**.log"  -> recursively find all .log files in /var/log
  ##   "/var/log/*/*.log" -> find all .log files with a parent dir in /var/log
  ##   "/var/log/apache.log" -> just tail the apache log file
  ##   "/var/log/log[!1-2]*  -> tail files without 1-2
  ##   "/var/log/log[^1-2]*  -> identical behavior as above
  ## See https://github.com/gobwas/glob for more examples
  ##
  files = ["/var/mymetrics.out"]

  ## Read file from beginning.
  # from_beginning = false

  ## Whether file is a named pipe
  # pipe = false

  ## Method used to watch for file updates.  Can be either "inotify" or "poll".
  ## inotify is supported on linux, *bsd, and macOS, while Windows requires
  ## using poll. Poll checks for changes every 250ms.
  # watch_method = "inotify"

  ## Maximum lines of the file to process that have not yet be written by the
  ## output.  For best throughput set based on the number of metrics on each
  ## line and the size of the output's metric_batch_size.
  # max_undelivered_lines = 1000

  ## Character encoding to use when interpreting the file contents.  Invalid
  ## characters are replaced using the unicode replacement character.  When set
  ## to the empty string the data is not decoded to text.
  ##   ex: character_encoding = "utf-8"
  ##       character_encoding = "utf-16le"
  ##       character_encoding = "utf-16be"
  ##       character_encoding = ""
  # character_encoding = ""

  ## 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"

  ## Set the tag that will contain the path of the tailed file. If you don't want this tag, set it to an empty string.
  # path_tag = "path"

  ## Filters to apply to files before generating metrics
  ## "ansi_color" removes ANSI colors
  # filters = []

  ## multiline parser/codec
  ## https://elastic.ac.cn/guide/en/logstash/2.4/plugins-filters-multiline.html
  #[inputs.tail.multiline]
    ## The pattern should be a regexp which matches what you believe to be an indicator that the field is part of an event consisting of multiple lines of log data.
    #pattern = "^\s"

    ## The field's value must be previous or next and indicates the relation to the
    ## multi-line event.
    #match_which_line = "previous"

    ## The invert_match can be true or false (defaults to false).
    ## If true, a message not matching the pattern will constitute a match of the multiline filter and the what will be applied. (vice-versa is also true)
    #invert_match = false

    ## The handling method for quoted text (defaults to 'ignore').
    ## The following methods are available:
    ##   ignore  -- do not consider quotation (default)
    ##   single-quotes -- consider text quoted by single quotes (')
    ##   double-quotes -- consider text quoted by double quotes (")
    ##   backticks     -- consider text quoted by backticks (`)
    ## When handling quotes, escaped quotes (e.g. \") are handled correctly.
    #quotation = "ignore"

    ## The preserve_newline option can be true or false (defaults to false).
    ## If true, the newline character is preserved for multiline elements,
    ## this is useful to preserve message-structure e.g. for logging outputs.
    #preserve_newline = false

    #After the specified timeout, this plugin sends the multiline event even if no new pattern is found to start a new event. The default is 5s.
    #timeout = 5s

Prometheus

[[outputs.prometheus_client]]
  ## Address to listen on.
  ##   ex:
  ##     listen = ":9273"
  ##     listen = "vsock://:9273"
  listen = ":9273"

  ## Maximum duration before timing out read of the request
  # read_timeout = "10s"
  ## Maximum duration before timing out write of the response
  # write_timeout = "10s"

  ## Metric version controls the mapping from Prometheus metrics into Telegraf metrics.
  ## See "Metric Format Configuration" in plugins/inputs/prometheus/README.md for details.
  ## Valid options: 1, 2
  # metric_version = 1

  ## Use HTTP Basic Authentication.
  # basic_username = "Foo"
  # basic_password = "Bar"

  ## If set, the IP Ranges which are allowed to access metrics.
  ##   ex: ip_range = ["192.168.0.0/24", "192.168.1.0/30"]
  # ip_range = []

  ## Path to publish the metrics on.
  # path = "/metrics"

  ## Expiration interval for each metric. 0 == no expiration
  # expiration_interval = "60s"

  ## Collectors to enable, valid entries are "gocollector" and "process".
  ## If unset, both are enabled.
  # collectors_exclude = ["gocollector", "process"]

  ## Send string metrics as Prometheus labels.
  ## Unless set to false all string metrics will be sent as labels.
  # string_as_label = true

  ## If set, enable TLS with the given certificate.
  # tls_cert = "/etc/ssl/telegraf.crt"
  # tls_key = "/etc/ssl/telegraf.key"

  ## Set one or more allowed client CA certificate file names to
  ## enable mutually authenticated TLS connections
  # tls_allowed_cacerts = ["/etc/telegraf/clientca.pem"]

  ## Export metric collection time.
  # export_timestamp = false

  ## Specify the metric type explicitly.
  ## This overrides the metric-type of the Telegraf metric. Globbing is allowed.
  # [outputs.prometheus_client.metric_types]
  #   counter = []
  #   gauge = []

输入和输出集成示例

Tail

  1. 实时服务器健康状况监控:实施 Tail 插件以实时解析 Web 服务器访问日志,从而立即了解用户活动、错误率和性能指标。 通过可视化此日志数据,运营团队可以快速识别和响应流量或错误峰值,从而提高系统可靠性和用户体验。

  2. 集中式日志管理:利用 Tail 插件聚合分布式系统中多个来源的日志。 通过配置每个服务以通过 Tail 插件将其日志发送到集中位置,团队可以简化日志分析并确保可以从单个界面访问所有相关数据,从而简化故障排除流程。

  3. 安全事件检测:使用此插件监控身份验证日志,以查找未经授权的访问尝试或可疑活动。 通过在某些日志消息上设置警报,团队可以利用此插件来增强安全态势并及时响应潜在的安全威胁,从而降低漏洞风险并提高整体系统完整性。

  4. 动态应用程序性能洞察:与分析工具集成以创建实时仪表板,这些仪表板根据日志数据展示应用程序性能指标。 这种设置不仅可以帮助开发人员诊断瓶颈和效率低下问题,还可以实现主动的性能调整和资源分配,从而优化应用程序在不同负载下的行为。

Prometheus

  1. 监控多云部署:利用 Prometheus 插件从跨多个云提供商运行的应用程序收集指标。 这种情况允许团队通过单个 Prometheus 实例集中监控,该实例从不同环境抓取指标,从而提供跨混合基础设施的统一性能指标视图。 它简化了报告和警报,提高了运营效率,而无需复杂的集成。

  2. 增强微服务可见性:实施该插件以公开 Kubernetes 集群中各种微服务的指标。 通过使用 Prometheus,团队可以实时可视化服务指标、识别瓶颈并维护系统健康状况检查。 这种设置支持基于从收集的指标生成的洞察进行自适应扩展和资源利用率优化。 它增强了对服务交互进行故障排除的能力,从而显着提高了微服务架构的弹性。

  3. 电子商务中的实时异常检测:通过将此插件与 Prometheus 一起使用,电子商务平台可以监控关键绩效指标,例如响应时间和错误率。 将异常检测算法与抓取的指标集成,可以识别指示潜在问题的意外模式,例如突然的流量峰值或后端服务故障。 这种主动监控增强了业务连续性和运营效率,最大限度地减少了潜在的停机时间,同时确保了服务可靠性。

  4. API 的性能指标报告:利用 Prometheus 输出插件收集和报告 API 性能指标,然后可以在 Grafana 仪表板中可视化这些指标。 此用例可以详细分析 API 响应时间、吞吐量和错误率,从而促进 API 服务的持续改进。 通过密切监控这些指标,团队可以快速响应性能下降,确保最佳 API 性能并保持高水平的服务可用性。

反馈

感谢您成为我们社区的一份子! 如果您有任何一般性反馈或在这些页面上发现了任何错误,我们欢迎并鼓励您提出意见。 请在 InfluxDB 社区 Slack 中提交您的反馈。

强大的性能,无限的扩展能力

收集、组织和处理大量高速数据。 当您将任何数据视为时间序列数据时,它会更有价值。 使用 InfluxDB,这是基于 Telegraf 构建的排名第一的时间序列平台,可进行扩展。

查看入门方法

相关集成

HTTP 和 InfluxDB 集成

HTTP 插件从一个或多个 HTTP(S) 端点收集指标。 它支持各种身份验证方法和数据格式的配置选项。

查看集成

Kafka 和 InfluxDB 集成

此插件从 Kafka 读取消息,并允许基于这些消息创建指标。 它支持各种配置,包括不同的 Kafka 设置和消息处理选项。

查看集成

Kinesis 和 InfluxDB 集成

Kinesis 插件允许从 AWS Kinesis 流中读取指标。 它支持多种输入数据格式,并为可靠的消息处理提供带有 DynamoDB 的检查点功能。

查看集成