feat(inputs.procstat): Add child level tag (#16105)
Co-authored-by: Thomas Casteleyn <thomas.casteleyn@me.com>
This commit is contained in:
parent
b2d81f056b
commit
fc6bf15944
|
|
@ -77,6 +77,8 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
## dest -- destination address of the process socket (non-unix sockets)
|
## dest -- destination address of the process socket (non-unix sockets)
|
||||||
## dest_port -- destination port of the process socket (non-unix sockets)
|
## dest_port -- destination port of the process socket (non-unix sockets)
|
||||||
## name -- name of the process socket (unix sockets only)
|
## name -- name of the process socket (unix sockets only)
|
||||||
|
## Available for procstat_lookup:
|
||||||
|
## level -- level of the process filtering
|
||||||
# tag_with = []
|
# tag_with = []
|
||||||
|
|
||||||
## Properties to collect
|
## Properties to collect
|
||||||
|
|
@ -176,6 +178,8 @@ Below are an example set of tags and fields:
|
||||||
- cgroup_full (when cgroup or systemd_unit is used with glob)
|
- cgroup_full (when cgroup or systemd_unit is used with glob)
|
||||||
- supervisor_unit (when defined)
|
- supervisor_unit (when defined)
|
||||||
- win_service (when defined)
|
- win_service (when defined)
|
||||||
|
- parent_pid (for child processes)
|
||||||
|
- child_level (for child processes)
|
||||||
- fields:
|
- fields:
|
||||||
- child_major_faults (int)
|
- child_major_faults (int)
|
||||||
- child_minor_faults (int)
|
- child_minor_faults (int)
|
||||||
|
|
|
||||||
|
|
@ -202,9 +202,11 @@ func (f *filter) applyFilter() ([]processGroup, error) {
|
||||||
tags[k] = v
|
tags[k] = v
|
||||||
}
|
}
|
||||||
tags["parent_pid"] = strconv.FormatInt(int64(p.Pid), 10)
|
tags["parent_pid"] = strconv.FormatInt(int64(p.Pid), 10)
|
||||||
|
|
||||||
children = append(children, processGroup{
|
children = append(children, processGroup{
|
||||||
processes: c,
|
processes: c,
|
||||||
tags: tags,
|
tags: tags,
|
||||||
|
level: depth + 1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ type pidsTags struct {
|
||||||
type processGroup struct {
|
type processGroup struct {
|
||||||
processes []*gopsprocess.Process
|
processes []*gopsprocess.Process
|
||||||
tags map[string]string
|
tags map[string]string
|
||||||
|
level int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Procstat) SampleConfig() string {
|
func (*Procstat) SampleConfig() string {
|
||||||
|
|
@ -98,7 +99,7 @@ func (p *Procstat) Init() error {
|
||||||
p.cfg.tagging = make(map[string]bool, len(p.TagWith))
|
p.cfg.tagging = make(map[string]bool, len(p.TagWith))
|
||||||
for _, tag := range p.TagWith {
|
for _, tag := range p.TagWith {
|
||||||
switch tag {
|
switch tag {
|
||||||
case "cmdline", "pid", "ppid", "status", "user":
|
case "cmdline", "pid", "ppid", "status", "user", "child_level", "parent_pid", "level":
|
||||||
case "protocol", "state", "src", "src_port", "dest", "dest_port", "name": // socket only
|
case "protocol", "state", "src", "src_port", "dest", "dest_port", "name": // socket only
|
||||||
if !slices.Contains(p.Properties, "sockets") {
|
if !slices.Contains(p.Properties, "sockets") {
|
||||||
return fmt.Errorf("socket tagging option %q specified without sockets enabled", tag)
|
return fmt.Errorf("socket tagging option %q specified without sockets enabled", tag)
|
||||||
|
|
@ -349,6 +350,7 @@ func (p *Procstat) gatherNew(acc telegraf.Accumulator) error {
|
||||||
var count int
|
var count int
|
||||||
for _, g := range groups {
|
for _, g := range groups {
|
||||||
count += len(g.processes)
|
count += len(g.processes)
|
||||||
|
level := strconv.Itoa(g.level)
|
||||||
for _, gp := range g.processes {
|
for _, gp := range g.processes {
|
||||||
// Skip over non-running processes
|
// Skip over non-running processes
|
||||||
if running, err := gp.IsRunning(); err != nil || !running {
|
if running, err := gp.IsRunning(); err != nil || !running {
|
||||||
|
|
@ -375,6 +377,9 @@ func (p *Procstat) gatherNew(acc telegraf.Accumulator) error {
|
||||||
process.setTag("process_name", p.ProcessName)
|
process.setTag("process_name", p.ProcessName)
|
||||||
}
|
}
|
||||||
tags["filter"] = f.Name
|
tags["filter"] = f.Name
|
||||||
|
if p.cfg.tagging["level"] {
|
||||||
|
tags["level"] = level
|
||||||
|
}
|
||||||
|
|
||||||
process = &proc{
|
process = &proc{
|
||||||
Process: gp,
|
Process: gp,
|
||||||
|
|
@ -394,6 +399,23 @@ func (p *Procstat) gatherNew(acc telegraf.Accumulator) error {
|
||||||
acc.AddMetric(m)
|
acc.AddMetric(m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if p.cfg.tagging["level"] {
|
||||||
|
// Add lookup statistics-metric
|
||||||
|
acc.AddFields(
|
||||||
|
"procstat_lookup",
|
||||||
|
map[string]interface{}{
|
||||||
|
"pid_count": len(g.processes),
|
||||||
|
"running": len(running),
|
||||||
|
"result_code": 0,
|
||||||
|
"level": g.level,
|
||||||
|
},
|
||||||
|
map[string]string{
|
||||||
|
"filter": f.Name,
|
||||||
|
"result": "success",
|
||||||
|
},
|
||||||
|
now,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add lookup statistics-metric
|
// Add lookup statistics-metric
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@
|
||||||
## dest -- destination address of the process socket (non-unix sockets)
|
## dest -- destination address of the process socket (non-unix sockets)
|
||||||
## dest_port -- destination port of the process socket (non-unix sockets)
|
## dest_port -- destination port of the process socket (non-unix sockets)
|
||||||
## name -- name of the process socket (unix sockets only)
|
## name -- name of the process socket (unix sockets only)
|
||||||
|
## Available for procstat_lookup:
|
||||||
|
## level -- level of the process filtering
|
||||||
# tag_with = []
|
# tag_with = []
|
||||||
|
|
||||||
## Properties to collect
|
## Properties to collect
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue