【问题标题】:Telegraf & InfluxDB: how to convert PROCSTAT's pid from field to tag?Telegraf & InfluxDB:如何将 PROCSTAT 的 pid 从字段转换为标记?
【发布时间】:2020-12-21 03:27:35
【问题描述】:

总结:我正在使用 telegraf 将 procstat 导入 InfluxDB。 我想将 pid 从整数字段转换为 TAG,以便在 Influx 中对其进行分组。

详情: 经过大量搜索后,我在某个站点上找到了以下内容,但它似乎正在做相反的事情(将标签转换为字段)。我不确定如何从中推断出相反的转换语法:

[processors]
[[processors.converter]]
namepass = [ "procstat",]

[processors.converter.tags]
string = [ "cmdline",]

我正在使用 Influx 1.7.9

【问题讨论】:

    标签: grafana influxdb pid telegraf procstat


    【解决方案1】:

    将pid转换为标签的正确处理器配置如下。

    [processors]
      [[processors.converter]]
         namepass = [ "procstat"]
    
      [processors.converter.fields]
         tag = [ "pid"]
    

    请参考转换器处理器插件的文档 https://github.com/influxdata/telegraf/tree/master/plugins/processors/converter

    在最新版本的电报 pid 可以通过在输入插件配置中指定它来存储为标签。这里不需要转换器处理器。

    在配置中提及pid_tag = true。但是请注意,当进程生命周期较短时,将 pid 作为标签对性能的影响。

    P.S:您应该尝试将您的电报版本升级到 1.14.5。此版本中有针对 procstat 插件的性能改进修复。

    插件配置参考https://github.com/influxdata/telegraf/tree/master/plugins/inputs/procstat

    示例配置。

    # Monitor process cpu and memory usage
    [[inputs.procstat]]
      ## PID file to monitor process
      pid_file = "/var/run/nginx.pid"
      ## executable name (ie, pgrep <exe>)
      # exe = "nginx"
      ## pattern as argument for pgrep (ie, pgrep -f <pattern>)
      # pattern = "nginx"
      ## user as argument for pgrep (ie, pgrep -u <user>)
      # user = "nginx"
      ## Systemd unit name
      # systemd_unit = "nginx.service"
      ## CGroup name or path
      # cgroup = "systemd/system.slice/nginx.service"
    
      ## Windows service name
      # win_service = ""
    
      ## override for process_name
      ## This is optional; default is sourced from /proc/<pid>/status
      # process_name = "bar"
    
      ## Field name prefix
      # prefix = ""
    
      ## When true add the full cmdline as a tag.
      # cmdline_tag = false
    
      ## Add the PID as a tag instead of as a field.  When collecting multiple
      ## processes with otherwise matching tags this setting should be enabled to
      ## ensure each process has a unique identity.
      ##
      ## Enabling this option may result in a large number of series, especially
      ## when processes have a short lifetime.
      # pid_tag = false
    

    【讨论】:

    • 非常感谢您提供的信息丰富的回复和多个修复选项。
    猜你喜欢
    • 2021-10-29
    • 2018-11-02
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    • 2022-12-10
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    相关资源
    最近更新 更多