github.com/influxdata/influxdb/v2@v2.7.6/telegraf/plugins/inputs/procstat.go (about)

     1  package inputs
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  )
     7  
     8  // Procstat is based on telegraf procstat input plugin.
     9  type Procstat struct {
    10  	baseInput
    11  	Exe string `json:"exe"`
    12  }
    13  
    14  // PluginName is based on telegraf plugin name.
    15  func (p *Procstat) PluginName() string {
    16  	return "procstat"
    17  }
    18  
    19  // TOML encodes to toml string.
    20  func (p *Procstat) TOML() string {
    21  	return fmt.Sprintf(`[[inputs.%s]]
    22    ## PID file to monitor process
    23    pid_file = "/var/run/nginx.pid"
    24    ## executable name (ie, pgrep <exe>)
    25    # exe = "%s"
    26    ## pattern as argument for pgrep (ie, pgrep -f <pattern>)
    27    # pattern = "nginx"
    28    ## user as argument for pgrep (ie, pgrep -u <user>)
    29    # user = "nginx"
    30    ## Systemd unit name
    31    # systemd_unit = "nginx.service"
    32    ## CGroup name or path
    33    # cgroup = "systemd/system.slice/nginx.service"
    34  
    35    ## Windows service name
    36    # win_service = ""
    37  
    38    ## override for process_name
    39    ## This is optional; default is sourced from /proc/<pid>/status
    40    # process_name = "bar"
    41  
    42    ## Field name prefix
    43    # prefix = ""
    44  
    45    ## When true add the full cmdline as a tag.
    46    # cmdline_tag = false
    47  
    48    ## Mode to use when calculating CPU usage. Can be one of 'solaris' or 'irix'.
    49    # mode = "irix"
    50  
    51    ## Add the PID as a tag instead of as a field.  When collecting multiple
    52    ## processes with otherwise matching tags this setting should be enabled to
    53    ## ensure each process has a unique identity.
    54    ##
    55    ## Enabling this option may result in a large number of series, especially
    56    ## when processes have a short lifetime.
    57    # pid_tag = false
    58  
    59    ## Method to use when finding process IDs.  Can be one of 'pgrep', or
    60    ## 'native'.  The pgrep finder calls the pgrep executable in the PATH while
    61    ## the native finder performs the search directly in a manor dependent on the
    62    ## platform.  Default is 'pgrep'
    63    # pid_finder = "pgrep"
    64  `, p.PluginName(), p.Exe)
    65  }
    66  
    67  // UnmarshalTOML decodes the parsed data to the object
    68  func (p *Procstat) UnmarshalTOML(data interface{}) error {
    69  	dataOK, ok := data.(map[string]interface{})
    70  	if !ok {
    71  		return errors.New("bad exe for procstat input plugin")
    72  	}
    73  	if p.Exe, ok = dataOK["exe"].(string); !ok {
    74  		return errors.New("exe is not a string value")
    75  	}
    76  	return nil
    77  }