Telegraf & InfluxDB: how to convert PROCSTAT's pid from field to tag?

2.1k views Asked by At

Summary: I am using telegraf to get procstat into InfluxDB. I want to convert the pid from an integer field to a TAG so that I can do group by on it in Influx.

Details: After a lot of searching I found the following on some site but it seems to be doing the opposite (converts tag into a field). I am not sure how to deduce the opposite conversion syntax from it:

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

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

I'm using Influx 1.7.9

1

There are 1 answers

1
robert On BEST ANSWER

The correct processor configuration to convert pid as tag is as below.

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

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

Please refer the documentation of converter processor plugin https://github.com/influxdata/telegraf/tree/master/plugins/processors/converter

In the latest version of telegraf pid can be stored as tag by specifying it in the input plugin configuration. A converter processor is not needed here.

Mention pid_tag = true in the configuration. However be aware of the performance impact of having pid as a tag when processes are short lived.

P.S: You should try to upgrade your telegraf version to 1.14.5. There is a performance improvement fix for procstat plugin in this version.

Plugin configuration reference https://github.com/influxdata/telegraf/tree/master/plugins/inputs/procstat

Sample config.

# 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